Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
camera = gp.check_result(gp.gp_camera_new())
gp.check_result(gp.gp_camera_init(camera))
print('Getting list of files')
files = list_files(camera)
if not files:
print('No files found')
return 1
path = files[0]
print('Copying %s to memory' % path)
folder, name = os.path.split(path)
camera_file = gp.check_result(gp.gp_camera_file_get(
camera, folder, name, gp.GP_FILE_TYPE_NORMAL))
## # read file data using 'slurp' and a buffer allocated in Python
## info = gp.check_result(
## gp.gp_camera_file_get_info(camera, folder, name))
## file_data = bytearray(info.file.size)
## count = gp.check_result(gp.gp_file_slurp(camera_file, file_data))
def main():
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
camera = gp.check_result(gp.gp_camera_new())
gp.check_result(gp.gp_camera_init(camera))
print('Getting list of files')
files = list_files(camera)
if not files:
print('No files found')
return 1
path = files[0]
print('Copying %s to memory in 100 kilobyte chunks' % path)
folder, name = os.path.split(path)
file_info = gp.check_result(gp.gp_camera_file_get_info(
camera, folder, name))
data = bytearray(file_info.file.size)
view = memoryview(data)
chunk_size = 100 * 1024
offset = 0
while offset < len(data):
def main():
# use Python logging
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
# get user value
if len(sys.argv) != 2:
print('One command line parameter required')
return 1
try:
value = int(sys.argv[1])
except:
print('Integer parameter required')
return 1
# open camera connection
camera = gp.check_result(gp.gp_camera_new())
gp.check_result(gp.gp_camera_init(camera))
# get configuration tree
config = gp.check_result(gp.gp_camera_get_config(camera))
# find the capture target config item
capture_target = gp.check_result(
gp.gp_widget_get_child_by_name(config, 'capturetarget'))
# check value in range
count = gp.check_result(gp.gp_widget_count_choices(capture_target))
if value < 0 or value >= count:
print('Parameter out of range')
return 1
# set value
value = gp.check_result(gp.gp_widget_get_choice(capture_target, value))
gp.check_result(gp.gp_widget_set_value(capture_target, value))
# set config
gp.check_result(gp.gp_camera_set_config(camera, config))
def main():
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
computer_files = list_computer_files()
camera = gp.check_result(gp.gp_camera_new())
gp.check_result(gp.gp_camera_init(camera))
print('Getting list of files from camera...')
camera_files = list_camera_files(camera)
if not camera_files:
print('No files found')
return 1
print('Copying files...')
for path in camera_files:
info = get_camera_file_info(camera, path)
timestamp = datetime.fromtimestamp(info.file.mtime)
folder, name = os.path.split(path)
dest_dir = get_target_dir(timestamp)
dest = os.path.join(dest_dir, name)
if dest in computer_files:
continue
print('%s -> %s' % (path, dest_dir))
def main():
# use Python logging
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
# open camera connection
camera = gp.check_result(gp.gp_camera_new())
gp.check_result(gp.gp_camera_init(camera))
# get configuration tree
config = gp.check_result(gp.gp_camera_get_config(camera))
# find the capture target config item
capture_target = gp.check_result(
gp.gp_widget_get_child_by_name(config, 'capturetarget'))
# print current setting
value = gp.check_result(gp.gp_widget_get_value(capture_target))
print('Current setting:', value)
# print possible settings
for n in range(gp.check_result(gp.gp_widget_count_choices(capture_target))):
choice = gp.check_result(gp.gp_widget_get_choice(capture_target, n))
print('Choice:', n, choice)
# clean up
gp.check_result(gp.gp_camera_exit(camera))
return 0
def main():
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
camera = gp.check_result(gp.gp_camera_new())
gp.check_result(gp.gp_camera_init(camera))
# required configuration will depend on camera type!
print('Checking camera config')
# get configuration tree
config = gp.check_result(gp.gp_camera_get_config(camera))
# find the image format config item
# camera dependent - 'imageformat' is 'imagequality' on some
OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat')
if OK >= gp.GP_OK:
# get current setting
value = gp.check_result(gp.gp_widget_get_value(image_format))
# make sure it's not raw
if 'raw' in value.lower():
print('Cannot preview raw images')
return 1
# find the capture size class config item