Exemple #1
0
def cmd_pubinfo(filename, show_dl_cmd):
    if not filename:
        # FIXME: gdrive does not return full title if it is longer than 40
        candidates = list_gdrive().splitlines()
        selected = percol_select(candidates)
        if len(selected) != 1:
            sys.stderr.write('Please select 1 filename.\n')
            sys.exit(1)
        filename = selected[0].split()[1]

    stdout = list_gdrive()
    for line in stdout.splitlines():
        file_id, title = line.split()[:2]
        if filename == title:
            filename = info_gdrive(id=file_id, only_filename=True)
            break
    else:
        sys.stderr.write('file not found: {0}\n'.format(filename))
        sys.stderr.write('Run `jsk_data ls --public` to find files.\n')
        return

    dl_url = google_drive_file_url(file_id, download=True)
    if show_dl_cmd:
        info = 'wget {url} -O {file}'.format(url=dl_url, file=filename)
        sys.stdout.write(info)  # no new line for copy with pipe
    else:
        view_url = google_drive_file_url(file_id)
        info = '''\
Id: {id}
Filename: {file}
View URL: {view_url}
Download URL: {dl_url}'''.format(id=file_id, file=filename,
                                 view_url=view_url, dl_url=dl_url)
        print(info)
Exemple #2
0
def cmd_delete(public, filename):
    """Delete specified file."""
    if not public:
        sys.stderr.write('ERROR: public=False is not supported\n')
        sys.exit(1)

    if not filename:
        # FIXME: gdrive does not return full title if it is longer than 40
        candidates = list_gdrive().splitlines()
        selected = percol_select(candidates)
        if len(selected) != 1:
            sys.stderr.write('Please select 1 filename.\n')
            sys.exit(1)
        filename = selected[0].split()[1]

    delete_gdrive(filename=filename)
Exemple #3
0
def cmd_get(public, query):
    """Download specified file."""
    if not query:
        candidates = _list_aries_files(public=public)
        selected = percol_select(candidates)
        if len(selected) != 1:
            sys.stderr.write('Please select 1 filename.\n')
            sys.exit(1)
        filename = selected[0]

    public_level = 'public' if public else 'private'
    cmd = 'rsync -avz --progress -e "ssh -o StrictHostKeyChecking=no"\
           --bwlimit=100000 {usr}@{host}:{dir}/{lv}/{q} .'
    cmd = cmd.format(usr=LOGIN_USER, host=HOST,
                     dir=DATA_DIR, lv=public_level, q=query)
    subprocess.call(shlex.split(cmd))
Exemple #4
0
def cmd_get(public, query):
    """Download specified file."""
    if not query:
        if public:
            lines = list_gdrive().splitlines()
            candidates = [l.split()[1] for l in lines]
        else:
            candidates = _list_aries_files()
        selected = percol_select(candidates)
        if len(selected) != 1:
            sys.stderr.write('Please select 1 filename.\n')
            sys.exit(1)
        query = selected[0]
        sys.stderr.write('Selected: {0}\n'.format(query))

    if public:
        download_gdrive(filename=query)
    else:
        cmd = 'rsync -avz --progress -e "ssh -o StrictHostKeyChecking=no"\
            --bwlimit=100000 {usr}@{host}:{dir}/private/{q} .'
        cmd = cmd.format(usr=LOGIN_USER, host=HOST, dir=DATA_DIR, q=query)
        subprocess.call(shlex.split(cmd))
Exemple #5
0
def cmd_pubinfo(filename, show_dl_cmd):
    if not filename:
        candidates = _list_aries_files(public=True)
        selected = percol_select(candidates)
        if len(selected) != 1:
            sys.stderr.write('Please select 1 filename.\n')
            sys.exit(1)
        filename = selected[0]

    with connect_ssh(HOST, LOGIN_USER) as ssh:
        cmd = '{dir}/scripts/list-public-data.sh'.format(dir=DATA_DIR)
        _, stdout, stderr = ssh.exec_command(cmd)
        stdout.next()  # drop header
        for line in stdout.readlines():
            file_id, title = line.split()[:2]
            # FIXME: gdrive does not return full title if it is longer than 40
            if len(filename) > 40:
                filename = filename[:19] + '...' + filename[-18:]
            if filename == title:
                break
        else:
            sys.stderr.write('file not found: {0}\n'.format(filename))
            sys.stderr.write('Run `jsk_data ls --public` to find files.\n')
            return

    dl_url = google_drive_file_url(file_id, download=True)
    if show_dl_cmd:
        info = 'wget {url} -O {file}'.format(url=dl_url, file=filename)
        sys.stdout.write(info)  # no new line for copy with pipe
    else:
        view_url = google_drive_file_url(file_id)
        info = '''\
Id: {id}
Filename: {file}
View URL: {view_url}
Download URL: {dl_url}'''.format(id=file_id, file=filename,
                                 view_url=view_url, dl_url=dl_url)
        print(info)
Exemple #6
0
def cmd_pubinfo(filename, show_dl_cmd):
    if not filename:
        candidates = list_gdrive().splitlines()
        selected = percol_select(candidates)
        if len(selected) != 1:
            sys.stderr.write('Please select 1 filename.\n')
            sys.exit(1)
        filename = selected[0].split()[1]

    # FIXME: gdrive does not return full title if it is longer than 40
    if len(filename) > 40:
        filename = filename[:19] + '...' + filename[-18:]

    stdout = list_gdrive()
    for line in stdout.splitlines():
        file_id, title = line.split()[:2]
        if filename == title:
            filename = info_gdrive(id=file_id, only_filename=True)
            break
    else:
        sys.stderr.write('file not found: {0}\n'.format(filename))
        sys.stderr.write('Run `jsk_data ls --public` to find files.\n')
        return

    dl_url = google_drive_file_url(file_id, download=True)
    if show_dl_cmd:
        info = 'wget {url} -O {file}'.format(url=dl_url, file=filename)
        sys.stdout.write(info)  # no new line for copy with pipe
    else:
        view_url = google_drive_file_url(file_id)
        info = '''\
Id: {id}
Filename: {file}
View URL: {view_url}
Download URL: {dl_url}'''.format(id=file_id, file=filename,
                                 view_url=view_url, dl_url=dl_url)
        print(info)