コード例 #1
0
def get_file(*args, **kwargs):
    if len(args) == 0 or '--help' in ''.join(args):
        map(print, [
            'About: This command retrieves a file from the virtual file system if it exists.',
            '', 'Usage: $ dcc get <virtual path> (<local path>)', '',
            'By default this will output the contents of the file to standard output unless the `<local path>` is specified.',
            'The `<local path>` can optionally include the filename otherwise the name of the file when uploaded will be used.'
        ])
        return 1
    encryption_key, signing_key, api_token, human_container_name, container_name = prompt_userinfo(
    )
    vfs = load_vfs(api_token, container_name, encryption_key, signing_key)
    vfs_exists, data = vfs.get_file_data(args[0])
    if not vfs_exists:
        print('Error: The path `%s` does not exist.' % args[0])
        return 1
    if len(args) >= 2:  # if we have virtual path and local path
        local_path = normpath(join(getcwd(), args[1].strip()))
        if len(local_path) > 0:
            local_filename = basename(local_path)
            if len(local_filename) > 0 and '.' not in local_filename:
                local_filename = ''
            if len(local_filename) > 0:
                local_path = local_path[:-len(local_filename)]
            else:
                local_filename = data[0]
            if not exists(local_path):
                makedirs(local_path)
            with open(join(local_path, local_filename), 'w+') as output_file:
                content = download_file(api_token, container_name, data[2])
                output_file.write(decrypt(content, encryption_key,
                                          signing_key))
                return 0
    # else we do not have the local path, we need to output to standard out
    content = download_file(api_token, container_name, data[2])
    print(decrypt(content, encryption_key, signing_key))
    return 0
コード例 #2
0
def get_file(*args, **kwargs):
    if len(args) == 0 or '--help' in ''.join(args):
        map(print, [
            'About: This command retrieves a file from the virtual file system if it exists.',
            '',
            'Usage: $ dcc get <virtual path> (<local path>)',
            '',
            'By default this will output the contents of the file to standard output unless the `<local path>` is specified.',
            'The `<local path>` can optionally include the filename otherwise the name of the file when uploaded will be used.'
        ])
        return 1
    encryption_key, signing_key, api_token, human_container_name, container_name = prompt_userinfo()
    vfs = load_vfs(api_token, container_name, encryption_key, signing_key)
    vfs_exists, data = vfs.get_file_data(args[0])
    if not vfs_exists:
        print('Error: The path `%s` does not exist.' % args[0])
        return 1
    if len(args) >= 2: # if we have virtual path and local path
        local_path = normpath(join(getcwd(), args[1].strip()))
        if len(local_path) > 0:
            local_filename = basename(local_path)
            if len(local_filename) > 0 and '.' not in local_filename:
                local_filename = ''
            if len(local_filename) > 0:
                local_path = local_path[:-len(local_filename)]
            else:
                local_filename = data[0]
            if not exists(local_path):
                makedirs(local_path)
            with open(join(local_path, local_filename), 'w+') as output_file:
                content = download_file(api_token, container_name, data[2])
                output_file.write(decrypt(content, encryption_key, signing_key))
                return 0
    # else we do not have the local path, we need to output to standard out
    content = download_file(api_token, container_name, data[2])
    print(decrypt(content, encryption_key, signing_key))
    return 0
コード例 #3
0
def sync_files(*args, **kwargs):
    encryption_key, signing_key, api_token, human_container_name, container_name = prompt_userinfo()
    vfs = load_vfs(api_token, container_name, encryption_key, signing_key)
    for _, (file_name, path, file_uuid) in vfs.files.iteritems():
        path = path[:-len(basename(path))]
        print('Attempting to write `%s` ~> `%s`' % (file_name, path))
        if not exists(path):
            makedirs(path)
            print(' [OK] Created Path `%s`' % path)
        decrypted_file = decrypt(download_file(api_token, container_name, file_uuid), encryption_key, signing_key)
        print(' [OK] Downloaded and decrypted `%s`' % file_uuid)
        with open(join(path, file_name), 'w+') as output_file:
            output_file.write(decrypted_file)
            print(' [OK] Wrote file `%s`' % file_name)
    return 0
コード例 #4
0
def sync_files(*args, **kwargs):
    encryption_key, signing_key, api_token, human_container_name, container_name = prompt_userinfo(
    )
    vfs = load_vfs(api_token, container_name, encryption_key, signing_key)
    for _, (file_name, path, file_uuid) in vfs.files.iteritems():
        path = path[:-len(basename(path))]
        print('Attempting to write `%s` ~> `%s`' % (file_name, path))
        if not exists(path):
            makedirs(path)
            print(' [OK] Created Path `%s`' % path)
        decrypted_file = decrypt(
            download_file(api_token, container_name, file_uuid),
            encryption_key, signing_key)
        print(' [OK] Downloaded and decrypted `%s`' % file_uuid)
        with open(join(path, file_name), 'w+') as output_file:
            output_file.write(decrypted_file)
            print(' [OK] Wrote file `%s`' % file_name)
    return 0
コード例 #5
0
import client

if __name__ == '__main__':
    print('We provide the following two functions: ')
    print('1. Upload file ')
    print('2. Download file \n')
    print('Please input the function number you want: (eg. 1) ')
    option = input()
    if option == '1':
        print(
            'Please input the file name you want to upload: (eg. Goodbye.txt) '
        )
    else:
        print(
            'Please input the file name you want to download: (eg. Goodbye.txt) '
        )
    filename = input()
    if option == '1':
        print('Upload... ')
        client.upload_file(filename)
    else:
        print('Download... ')
        client.download_file(filename)