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


Python girder_client.GirderClient类代码示例

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


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

示例1: NewtIntegrationTest

class NewtIntegrationTest(BaseIntegrationTest):
    def __init__(self, name, girder_url, girder_user, girder_password, machine, job_timeout=60 * 5):
        super(NewtIntegrationTest, self).__init__(name, girder_url, girder_user, girder_password, job_timeout)
        self._cluster_id = None
        self._machine = machine

    def setUp(self):

        # First authenticate with NEWT
        self._session = Session()
        r = self._session.post(
            "https://newt.nersc.gov/newt/auth", {"username": self._girder_user, "password": self._girder_password}
        )

        self.assertEqual(r.status_code, 200)
        print r.json()
        self._newt_session_id = r.json()["newt_sessionid"]

        # Now authenticate with Girder using the session id
        url = "%s/api/v1/newt/authenticate/%s" % (self._girder_url, self._newt_session_id)
        r = self._session.put(url)
        self.assertEqual(r.status_code, 200)

        url = "%s/api/v1/newt/authenticate/%s" % (self._girder_url, self._newt_session_id)
        r = self._session.put(url)
        self.assertEqual(r.status_code, 200)

        url = "%s/api/v1" % self._girder_url
        self._client = GirderClient(apiUrl=url)
        self._client.token = self._session.cookies["girderToken"]

        user = self._client.get("user/me")
        self._user_id = user["_id"]
        r = self._client.listFolder(self._user_id, "user", name="Private")
        r = list(r)
        self.assertEqual(len(r), 1)
        self._private_folder_id = r[0]["_id"]

    def tearDown(self):
        super(NewtIntegrationTest, self).tearDown()
        if self._cluster_id:
            try:
                url = "clusters/%s" % self._cluster_id
                self._client.delete(url)
            except Exception:
                traceback.print_exc()

    def create_cluster(self):
        body = {"config": {"host": self._machine}, "name": "NewtIntegrationTest", "type": "newt"}

        r = self._client.post("clusters", data=json.dumps(body))
        self._cluster_id = r["_id"]

        # Now test the connection
        r = self._client.put("clusters/%s/start" % self._cluster_id)
        sleeps = 0
        while True:
            time.sleep(1)
            r = self._client.get("clusters/%s/status" % self._cluster_id)

            if r["status"] == "running":
                break
            elif r["status"] == "error":
                r = self._client.get("clusters/%s/log" % self._cluster_id)
                self.fail(str(r))

            if sleeps > 9:
                self.fail("Cluster never moved into running state")
            sleeps += 1

    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)

        url = "%s/api/v1/file/%s/download" % (self._girder_url, r[0]["_id"])
        r = self._session.get(url)
        self.assertEqual(r.content, self._data)

    def test(self):
        try:
            self.create_cluster()
            self.create_script()
            self.create_input()
            self.create_output_folder()
            self.create_job()
            self.submit_job(timeout=self._job_timeout)
            self.assert_output()
        except HttpError as error:
            self.fail(error.responseText)
开发者ID:Kitware,项目名称:cumulus,代码行数:99,代码来源:newt_integration_test.py

示例2: __init__

 def __init__(self, apiKey, objectStore):
     """initialization function to create a GirderCli instance, will attempt
     to authenticate with the designated Girder instance.
     """
     GirderClient.__init__(self, apiUrl="https://data.kitware.com/api/v1")
     self.objectStore = objectStore
     self.authenticate(apiKey=apiKey)
开发者ID:Kitware,项目名称:ITK,代码行数:7,代码来源:ArchiveTestingDataOnGirder.py

示例3: main

def main(config):
    client = GirderClient(apiUrl=config.girder_api_url)
    client.authenticate(config.girder_user,
                        config.girder_password)

    # Load any parameters
    params = {}
    if config.taskflow_start_params is not None:
        with open(config.taskflow_start_params) as fp:
            params = json.load(fp)

    print params

    try:
        print ('Running %s taskflow ...' % config.taskflow_start_params)
        taskflow_id = create_taskflow(
            client, config.taskflow_class)

        # Start the task flow
        url = 'taskflows/%s/start' % (taskflow_id)
        client.put(url, data=json.dumps(params))

        # Wait for it to complete
        wait_for_complete(client, taskflow_id)

    except HttpError as ex:
        print( ex.responseText)
开发者ID:Kitware,项目名称:HPCCloud,代码行数:27,代码来源:runner.py

示例4: _update_girder

    def _update_girder(taskflow, body):
        taskflow = to_taskflow(taskflow)
        taskflow_id = taskflow['id']
        girder_token = taskflow['girder_token']
        girder_api_url = taskflow['girder_api_url']

        client = GirderClient(apiUrl=girder_api_url)
        client.token = girder_token

        client = _create_girder_client(girder_api_url, girder_token)

        # If this is a retry then we have already create a task get it from
        # the current tasks headers.
        if body['retries'] > 0:
            taskflow_task_id = \
                current_task.request.headers[TASKFLOW_TASK_ID_HEADER]

            # Celery always fires the postrun handler with a state of SUCCESS
            # for retries. So we need to save the retries here so we can
            # determine in the postrun handler if the task is really complete.
            current_task.request.headers[TASKFLOW_RETRY_HEADER] \
                = body['retries']
        else:
                # This is a new task so create a taskflow task instance
            body = {
                'celeryTaskId': body['id'],
                'name': body['task']
            }
            url = 'taskflows/%s/tasks' % taskflow_id
            r = client.post(url, data=json.dumps(body))
            taskflow_task_id = r['_id']
        return taskflow, taskflow_task_id
开发者ID:Kitware,项目名称:cumulus,代码行数:32,代码来源:__init__.py

示例5: _taskflow_task_finished

def _taskflow_task_finished(taskflow, taskflow_task_id):
    girder_token = taskflow['girder_token']
    girder_api_url = taskflow['girder_api_url']

    client = GirderClient(apiUrl=girder_api_url)
    client.token = girder_token
    url = 'taskflows/%s/tasks/%s/finished' % (taskflow.id, taskflow_task_id)

    return client.put(url)
开发者ID:Kitware,项目名称:cumulus,代码行数:9,代码来源:__init__.py

示例6: _importAnalysis

    def _importAnalysis(self):
        """Setup and import analyses for bsve tests."""
        if self._import_done:
            return

        path = "/minerva_analysis/folder"
        response = self.request(path=path, method="POST", user=self._user)
        self.assertStatusOk(response)
        analyses_folder = response.json["folder"]

        # import the bsve analysis
        client = GirderClient("localhost", girder_port)
        client.authenticate("minervauser", "password")

        bsve_analysis_path = os.path.abspath(
            os.path.join(os.path.dirname(os.path.realpath(__file__)), "../analyses/bsve")
        )
        import_analyses.import_analyses(client, bsve_analysis_path)

        path = "/item"
        params = {"folderId": analyses_folder["_id"]}
        response = self.request(path=path, method="GET", params=params, user=self._user)
        self.assertStatusOk(response)
        self.assertEquals(len(response.json), 2, "Expecting only one analysis")
        for analysis in response.json:
            if analysis["name"] == "bsve search":
                search_analysis = analysis
            elif analysis["name"] == "MMWR data import":
                soda_analysis = analysis
            else:
                self.fail('Unexpected analysis found "%s".' % analysis["name"])
        expected_meta = {
            u"minerva": {
                u"analysis_type": u"bsve_search",
                u"analysis_name": u"bsve search",
                u"analysis_id": search_analysis["_id"],
            }
        }
        self.assertEquals(search_analysis["meta"], expected_meta, "Unexpected value for search meta data")
        expected_meta = {
            u"minerva": {
                u"analysis_type": u"mmwr_import_data",
                u"analysis_name": u"MMWR data import",
                u"analysis_id": soda_analysis["_id"],
            }
        }
        self.assertEquals(soda_analysis["meta"], expected_meta, "Unexpected value for soda meta data")

        # create the dataset folder
        path = "/minerva_dataset/folder"
        params = {"userId": self._user["_id"]}
        response = self.request(path=path, method="POST", params=params, user=self._user)
        self.assertStatusOk(response)
        self._importDone = True
开发者ID:Kitware,项目名称:minerva,代码行数:54,代码来源:analysis_test.py

示例7: upload_file

def upload_file(cluster, girder_token, file, path):
    """
    Upload a file to a cluster

    :param cluster: The cluster to upload to.
    :param girder_tokebn: The Grider token for Girder access.
    :param file: The Girder file object.
    :param path: The path on the cluster to upload to.
    """
    girder_client = GirderClient(apiUrl=cumulus.config.girder.baseUrl)
    girder_client.token = girder_token
    with get_connection(girder_token, cluster) as conn:
        conn.makedirs(os.path.dirname(path))
        _upload_file(conn, girder_client, file, path)
开发者ID:Kitware,项目名称:cumulus,代码行数:14,代码来源:upload.py

示例8: import_calc

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)
开发者ID:OpenChemistry,项目名称:mongochemserver,代码行数:58,代码来源:bulk_import.py

示例9: setUp

    def setUp(self):

        # First authenticate with NEWT
        self._session = Session()
        r = self._session.post(
            "https://newt.nersc.gov/newt/auth", {"username": self._girder_user, "password": self._girder_password}
        )

        self.assertEqual(r.status_code, 200)
        print r.json()
        self._newt_session_id = r.json()["newt_sessionid"]

        # Now authenticate with Girder using the session id
        url = "%s/api/v1/newt/authenticate/%s" % (self._girder_url, self._newt_session_id)
        r = self._session.put(url)
        self.assertEqual(r.status_code, 200)

        url = "%s/api/v1/newt/authenticate/%s" % (self._girder_url, self._newt_session_id)
        r = self._session.put(url)
        self.assertEqual(r.status_code, 200)

        url = "%s/api/v1" % self._girder_url
        self._client = GirderClient(apiUrl=url)
        self._client.token = self._session.cookies["girderToken"]

        user = self._client.get("user/me")
        self._user_id = user["_id"]
        r = self._client.listFolder(self._user_id, "user", name="Private")
        r = list(r)
        self.assertEqual(len(r), 1)
        self._private_folder_id = r[0]["_id"]
开发者ID:Kitware,项目名称:cumulus,代码行数:31,代码来源:newt_integration_test.py

示例10: setUp

    def setUp(self):

        # First authenticate with NEWT
        self._session = Session()
        r = self._session.post('https://newt.nersc.gov/newt/auth',
                               {
                                    'username': self._girder_user,
                                    'password': self._girder_password})

        self.assertEqual(r.status_code, 200)
        print r.json()
        self._newt_session_id = r.json()['newt_sessionid']

        # Now authenticate with Girder using the session id
        url = '%s/api/v1/newt/authenticate/%s' % (self._girder_url, self._newt_session_id)
        r = self._session.put(url)
        self.assertEqual(r.status_code, 200)

        url = '%s/api/v1/newt/authenticate/%s' % (self._girder_url, self._newt_session_id)
        r = self._session.put(url)
        self.assertEqual(r.status_code, 200)

        url = '%s/api/v1' % self._girder_url
        self._client = GirderClient(apiUrl=url)
        self._client.token = self._session.cookies['girderToken']

        user = self._client.get('user/me')
        self._user_id = user['_id']
        r = self._client.listFolder(self._user_id, 'user', name='Private')
        self.assertEqual(len(r), 1)
        self._private_folder_id = r[0]['_id']
开发者ID:mgrauer,项目名称:cumulus,代码行数:31,代码来源:newt_integration_test.py

示例11: __init__

    def __init__(self, username, password, dryrun, blacklist,
                 host=None, port=None, apiRoot=None, scheme=None, apiUrl=None):
        """initialization function to create a GirderCli instance, will attempt
        to authenticate with the designated Girder instance. Aside from username
        and password, all other kwargs are passed directly through to the
        :py:class:`girder_client.GirderClient` base class constructor.

        :param username: username to authenticate to Girder instance.
        :param password: password to authenticate to Girder instance, leave
            this blank to be prompted.
        """
        GirderClient.__init__(self, host=host, port=port,
                              apiRoot=apiRoot, scheme=scheme, dryrun=dryrun,
                              blacklist=blacklist, apiUrl=apiUrl)
        interactive = password is None
        self.authenticate(username, password, interactive=interactive)
开发者ID:anukat2015,项目名称:girder,代码行数:16,代码来源:cli.py

示例12: main

def main():
    parser = argparse.ArgumentParser(description='Import analyses into minerva')
    parser.add_argument('--username', required=False, default=None)
    parser.add_argument('--password', required=False, default=None)
    parser.add_argument('--scheme', required=False, default='http')
    parser.add_argument('--host', required=False, default='localhost')
    parser.add_argument('--port', required=False, default='8080')
    parser.add_argument('--api-root', required=False, default='/api/v1',
                        help='path to the Girder REST API')
    parser.add_argument('--path', required=True, help='the path to import the analyses from')

    config = parser.parse_args()

    client = GirderClient(host=config.host, port=config.port,
                          apiRoot=config.api_root, scheme=config.scheme)
    client.authenticate(config.username, config.password)

    import_analyses(client, config.path)
开发者ID:justincampbell,项目名称:minerva,代码行数:18,代码来源:import_analyses.py

示例13: testClientMetadataExtractor

    def testClientMetadataExtractor(self):
        item = self.model('item').load(self.item['_id'], user=self.user)
        self.assertEqual(item['name'], self.name)
        self.assertNotHasKeys(item, ['meta'])
        clientPath = os.path.join(ROOT_DIR, 'clients', 'python')
        sys.path.insert(0, clientPath)

        from girder_client import GirderClient

        client = GirderClient('localhost', int(os.environ['GIRDER_PORT']))
        client.authenticate(self.user['login'], self.password)
        extractor = ClientMetadataExtractor(client, self.path, self.item['_id'])
        extractor.extractMetadata()
        sys.path.remove(clientPath)
        item = self.model('item').load(self.item['_id'], user=self.user)
        self.assertEqual(item['name'], self.name)
        self.assertHasKeys(item, ['meta'])
        self.assertEqual(item['meta']['MIME type'], self.mimeType)
开发者ID:jbeezley,项目名称:girder,代码行数:18,代码来源:client_metadata_extractor_test.py

示例14: setUp

    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']
开发者ID:Kitware,项目名称:cumulus,代码行数:11,代码来源:base_integration_test.py

示例15: __init__

 def __init__(self, username, password, dryrun, blacklist, host="localhost", port=8080, apiRoot=None, scheme="http"):
     """initialization function to create a GirderCli instance, will attempt
     to authenticate with the designated Girder instance.
     :param username: username to authenticate to Girder instance.
     :param password: password to authenticate to Girder instance, leave
         this blank to be prompted.
     :param dryrun: boolean indicating whether to run the command or just
         perform a dryrun showing which files and folders will be uploaded.
     :param blacklist: list of filenames which will be ignored by upload.
     :param host: host used to connect to Girder instance,
         defaults to 'localhost'
     :param port: port used to connect to Girder instance,
         defaults to 8080
     :param apiRoot: The path on the server corresponding to the root of the
         Girder REST API. If None is passed, assumes '/api/v1'.
     :param scheme: scheme used to connect to Girder instance,
         defaults to 'http'; if passing 'https' port should likely be 443.
     """
     GirderClient.__init__(
         self, host=host, port=port, apiRoot=apiRoot, scheme=scheme, dryrun=dryrun, blacklist=blacklist
     )
     interactive = password is None
     self.authenticate(username, password, interactive=interactive)
开发者ID:manthey,项目名称:girder,代码行数:23,代码来源:cli.py


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