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())
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:
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()
files = list_files(camera)
if not files:
print('No files found')
return 1
print('File list')
print('=========')
for path in files[:10]:
print(path)
print('...')
for path in files[-10:]:
print(path)
info = get_file_info(camera, files[-1])
print
print('File info')
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()
files = list_files(camera)
if not files:
print('No files found')
return 1
print('File list')
print('=========')
for path in files[:10]:
print(path)
print('...')
for path in files[-10:]:
print(path)
print()
print('Exif data')
print('=========')
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
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()
files = list_files(camera)
if not files:
print('No files found')
return 1
print('File list')
print('=========')
for path in files[:10]:
print(path)
print('...')
for path in files[-10:]:
print(path)
info = get_file_info(camera, files[-1])
print
print('File info')
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
def main():
# set up logging
# note that: '%(filename)s:%(lineno)d' just prints 'port_log.py:127'
logging.basicConfig(
format='%(asctime)s %(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
# command line argument parser
parser = argparse.ArgumentParser(description="{} - interact with camera via python-gphoto2. Called without command line arguments, it will start a Qt GUI.".format(APPNAME))
parser.add_argument('--save-cam-conf-json', default=argparse.SUPPRESS, help='Get and save the camera configuration to .json file, if standalone (together with --load-cam-conf-json, can be used for copying filtered json files). The string argument is the filename, action is aborted if standalone and no camera online, or if the argument is empty. Overwrites existing files without prompting. Note that if camera is online, but mirror is not raised, process will complete with errors and fewer properties collected in json file (default: suppress)') # "%(default)s"
parser.add_argument('--load-cam-conf-json', default=argparse.SUPPRESS, help='Load and set the camera configuration from .json file, if standalone (together with --save-cam-conf-json, can be used for copying filtered json files). The string argument is the filename, action is aborted if standalone and no camera online, or if the argument is empty (default: suppress)') # "%(default)s"
parser.add_argument('--include-names-json', default=argparse.SUPPRESS, help='Comma separated list of property names to be filtered/included. When using --load-cam-conf-json with --save-cam-conf-json, a json copy with flattening of hierarchy (removal of nodes with children and without value) is performed; in that case --include-names-json can be used to include only certain properties in the output. Can also use `ro=0` or `ro=1` as filtering criteria. If empty ignored (default: suppress)') # "%(default)s"
parser.add_argument('--start-capture-view', default='', help='Command - start capture view (extend lens/raise mirror) on the camera, then exit', action='store_const', const=start_capture_view) # "%(default)s"
parser.add_argument('--stop-capture-view', default='', help='Command - stop capture view (retract lens/release mirror) on the camera, then exit', action='store_const', const=stop_capture_view) # "%(default)s"
parser.add_argument('--config-apply-btn', type=int, default=0, help='GUI option: 0: do not create apply button, update on change; 1: create apply button, update on its click (default: %(default)s)') # ""
args = parser.parse_args() # in case of --help, this also prints help and exits before Qt window is raised
if (args.start_capture_view): args.start_capture_view()
elif (args.stop_capture_view): args.stop_capture_view()
elif (hasattr(args, 'save_cam_conf_json') and not(hasattr(args, 'load_cam_conf_json'))):
getSaveCamConfJson(args)
elif (hasattr(args, 'load_cam_conf_json') and not(hasattr(args, 'save_cam_conf_json'))):
loadSetCamConfJson(args)
def main():
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
# make a list of all available cameras
camera_list = list(gp.Camera.autodetect())
if not camera_list:
print('No camera detected')
return 1
camera_list.sort(key=lambda x: x[0])
# ask user to choose one
for index, (name, addr) in enumerate(camera_list):
print('{:d}: {:s} {:s}'.format(index, addr, name))
if six.PY3:
choice = input('Please input number of chosen camera: ')
else:
choice = raw_input('Please input number of chosen camera: ')
try:
choice = int(choice)
except ValueError:
def main():
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
cameras = gp.Camera.autodetect()
for n, (name, value) in enumerate(cameras):
print('camera number', n)
print('===============')
print(name)
print(value)
print
return 0