Ejemplo n.º 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)
Ejemplo n.º 2
0
def cmd_put(filename, public, stamped):
    """Upload file to aries."""
    if stamped:
        filename_org = filename
        filename = filename_with_timestamp(filename)
        if filename_org != filename:
            print('Filename is being changed: {0} -> {1}'
                  .format(filename_org, filename))
            yn = raw_input('Are you sure?[Y/n]: ')
            if yn not in 'yY':
                sys.stderr.write('Aborted!')
                sys.exit(1)
            os.rename(filename_org, filename)

    if public:
        print('Uploading to Google Drive...')
        stdout = upload_gdrive(filename)
        for line in stdout.splitlines():
            if line.startswith('Title:'):
                filename = line.split(' ')[-1].strip()
            elif line.startswith('Id:'):
                file_id = line.split(' ')[-1].strip()
        print('Done.')
        print('You can download it by:')
        dl_url = google_drive_file_url(file_id, download=True)
        print('$ wget {url} -O {file}'.format(url=dl_url, file=filename))
    else:
        print('Uploading to aries...')
        cmd = 'rsync -avz --progress -e "ssh -o StrictHostKeyChecking=no"\
            --bwlimit=100000 {file} {usr}@{host}:{dir}/private/'
        cmd = cmd.format(file=filename, usr=LOGIN_USER, host=HOST,
                         dir=DATA_DIR)
        subprocess.call(shlex.split(cmd))
        print('Done.')
Ejemplo n.º 3
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)