def store(args, syn): #If we are storing a fileEntity we need to have id or parentId if args.parentid is None and args.id is None and args.file is not None: raise ValueError('synapse store requires at least either parentId or id to be specified.') #If both args.FILE and args.file specified raise error if args.file and args.FILE: raise ValueError('only specify one file') args.file = args.FILE if args.FILE is not None else args.file args.type = 'FileEntity' if args.type == 'File' else args.type if args.id is not None: entity = syn.get(args.id) else: entity = {'concreteType': u'org.sagebionetworks.repo.model.%s' % args.type, 'name': utils.guess_file_name(args.file) if args.file and not args.name else None, 'parentId' : None, 'description' : None, 'path': args.file} #Overide setting for parameters included in args entity['name'] = args.name if args.name is not None else entity['name'] entity['description'] = args.description if args.description is not None else entity['description'] entity['parentId'] = args.parentid if args.parentid is not None else entity['parentId'] entity['path'] = args.file if args.file is not None else None if utils.is_url(args.file): entity['synapseStore'] = False used = _convertProvenanceList(args.used, args.limitSearch, syn) executed = _convertProvenanceList(args.executed, args.limitSearch, syn) entity = syn.store(entity, used=used, executed=executed) print 'Created/Updated entity: %s\t%s' %(entity['id'], entity['name'])
def store(args, syn): #If we are storing a fileEntity we need to have id or parentId if args.parentid is None and args.id is None and args.file is not None: raise ValueError( 'synapse store requires at least either parentId or id to be specified.' ) #If both args.FILE and args.file specified raise error if args.file and args.FILE: raise ValueError('only specify one file') args.file = args.FILE if args.FILE is not None else args.file args.type = 'FileEntity' if args.type == 'File' else args.type if args.id is not None: entity = syn.get(args.id, downloadFile=False) else: entity = { 'concreteType': u'org.sagebionetworks.repo.model.%s' % args.type, 'name': utils.guess_file_name(args.file) if args.file and not args.name else None, 'parentId': None, 'description': None, 'path': args.file } #Overide setting for parameters included in args entity['name'] = args.name if args.name is not None else entity['name'] entity[ 'description'] = args.description if args.description is not None else entity.get( 'description', None) entity[ 'parentId'] = args.parentid if args.parentid is not None else entity[ 'parentId'] entity['path'] = args.file if args.file is not None else None entity['synapseStore'] = not utils.is_url(args.file) used = _convertProvenanceList(args.used, args.limitSearch, syn) executed = _convertProvenanceList(args.executed, args.limitSearch, syn) entity = syn.store(entity, used=used, executed=executed) print 'Created/Updated entity: %s\t%s' % (entity['id'], entity['name']) # After creating/updating, if there are annotations to add then # add them if args.annotations is not None: # Need to override the args id parameter setattr(args, 'id', entity['id']) setAnnotations(args, syn)
def add(args, syn): if args.type == 'File': args.type = 'FileEntity' if args.file and not args.name: args.name = utils.guess_file_name(args.file) entity = {'name': args.name, 'parentId': args.parentid, 'description':args.description, 'concreteType': u'org.sagebionetworks.repo.model.%s' % args.type, 'path': args.file} if utils.is_url(args.file): entity['synapseStore'] = False entity = syn.store(entity, used=args.used, executed=args.executed) print 'Created/Updated entity: %s\t%s from file: %s' %(entity['id'], entity['name'], args.file)