示例#1
0
def run(config):
    """
    Gets the revisions for a given dropbox file. If set, produces the revs in
    different formats.
    """
    # Get client
    client, config = authutils.build_client(config)

    # Get the remote path for the given file
    remote_path = pathutils.find_remote_db_path(config.get("local_file"))

    # Now get the revisions of the given file
    revs = client.revisions(remote_path)

    # Which revision to use?
    revVal = __get_rev(revs, config)

    # Get the formatter function
    formatter = __get_formatter(config.get("formatter"))

    # TODO Needs a way to control where to send output
    output = formatter(revVal)
    if config.get("output"):
        __do_output(output, config)

    return output
示例#2
0
def build_config_with_client(*sources):
    """
    Builds the config dict using `build_config`, and then creates the auth client.
    """
    config = build_config(*sources)
    client, config = authutils.build_client(config)

    return config
示例#3
0
def build_config_with_client(*sources):
    """
    Builds the config dict using `build_config`, and then creates the auth client.
    """
    config = build_config(*sources)
    client, config = authutils.build_client(config)

    return config
示例#4
0
def run(config):
    """
    Verifies dropbox is properly configured.

    Attempts to:
        - Test authentication by creating a connection.
        - List the root dir
        - Puts a tmp file on dropbox
        - Gets that tmp file from dropbox
        - Checks that there is revisions available
        - Deletes that file
    """
    client, config = authutils.build_client(config)

    __log__.info("START checking connection!")

    # Create file properties
    db_filepath = "/test.txt"
    tmpfile = __build_tmp_file()

    # Build each check func as partials
    partial_funcs = [
        partial(check_virtenv),
        partial(check_root, client, config),
        partial(check_put, client, config, db_filepath, tmpfile),
        partial(check_get, client, config, db_filepath),
        partial(check_rev, client, config, db_filepath),
        partial(check_delete, client, config, db_filepath),
    ]

    # Execute the partials and collect their results
    check_results = True
    for func in partial_funcs:
        name = func.func.__name__
        result = func()
        if result:
            __log__.info("Result: {}: SUCCESS".format(name))
        else:
            __log__.warn("Result: {}: FAILED".format(name))
            check_results = False

    # Don't forget to close the tmpfile and delete it from disk!
    tmpfile.close()
    os.remove(tmpfile.name)

    __log__.info("END checking connection! Result {}".format(check_results))
    return check_results
示例#5
0
def run(config):
    """
    Verifies dropbox is properly configured.

    Attempts to:
        - Test authentication by creating a connection.
        - List the root dir
        - Puts a tmp file on dropbox
        - Gets that tmp file from dropbox
        - Checks that there is revisions available
        - Deletes that file
    """
    client, config = authutils.build_client(config)

    __log__.info("START checking connection!")

    # Create file properties
    db_filepath = "/test.txt"
    tmpfile = __build_tmp_file()

    # Build each check func as partials
    partial_funcs = [
        partial(check_virtenv),
        partial(check_root, client, config),
        partial(check_put, client, config, db_filepath, tmpfile),
        partial(check_get, client, config, db_filepath),
        partial(check_rev, client, config, db_filepath),
        partial(check_delete, client, config, db_filepath),
    ]

    # Execute the partials and collect their results
    check_results = True
    for func in partial_funcs:
        name = func.func.__name__
        result = func()
        if result:
            __log__.info("Result: {}: SUCCESS".format(name))
        else:
            __log__.warn("Result: {}: FAILED".format(name))
            check_results = False

    # Don't forget to close the tmpfile and delete it from disk!
    tmpfile.close()
    os.remove(tmpfile.name)

    __log__.info("END checking connection! Result {}".format(check_results))
    return check_results
示例#6
0
def run(config):
    """
    Gets a copy of the file from dropbox store. If specified gets
    """
    # Get client
    client, config = authutils.build_client(config)

    # Get the remote path for the given file
    # TODO Might need a check if `local_file` is a dir
    remote_path = pathutils.find_remote_db_path(config.get("local_file"))

    try:
        get_file = __do_output(remote_path, client, config)
    except dbrest.ErrorResponse as err:
        msg = {
            "local_file": config.get("local_file"),
            "remote_path": remote_path,
            "body": err.body,
            "message": err.message,
        }
        __log__.exception("Failed to output file! Error: {}".format(msg))

    return get_file