Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
# add our own callback, with data
print('Using Python callback, with data')
print('================================')
callback_obj = gp.check_result(
gp.gp_log_add_func(gp.GP_LOG_VERBOSE, callback, 'some data'))
print('callback_obj', callback_obj)
# create an error
gp.gp_camera_init(camera)
# uninstall callback
del callback_obj
# set gphoto2 to use Python's logging directly
print('Using Python logging')
print('====================')
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
# create an error
gp.gp_camera_init(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.Camera()
camera.init()
print('Capturing image')
file_path = camera.capture(gp.GP_CAPTURE_IMAGE)
print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name))
target = os.path.join('/tmp', file_path.name)
print('Copying image to', target)
camera_file = camera.file_get(
file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL)
camera_file.save(target)
subprocess.call(['xdg-open', target])
camera.exit()
return 0
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))
if not os.path.isdir(dest_dir):
os.makedirs(dest_dir)
camera_file = gp.check_result(gp.gp_camera_file_get(
camera, folder, name, gp.GP_FILE_TYPE_NORMAL))
gp.check_result(gp.gp_file_save(camera_file, dest))
gp.check_result(gp.gp_camera_exit(camera))
return 0
def list_camera_files(camera, path='/'):
""" Returns a list of all the image files on the camera """
result = []
# get files
for name, value in gp.check_result(
gp.gp_camera_folder_list_files(camera, path)):
result.append(os.path.join(path, name))
# read folders
folders = []
for name, value in gp.check_result(
gp.gp_camera_folder_list_folders(camera, path)):
folders.append(name)
# recurse over subfolders
for name in folders:
result.extend(list_camera_files(camera, os.path.join(path, name)))
return result