def logout(): pc = PilotClient() if pc.is_logged_in(): pc.logout() click.echo('You have been logged out.') else: click.echo('No user logged in, no logout necessary.')
def login(refresh_tokens, force, local_server, browser): pc = PilotClient() is_logged_in = pc.is_logged_in() if is_logged_in and not force: click.echo('You are already logged in.') return elif is_logged_in and force: pc.logout() pc.login(refresh_tokens=refresh_tokens, no_local_server=not local_server, no_browser=not browser, force=force) click.echo('You have been logged in.')
def list_command(test, output_json, limit): # Should require login if there are publicly visible records pc = PilotClient() if not pc.is_logged_in(): click.echo('You are not logged in.') return search_authorizer = pc.get_authorizers()['search.api.globus.org'] sc = globus_sdk.SearchClient(authorizer=search_authorizer) # TO DO: iterate instead of upping limit search_results = sc.search(index_id=pc.get_index(test), q='*', limit=limit) if output_json: click.echo(json.dumps(search_results.data, indent=4)) return fmt = '{:21.20}{:11.10}{:10.9}{:7.6}{:7.6}{:7.6}{}' columns = [ ('Title', lambda r: r['dc']['titles'][0]['title']), ('Data', lambda r: r['ncipilot']['data_type']), ('Dataframe', lambda r: r['ncipilot']['dataframe_type']), ('Rows', lambda r: str(r['field_metadata']['numrows'])), ('Cols', lambda r: str(r['field_metadata']['numcols'])), ('Size', get_size), ('Filename', get_identifier), ] # Build row data rows = [] for result in search_results['gmeta']: content = result['content'][0] if content.get('testing'): content = content['testing'] row = [] for _, function in columns: try: row.append(function(content)) except Exception: row.append('') # raise rows.append(row) formatted_rows = [fmt.format(*r) for r in rows] header = fmt.format(*[c[0] for c in columns]) output = '{}\n{}'.format(header, '\n'.join(formatted_rows)) click.echo(output)
def describe(path, test, output_json): pc = PilotClient() if not pc.is_logged_in(): click.echo('You are not logged in.') return old_entry = False fname, dirname = os.path.basename(path), os.path.dirname(path) entry = pc.get_search_entry(fname, dirname, test) if not entry: old_entry = True entry = pc.get_search_entry(fname, dirname, old=True) if not entry: click.echo('Unable to find entry') return if output_json: click.echo(json.dumps(entry, indent=4)) return general_fmt = '{:21.20}{}' general_columns = [ ('Title', lambda r: r['dc']['titles'][0]['title']), ('Authors', lambda r: [c['creatorName'] for c in r['dc']['creators']]), ('Publisher', lambda r: r['dc']['publisher']), ('Subjects', lambda r: [s['subject'] for s in r['dc']['subjects']]), ('Dates', get_dates), ('Data', lambda r: r['ncipilot']['data_type']), ('Dataframe', lambda r: r['ncipilot']['dataframe_type']), ('Rows', lambda r: str(r['field_metadata']['numrows'])), ('Columns', lambda r: str(r['field_metadata']['numcols'])), ('Formats', lambda r: r['dc']['formats']), ('Version', lambda r: r['dc']['version']), ('Size', get_size), ('Filename', get_identifier), ('Description', lambda r: r['dc']['descriptions'][0]['description']), ] def format_list(name, content): return [general_fmt.format(name, content[0])] + \ [general_fmt.format('', item) for item in content[1:]] def format_entry(name, content): return [general_fmt.format(name, content)] output = fetch_format(general_columns, entry, format_entry, format_list) fmt = ('{:21.20}' '{:8.7}{:7.6}{:5.4}{:12.11}{:7.6}' '{:7.6}{:7.6}{:7.6}{:7.6}' '{:8.7}{:8.7}{:8.7}' ) field_metadata = [ ('Column Name', 'name'), ('Type', 'type'), ('Count', 'count'), ('Freq', 'frequency'), ('Top', 'top'), ('Unique', 'unique'), ('Min', 'min'), ('Max', 'max'), ('Mean', 'mean'), ('Std', 'std'), ('25-PCTL', '25'), ('50-PCTL', '50'), ('75-PCTL', '75'), ] names = [n for n, f in field_metadata] keys = [f for n, f in field_metadata] fm_output = [] try: for field in entry['field_metadata']['field_definitions']: f_metadata = [str(field.get(key, '')) for key in keys] fm_output.append(fmt.format(*f_metadata)) field_metadata_names = fmt.format(*names) output = '{}\n\nField Metadata\n{}\n{}'.format(output, field_metadata_names, '\n'.join(fm_output)) except KeyError: output = '{}\n\nField Metadata\nNo Field Metadata'.format(output) if not test: sub = pc.get_subject_url(fname, dirname, test, old=old_entry) qsub = urllib.parse.quote_plus(urllib.parse.quote_plus(sub)) portal_url = '{}{}'.format(PORTAL_DETAIL_PAGE_PREFIX, qsub) other_data = [general_fmt.format('Subject', sub), general_fmt.format(path, portal_url)] output = '{}\n\nOther Data\n{}'.format(output, '\n'.join(other_data)) click.echo(output)