当前位置: 首页>>代码示例>>Python>>正文


Python GirderClient.downloadFile方法代码示例

本文整理汇总了Python中girder_client.GirderClient.downloadFile方法的典型用法代码示例。如果您正苦于以下问题:Python GirderClient.downloadFile方法的具体用法?Python GirderClient.downloadFile怎么用?Python GirderClient.downloadFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在girder_client.GirderClient的用法示例。


在下文中一共展示了GirderClient.downloadFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BaseIntegrationTest

# 需要导入模块: from girder_client import GirderClient [as 别名]
# 或者: from girder_client.GirderClient import downloadFile [as 别名]

#.........这里部分代码省略.........
        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': '.'
              }
            ]
        }

        if tail:
            body['output'].append({
                "path": tail,
                "tail": True
            })

        job = self._client.post('jobs', data=json.dumps(body))
        self._job_id = job['_id']

    def submit_job(self, job_params={}, timeout=None):
        url = 'clusters/%s/job/%s/submit' % (self._cluster_id, self._job_id)

        self._client.put(url, data=json.dumps(job_params))
        start = time.time()
        while True:
            time.sleep(1)
            r = self._client.get('jobs/%s' % self._job_id)

            if r['status'] in ['error', 'unexpectederror']:
                r = self._client.get('jobs/%s/log' % self._job_id)
                self.fail(str(r))
            elif r['status'] == 'complete':
                break

            if time.time() - start > timeout:
                self.fail('Job didn\'t complete in timeout')

    def assert_output(self):
        r = self._client.listItem(self._output_folder_id)
        self.assertEqual(len(r), 4)

        stdout_item = None
        for i in r:
            if i['name'].startswith('CumulusIntegrationTestJob-%s.o' % self._job_id):
                stdout_item = i
                break

        self.assertIsNotNone(stdout_item)
        r = self._client.get('item/%s/files' % i['_id'])
        self.assertEqual(len(r), 1)

        path = os.path.join(tempfile.gettempdir(), self._job_id)
        try:
            self._client.downloadFile(r[0]['_id'], path)
            with open(path, 'rb') as fp:
                self.assertEqual(fp.read(), self._data)

        finally:
            if os.path.exists(path):
                os.remove(path)
开发者ID:Kitware,项目名称:cumulus,代码行数:104,代码来源:base_integration_test.py

示例2: str

# 需要导入模块: from girder_client import GirderClient [as 别名]
# 或者: from girder_client.GirderClient import downloadFile [as 别名]
dataset_folder_id = dataset_folder['_id']
parameters = {
    'id': fileId,
    'type': 'file'
}

# Get the file resource so we can get the name
input_file = client.get('resource/%s' % str(fileId), parameters=parameters)
input_file_name = input_file['name']
output_file_name = input_file_name.replace('.nc', '.json')

try:
    # Now download the dataset
    (fd, filepath) = tempfile.mkstemp()
    os.close(fd)
    client.downloadFile(fileId, filepath)

    # Create temp file and convert to GeoJs contour JSON format
    output_dir = tempfile.mkdtemp()
    output_filepath = os.path.join(output_dir, output_file_name)
    with open(output_filepath, 'w') as fp:
        fp.write(json_util.dumps(convert(filepath, variable, timestep)))

    # Create an item for this file
    output_item = client.createItem(dataset_folder_id, output_file_name, output_file_name)

    # Now upload the result
    client.uploadFileToItem(output_item['_id'], output_filepath)

    output_item_id = output_item['_id']
开发者ID:essamjoubori,项目名称:minerva,代码行数:32,代码来源:contour.py


注:本文中的girder_client.GirderClient.downloadFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。