當前位置: 首頁>>代碼示例>>Python>>正文


Python GirderClient.sendRestRequest方法代碼示例

本文整理匯總了Python中girder_client.GirderClient.sendRestRequest方法的典型用法代碼示例。如果您正苦於以下問題:Python GirderClient.sendRestRequest方法的具體用法?Python GirderClient.sendRestRequest怎麽用?Python GirderClient.sendRestRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在girder_client.GirderClient的用法示例。


在下文中一共展示了GirderClient.sendRestRequest方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: import_calc

# 需要導入模塊: from girder_client import GirderClient [as 別名]
# 或者: from girder_client.GirderClient import sendRestRequest [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)
開發者ID:OpenChemistry,項目名稱:mongochemserver,代碼行數:60,代碼來源:bulk_import.py

示例2: GirderClient

# 需要導入模塊: from girder_client import GirderClient [as 別名]
# 或者: from girder_client.GirderClient import sendRestRequest [as 別名]
from girder_client import GirderClient

c = GirderClient(host="localhost", port=9000)

# Create an admin user if there isn't one
try:
    c.authenticate("girder", "girder")
except:
    c.sendRestRequest(
        "POST",
        "user",
        {
            "login": "girder",
            "password": "girder",
            "email": "[email protected]",
            "firstName": "Girder",
            "lastName": "Admin",
        },
    )
    c.authenticate("girder", "girder")

# Create a tangelo hub collection if there isn't one
coll_search = c.get("resource/search", parameters={"q": "Default", "types": '["collection"]'})
if len(coll_search["collection"]) == 0:
    collection = c.post(
        "collection", parameters={"name": "Default", "description": "Default workspace", "public": "true"}
    )
    c.post(
        "folder",
        parameters={
            "parentType": "collection",
開發者ID:Kitware,項目名稱:flow,代碼行數:33,代碼來源:girder-setup.py


注:本文中的girder_client.GirderClient.sendRestRequest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。