Ejemplo n.º 1
0
def download_by_skynet(resource_info, file_name):
    def sky_get(skynet_id, target_dir, timeout=None):
        cmd_args = [
            _sky_path(), 'get', "-N", "Backbone", "--user", "--wait", "--dir",
            target_dir, skynet_id
        ]
        if timeout is not None:
            cmd_args += ["--timeout", str(timeout)]
        logging.info('Call skynet with args: %s', cmd_args)
        stdout = subprocess.check_output(cmd_args).strip()
        logging.debug('Skynet call with args %s is finished, result is %s',
                      cmd_args, stdout)
        return stdout

    if not _is_skynet_avaliable():
        raise UnsupportedProtocolException("Skynet is not available")

    skynet_id = resource_info.get("skynet_id")
    if not skynet_id:
        raise ValueError("Resource does not have skynet_id")

    temp_dir = os.path.abspath(fetch_from.uniq_string_generator())
    os.mkdir(temp_dir)
    sky_get(skynet_id, temp_dir)
    return os.path.join(temp_dir, file_name)
Ejemplo n.º 2
0
def fetch(skynet_id, file_name, timeout=None):
    if not is_avaliable():
        raise UnsupportedProtocolException("Skynet is not available")

    target_dir = os.path.abspath(fetch_from.uniq_string_generator())
    os.mkdir(target_dir)

    cmd_args = [
        executable_path(), "get", "-N", "Backbone", "--user", "--wait",
        "--dir", target_dir, skynet_id
    ]
    if timeout is not None:
        cmd_args += ["--timeout", str(timeout)]

    logging.info("Call skynet with args: %s", cmd_args)
    stdout = subprocess.check_output(cmd_args).strip()
    logging.debug("Skynet call with args %s is finished, result is %s",
                  cmd_args, stdout)

    return os.path.join(target_dir, file_name)