How to use handprint - 10 common examples

To help you get started, we’ve selected a few handprint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github caltechlibrary / handprint / handprint / __main__.py View on Github external
exit(1)

    base_name  = 'document' if base_name == 'B' else base_name
    from_file  = None if from_file == 'F' else from_file
    output_dir = None if output_dir == 'O' else output_dir
    compare    = 'relaxed' if (compare and relaxed) else compare
    threads    = int(max(1, available_cpus()/2 if threads == 'T' else int(threads)))

    # Do the real work --------------------------------------------------------

    try:
        body = MainBody(base_name, extended, from_file, output_dir, threads)
        body.run(services, files, make_grid, compare)
    except (KeyboardInterrupt, UserCancelled) as ex:
        if __debug__: log('received {}', sys.exc_info()[0].__name__)
        inform('Quitting.')
        exit(0)
    except Exception as ex:
        if debugging:
            import traceback
            alert('{}\n{}', str(ex), traceback.format_exc())
            import pdb; pdb.set_trace()
        else:
            alert(str(ex))
            exit(2)
    inform('Done.')
github caltechlibrary / handprint / handprint / __main__.py View on Github external
service = add_creds.lower()
        if service not in services_list():
            alert('Unknown service: "{}". {}', service, hint)
            exit(1)
        if not files or len(files) > 1:
            alert('Option {}a requires one file. {}', prefix, hint)
            exit(1)
        creds_file = files[0]
        if not readable(creds_file):
            alert('File not readable: {}', creds_file)
            exit(1)
        Credentials.save_credentials(service, creds_file)
        inform('Saved credentials for service "{}".', service)
        exit(0)
    if no_grid and not extended and not compare:
        alert('{0}G without {0}e or {0}c produces no output. {1}', prefix, hint)
        exit(1)
    if any(item.startswith('-') for item in files):
        alert('Unrecognized option in arguments. {}', hint)
        exit(1)
    if not files and from_file == 'F':
        alert('Need images or URLs to have something to do. {}', hint)
        exit(1)
    if relaxed and not compare:
        warn('Option {0}r without {0}c has no effect. {1}', prefix, hint)

    services = services_list() if services == 'S' else services.lower().split(',')
    if not all(s in services_list() for s in services):
        alert('"{}" is not a known services. {}', services, hint)
        exit(1)

    base_name  = 'document' if base_name == 'B' else base_name
github caltechlibrary / handprint / handprint / __main__.py View on Github external
compare    = 'relaxed' if (compare and relaxed) else compare
    threads    = int(max(1, available_cpus()/2 if threads == 'T' else int(threads)))

    # Do the real work --------------------------------------------------------

    try:
        body = MainBody(base_name, extended, from_file, output_dir, threads)
        body.run(services, files, make_grid, compare)
    except (KeyboardInterrupt, UserCancelled) as ex:
        if __debug__: log('received {}', sys.exc_info()[0].__name__)
        inform('Quitting.')
        exit(0)
    except Exception as ex:
        if debugging:
            import traceback
            alert('{}\n{}', str(ex), traceback.format_exc())
            import pdb; pdb.set_trace()
        else:
            alert(str(ex))
            exit(2)
    inform('Done.')
github caltechlibrary / handprint / handprint / __main__.py View on Github external
exit(1)
        creds_file = files[0]
        if not readable(creds_file):
            alert('File not readable: {}', creds_file)
            exit(1)
        Credentials.save_credentials(service, creds_file)
        inform('Saved credentials for service "{}".', service)
        exit(0)
    if no_grid and not extended and not compare:
        alert('{0}G without {0}e or {0}c produces no output. {1}', prefix, hint)
        exit(1)
    if any(item.startswith('-') for item in files):
        alert('Unrecognized option in arguments. {}', hint)
        exit(1)
    if not files and from_file == 'F':
        alert('Need images or URLs to have something to do. {}', hint)
        exit(1)
    if relaxed and not compare:
        warn('Option {0}r without {0}c has no effect. {1}', prefix, hint)

    services = services_list() if services == 'S' else services.lower().split(',')
    if not all(s in services_list() for s in services):
        alert('"{}" is not a known services. {}', services, hint)
        exit(1)

    base_name  = 'document' if base_name == 'B' else base_name
    from_file  = None if from_file == 'F' else from_file
    output_dir = None if output_dir == 'O' else output_dir
    compare    = 'relaxed' if (compare and relaxed) else compare
    threads    = int(max(1, available_cpus()/2 if threads == 'T' else int(threads)))

    # Do the real work --------------------------------------------------------
github caltechlibrary / handprint / handprint / __main__.py View on Github external
if version:
        print_version()
        exit(0)
    if list:
        inform('Known services: {}', ', '.join(services_list()))
        exit(0)

    print_intro(ui)

    if add_creds != 'A':
        service = add_creds.lower()
        if service not in services_list():
            alert('Unknown service: "{}". {}', service, hint)
            exit(1)
        if not files or len(files) > 1:
            alert('Option {}a requires one file. {}', prefix, hint)
            exit(1)
        creds_file = files[0]
        if not readable(creds_file):
            alert('File not readable: {}', creds_file)
            exit(1)
        Credentials.save_credentials(service, creds_file)
        inform('Saved credentials for service "{}".', service)
        exit(0)
    if no_grid and not extended and not compare:
        alert('{0}G without {0}e or {0}c produces no output. {1}', prefix, hint)
        exit(1)
    if any(item.startswith('-') for item in files):
        alert('Unrecognized option in arguments. {}', hint)
        exit(1)
    if not files and from_file == 'F':
        alert('Need images or URLs to have something to do. {}', hint)
github caltechlibrary / handprint / handprint / __main__.py View on Github external
inform('Known services: {}', ', '.join(services_list()))
        exit(0)

    print_intro(ui)

    if add_creds != 'A':
        service = add_creds.lower()
        if service not in services_list():
            alert('Unknown service: "{}". {}', service, hint)
            exit(1)
        if not files or len(files) > 1:
            alert('Option {}a requires one file. {}', prefix, hint)
            exit(1)
        creds_file = files[0]
        if not readable(creds_file):
            alert('File not readable: {}', creds_file)
            exit(1)
        Credentials.save_credentials(service, creds_file)
        inform('Saved credentials for service "{}".', service)
        exit(0)
    if no_grid and not extended and not compare:
        alert('{0}G without {0}e or {0}c produces no output. {1}', prefix, hint)
        exit(1)
    if any(item.startswith('-') for item in files):
        alert('Unrecognized option in arguments. {}', hint)
        exit(1)
    if not files and from_file == 'F':
        alert('Need images or URLs to have something to do. {}', hint)
        exit(1)
    if relaxed and not compare:
        warn('Option {0}r without {0}c has no effect. {1}', prefix, hint)
github caltechlibrary / handprint / handprint / __main__.py View on Github external
exit(0)
    if no_grid and not extended and not compare:
        alert('{0}G without {0}e or {0}c produces no output. {1}', prefix, hint)
        exit(1)
    if any(item.startswith('-') for item in files):
        alert('Unrecognized option in arguments. {}', hint)
        exit(1)
    if not files and from_file == 'F':
        alert('Need images or URLs to have something to do. {}', hint)
        exit(1)
    if relaxed and not compare:
        warn('Option {0}r without {0}c has no effect. {1}', prefix, hint)

    services = services_list() if services == 'S' else services.lower().split(',')
    if not all(s in services_list() for s in services):
        alert('"{}" is not a known services. {}', services, hint)
        exit(1)

    base_name  = 'document' if base_name == 'B' else base_name
    from_file  = None if from_file == 'F' else from_file
    output_dir = None if output_dir == 'O' else output_dir
    compare    = 'relaxed' if (compare and relaxed) else compare
    threads    = int(max(1, available_cpus()/2 if threads == 'T' else int(threads)))

    # Do the real work --------------------------------------------------------

    try:
        body = MainBody(base_name, extended, from_file, output_dir, threads)
        body.run(services, files, make_grid, compare)
    except (KeyboardInterrupt, UserCancelled) as ex:
        if __debug__: log('received {}', sys.exc_info()[0].__name__)
        inform('Quitting.')
github caltechlibrary / handprint / handprint / __main__.py View on Github external
if list:
        inform('Known services: {}', ', '.join(services_list()))
        exit(0)

    print_intro(ui)

    if add_creds != 'A':
        service = add_creds.lower()
        if service not in services_list():
            alert('Unknown service: "{}". {}', service, hint)
            exit(1)
        if not files or len(files) > 1:
            alert('Option {}a requires one file. {}', prefix, hint)
            exit(1)
        creds_file = files[0]
        if not readable(creds_file):
            alert('File not readable: {}', creds_file)
            exit(1)
        Credentials.save_credentials(service, creds_file)
        inform('Saved credentials for service "{}".', service)
        exit(0)
    if no_grid and not extended and not compare:
        alert('{0}G without {0}e or {0}c produces no output. {1}', prefix, hint)
        exit(1)
    if any(item.startswith('-') for item in files):
        alert('Unrecognized option in arguments. {}', hint)
        exit(1)
    if not files and from_file == 'F':
        alert('Need images or URLs to have something to do. {}', hint)
        exit(1)
    if relaxed and not compare:
        warn('Option {0}r without {0}c has no effect. {1}', prefix, hint)
github caltechlibrary / handprint / handprint / files.py View on Github external
def delete_existing(file):
    '''Delete the given file.'''
    # Check if it's actually a directory.
    if path.isdir(file):
        if __debug__: log('doing rmtree on directory {}', file)
        try:
            shutil.rmtree(file)
        except:
            if __debug__: log('unable to rmtree {}; will try renaming', file)
            try:
                rename_existing(file)
            except:
                if __debug__: log('unable to rmtree or rename {}', file)
    else:
        if __debug__: log('doing os.remove on file {}', file)
        os.remove(file)
github caltechlibrary / handprint / handprint / files.py View on Github external
def rename(f):
        backup = f + '.bak'
        # If we fail, we just give up instead of throwing an exception.
        try:
            os.rename(f, backup)
            if __debug__: log('renamed {} to {}', file, backup)
        except:
            try:
                delete_existing(backup)
                os.rename(f, backup)
            except:
                if __debug__: log('failed to delete {}', backup)
                if __debug__: log('failed to rename {} to {}', file, backup)