本文整理汇总了Python中girder_client.GirderClient.uploadFile方法的典型用法代码示例。如果您正苦于以下问题:Python GirderClient.uploadFile方法的具体用法?Python GirderClient.uploadFile怎么用?Python GirderClient.uploadFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类girder_client.GirderClient
的用法示例。
在下文中一共展示了GirderClient.uploadFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_calc
# 需要导入模块: from girder_client import GirderClient [as 别名]
# 或者: from girder_client.GirderClient import uploadFile [as 别名]
def import_calc(config):
try:
target_port = None
if config.port:
target_port = config.port
target_scheme = None
if config.scheme:
target_scheme = config.scheme
target_apiroot = None
if config.apiroot:
target_apiroot = config.apiroot
client = GirderClient(host=config.host, port=target_port,
scheme=target_scheme, apiRoot=target_apiroot)
client.authenticate(apiKey=config.apiKey)
me = client.get('/user/me')
if not me:
print('Error: Girder token invalid, please verify')
return
folderParams = {
'parentId': me['_id'],
'parentType': 'user',
'name': 'Private'
}
# Get the private folder id first
folder = next(client.listResource('folder', folderParams))
folder = next(client.listFolder(me['_id'], 'user', 'Private'))
for file_name in config.datafile:
print ('\nUploading ' + file_name)
file_id = {}
with open(file_name, 'r') as fp:
fileNameBase = os.path.basename(file_name)
size = os.path.getsize(file_name)
file_id = client.uploadFile(folder['_id'], fp, fileNameBase,
size, 'folder')
body = {
'fileId': file_id['_id']
}
if config.public:
body['public'] = True
mol = client.sendRestRequest('POST', 'molecules', data=json.dumps(body))
if mol and '_id' in mol:
config.moleculeId = mol['_id']
print('Molecule ID: ' + mol['_id'])
else:
print(mol)
except HttpError as error:
print(error.responseText, file=sys.stderr)
示例2: BaseIntegrationTest
# 需要导入模块: from girder_client import GirderClient [as 别名]
# 或者: from girder_client.GirderClient import uploadFile [as 别名]
class BaseIntegrationTest(unittest.TestCase):
def __init__(self, name, girder_url, girder_user, girder_password, job_timeout=60, cleanup=True):
super(BaseIntegrationTest, self).__init__(name)
self._job_id = None
self._script_id = None
self._output_folder_id = None
self._input_folder_id = None
self._girder_url = girder_url
self._girder_user = girder_user
self._girder_password = girder_password
self._job_timeout = job_timeout
self._data = 'Need more input!'
self._cleanup = cleanup
def setUp(self):
url = '%s/api/v1' % self._girder_url
self._client = GirderClient(apiUrl=url)
self._client.authenticate(self._girder_user,
self._girder_password)
user = self._client.get('user/me')
self._user_id = user['_id']
r = list(self._client.listFolder(self._user_id, 'user', name='Private'))
self.assertEqual(len(r), 1)
self._private_folder_id = r[0]['_id']
def tearDown(self):
if not self._cleanup:
return
if self._job_id:
try:
url = 'jobs/%s' % self._job_id
self._client.delete(url)
except Exception as e:
traceback.print_exc()
if self._script_id:
try:
url = 'scripts/%s' % self._script_id
self._client.delete(url)
except Exception:
traceback.print_exc()
if self._output_folder_id:
try:
url = 'folder/%s' % self._output_folder_id
self._client.delete(url)
except Exception:
traceback.print_exc()
if self._input_folder_id:
try:
url = 'folder/%s' % self._input_folder_id
self._client.delete(url)
except Exception:
traceback.print_exc()
def create_script(self, commands=[
'sleep 10', 'cat CumulusIntegrationTestInput'
]):
body = {
'commands': commands,
'name': 'CumulusIntegrationTestLob'
}
r = self._client.post('scripts', data=json.dumps(body))
self._script_id = r['_id']
def create_input(self, folder_name='CumulusInput'):
r = self._client.createFolder(self._private_folder_id, folder_name)
self._input_folder_id = r['_id']
size = len(self._data)
item = self._client.uploadFile(self._input_folder_id,
StringIO(self._data), 'CumulusIntegrationTestInput', size,
parentType='folder')
self._item_id = item['itemId']
def create_output_folder(self, folder_name='CumulusOutput'):
r = self._client.createFolder(self._private_folder_id, folder_name)
self._output_folder_id = r['_id']
def create_job(self, job_name='CumulusIntegrationTestJob', tail=None):
body = {
'name': job_name,
'scriptId': self._script_id,
'output': [{
'folderId': self._output_folder_id,
'path': '.'
}],
'input': [
{
'folderId': self._input_folder_id,
'path': '.'
}
]
#.........这里部分代码省略.........