def client2(use_dev): bf = Blackfynn('*****@*****.**', 'password') # get organizations orgs = bf.organizations() assert len(orgs) > 0 # explicitly set context to Blackfyn org bf.set_context('Test Organization') assert bf.context is not None return bf
def get_test_client(profile=None, api_token=None, api_secret=None, **overrides): """ Utility function to get a Blackfynn client object """ bf = Blackfynn(profile=profile, api_token=api_token, api_secret=api_secret, **overrides) assert bf.context is not None orgs = bf.organizations() assert len(orgs) > 0 # explicitly set context to Blackfyn org assert bf.context is not None return bf
def client2(): api_token = os.environ.get('BLACKFYNN_API_TOKEN2') api_secret = os.environ.get('BLACKFYNN_API_SECRET2') assert api_token != "", "Must define BLACKFYNN_API_TOKEN2" assert api_secret != "", "Must define BLACKFYNN_API_SECRET2" bf = Blackfynn() # get organizations orgs = bf.organizations() assert len(orgs) > 0 # explicitly set context to Blackfyn org assert bf.context is not None return bf
def client(): """ Login via API, return client. Login information, by default, will be taken from environment variables, so ensure those are set properly before testing. Alternatively, to force a particular user, adjust input arguments as necessary. """ bf = Blackfynn() # get organizations orgs = bf.organizations() print 'organizations =', orgs assert len(orgs) > 0 # explicitly set context to Blackfyn org assert bf.context is not None return bf
def blackfynn_cli(): args = docopt(__doc__) if args['version']: print "version: {}".format(blackfynn.__version__) email = args['--user'] if args['--user'] is not None else settings.api_user passw = args['--pass'] if args['--pass'] is not None else settings.api_pass host = args['--host'] if args['--host'] is not None else settings.api_host org = args['--org'] try: bf = Blackfynn(email=email, password=passw, host=host) except: print "Unable to connect to to Blackfynn using specified user/password." return if args['orgs']: for o in bf.organizations(): print " * {} (id: {})".format(o.name, o.id) if org is not None: try: bf.set_context(org) except: print 'Error: Unable to set context to "{}"'.format(org) return if args['show']: item = bf.get(args['<item>']) print item if hasattr(item, 'items'): print "CONTENTS:" for i in item.items: print " * {}".format(i) if hasattr(item, 'channels'): print "CHANNELS:" for ch in item.channels: print " * {} (id: {})".format(ch.name, ch.id) elif args['search']: terms = ' '.join(args['<term>']) results = bf._api.search.query(terms) if len(results) == 0: print "No Results." else: for r in results: print " * {}".format(r) elif args['create']: if args['collection']: dest = args['<destination>'] name = args['<name>'] c = Collection(name) parent = bf.get(dest) parent.add(c) print c elif args['dataset']: name = args['<name>'] ds = bf.create_dataset(name) print ds else: print "Error: creation for object not supported." return elif args['delete']: item = bf.get(args['<item>']) if isinstance(item, Dataset): print "Error: cannot delete dataset" return elif not isinstance(item, BaseNode): print "Error: cannot delete item" return bf.delete(item) elif args['upload']: files = args['<file>'] dest = args['<destination>'] recursively_upload(bf, dest, files) elif args['append']: files = args['<file>'] dest = args['<destination>'] bf._api.io.upload_files(dest, files, append=True, display_progress=True) elif args['datasets']: print "Datasets: " for ds in bf.datasets(): print " - {} (id: {})".format(ds.name, ds.id) elif args['dataset']: ds = bf.get(args['<dataset>']) if args['collaborators']: if args['<action>'] == 'ls': resp = ds.collaborators() print " - Users" for u in resp['users']: print " - email:{} id:{}".format(u.email, u.id) print " - Groups" for g in resp['groups']: print " - name:{} id:{}".format(g.name, g.id) elif args['<action>'] == 'add': ids = args['<action-args>'] if len(ids) == 0: print "Error: No ids specified" sys.exit(1) resp = ds.add_collaborators(*ids) print_collaborator_edit_resp(resp) elif args['<action>'] == 'rm': ids = args['<action-args>'] if len(ids) == 0: print "Error: No ids specified" sys.exit(1) resp = ds.remove_collaborators(*ids) print_collaborator_edit_resp(resp) else: print "Error: invalid dataset collaborators command. Valid commands are 'ls', 'add' or 'rm'" else: print "Error: invalid dataset command. Valid commands are 'collaborators'" elif args['env']: print "# Blackfynn environment" print "API Location: {}".format(host) print "Streaming API: {}".format(settings.streaming_api_host) print "User: {}".format(email) print "Organization: {} (id: {})".format(bf.context.name, bf.context.id)