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)
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)
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)
def cmd_ls(public, query, show_size, sort, reverse): """Get list of files.""" if query is None: query = '' ls_options = [] if show_size: ls_options.append('--size') ls_options.append('--human-readable') if sort is not None: ls_options.append('--sort={0}'.format(sort)) if reverse: ls_options.append('--reverse') if public: if ls_options: sys.stderr.write( 'WARNING: if public=True, ignores all ls options\n') sys.stdout.write(list_gdrive()) else: print('\n'.join(_list_aries_files(query, ls_options)))
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))