コード例 #1
0
ファイル: plugins.py プロジェクト: outlyerapp/dlcli
def import_plugin(url='',
                  org='',
                  account='',
                  key='',
                  plugin_path='',
                  timeout=60,
                  **kwargs):
    plugin_name = os.path.splitext(os.path.basename(plugin_path))[0]
    plugin_extension = os.path.splitext(os.path.basename(plugin_path))[1]
    plugin_content = utils.read_file_content(plugin_path)
    payload = {
        "name": plugin_name,
        "extension": plugin_extension.replace('.', ''),
        "content": base64.b64encode(plugin_content)
    }
    print "restoring plugin %s" % plugin_name
    resp = requests.post(utils.build_api_url(url,
                                             org,
                                             account,
                                             endpoint='plugins'),
                         headers={'Authorization': "Bearer " + key},
                         data=payload,
                         timeout=timeout)

    if resp.status_code == 422:
        resp = requests.patch(utils.build_api_url(url,
                                                  org,
                                                  account,
                                                  endpoint='plugins/%s' %
                                                  plugin_name),
                              headers={'Authorization': "Bearer " + key},
                              data=payload,
                              timeout=timeout)
    return resp
コード例 #2
0
ファイル: templates.py プロジェクト: dataloop/dlcli
def put_rule(url='', org='', account='', key='', path='', template='', timeout=60, **kwargs):
    rule_name = os.path.splitext(os.path.basename(path))[0]
    rule_content = utils.read_file_content(path)
    return post(utils.build_api_url(url, org, account,
                                    endpoint='/templates/private/%s/rules' % template),
                headers={'Authorization': "Bearer " + key, "Content-Type": "application/yaml"},
                data=rule_content, timeout=timeout)
コード例 #3
0
ファイル: templates.py プロジェクト: dataloop/dlcli
def put_dashboard(url='', org='', account='', key='', path='', template='', timeout=60, **kwargs):
    dashboard_name = os.path.splitext(os.path.basename(path))[0]
    dashboard_yaml = utils.read_file_content(path)
    return put(utils.build_api_url(url, org, account,
                                   endpoint='/templates/private/%s/dashboards/%s' % (template, dashboard_name)),
               headers={'Authorization': "Bearer " + key, "Content-Type": "application/yaml"},
               data=dashboard_yaml, timeout=timeout)
コード例 #4
0
ファイル: templates.py プロジェクト: outlyerapp/dlcli
def put_plugin(url='',
               org='',
               account='',
               key='',
               path='',
               template='',
               timeout=60,
               type='INPROCESS',
               **kwargs):
    plugin_name = os.path.splitext(os.path.basename(path))[0]
    plugin_extension = os.path.splitext(os.path.basename(path))[1]
    plugin_content = utils.read_file_content(path)
    payload = {
        "name": plugin_name,
        "extension": plugin_extension.replace('.', ''),
        "content": base64.b64encode(plugin_content),
        "type": type
    }
    resp = post(utils.build_api_url(url,
                                    org,
                                    account,
                                    endpoint='/templates/private/%s/plugins' %
                                    template),
                headers={'Authorization': "Bearer " + key},
                data=payload,
                timeout=timeout)
    return resp
コード例 #5
0
ファイル: dashboards.py プロジェクト: dataloop/dlcli
def import_dashboard(url='', org='', account='', key='', file_path='', timeout=60, **kwargs):
    dashboard_name = os.path.splitext(os.path.basename(file_path))[0]
    dashboard_yaml = utils.read_file_content(file_path)
    print "restoring dashboard %s" % dashboard_name
    return put(utils.build_api_url(url, org, account,
                                   endpoint='dashboards/%s' % dashboard_name),
               headers={'Authorization': "Bearer " + key, "Content-Type": "application/yaml",
                        "Accept-Encoding": "identity"},
               data=dashboard_yaml, timeout=timeout)
コード例 #6
0
ファイル: templates.py プロジェクト: 2dotstwice/dlcli
def put_manifest(url='', org='', account='', key='', name='', path='', **kwargs):
    content = yaml.safe_load(utils.read_file_content(os.path.join(path, 'package.yaml')))
    return requests.put(
        utils.build_api_url(url,
                            org,
                            account,
                            endpoint='templates/private/%s' % name),
        headers={'Authorization': "Bearer " + key, "Content-Type": "application/json"},
        data=json.dumps(content))
コード例 #7
0
ファイル: dashboards.py プロジェクト: 2dotstwice/dlcli
def import_dashboard(url='', org='', account='', key='', file_path='', **kwargs):
    dashboard_name = os.path.splitext(os.path.basename(file_path))[0]
    dashboard_yaml = utils.read_file_content(file_path)
    return requests.put(
        utils.build_api_url(url,
                            org,
                            account,
                            endpoint='dashboards') + '/' + dashboard_name,
        headers={'Authorization': "Bearer " + key, "Content-Type": "application/yaml"},
        data=dashboard_yaml)
コード例 #8
0
def import_rule(url='', org='', account='', key='', rule_path='', timeout=60, **kwargs):
    rule_name = os.path.splitext(os.path.basename(rule_path))[0]
    rule_content = utils.read_file_content(rule_path)
    click.echo("restoring rule %s" % rule_name)
    post(utils.build_api_url(url, org, account,
                             endpoint='rules'),
         headers={'Authorization': "Bearer " + key},
         data={"name": rule_name}, timeout=timeout)
    return requests.put(
        utils.build_api_url(url, org, account,
                            endpoint='rules/%s' % rule_name),
        headers={'Authorization': "Bearer " + key, "Content-Type": "application/yaml"},
        data=rule_content, timeout=timeout)
コード例 #9
0
def map_audio_transcripts():

    audio_transcripts_map = dict()

    transcript_file_paths = get_files(GENERATED_DATA_TRANSCRIPTS_PATH)
    for i, transcript_file in enumerate(transcript_file_paths):
        transcriptions = read_file_content(transcript_file)
        for j, transcript in enumerate(transcriptions):
            transcript = transcript.rstrip()
            audio_file_path = GENERATED_DATA_WAV_PATH + "audio" + str(
                i) + "/track" + str(j) + ".wav"
            audio_transcripts_map[audio_file_path] = transcript

    return audio_transcripts_map
コード例 #10
0
ファイル: templates.py プロジェクト: dataloop/dlcli
def put_plugin(url='', org='', account='', key='', path='', template='', timeout=60, type='INPROCESS', **kwargs):
    plugin_name = os.path.splitext(os.path.basename(path))[0]
    plugin_extension = os.path.splitext(os.path.basename(path))[1]
    plugin_content = utils.read_file_content(path)
    payload = {
        "name": plugin_name,
        "extension": plugin_extension.replace('.', ''),
        "content": base64.b64encode(plugin_content),
        "type": type
    }
    resp = post(utils.build_api_url(url, org, account,
                                    endpoint='/templates/private/%s/plugins' % template),
                headers={'Authorization': "Bearer " + key},
                data=payload, timeout=timeout)
    return resp
コード例 #11
0
ファイル: rules.py プロジェクト: 2dotstwice/dlcli
def import_rule(url='', org='', account='', key='', rule_path='', **kwargs):
    rule_name = os.path.splitext(os.path.basename(rule_path))[0]
    rule_content = utils.read_file_content(rule_path)
    requests.post(
        utils.build_api_url(url,
                            org,
                            account,
                            endpoint='rules'),
        headers={'Authorization': "Bearer " + key},
        data={"name": rule_name})
    requests.put(
        utils.build_api_url(url,
                            org,
                            account,
                            endpoint='rules' + '/' + rule_name),
        headers={'Authorization': "Bearer " + key, "Content-Type": "application/yaml"},
        data=rule_content)
コード例 #12
0
def map_audio_transcripts_xml():
    """
    Maps an audio folder to its transcription file
    :return: Dict
    """
    audio_transcripts_map = dict()

    transcript_file_paths = get_files_full_path(
        settings.GENERATED_DATA_TRANSCRIPTS_PATH)
    for i, transcript_file in enumerate(transcript_file_paths):
        transcriptions = read_file_content(transcript_file)
        for j, transcript in enumerate(transcriptions):
            transcript = transcript.rstrip()
            audio_file_path = settings.GENERATED_DATA_WAV_PATH + "audio" + str(
                i) + "/track" + str(j) + ".wav"
            audio_transcripts_map[audio_file_path] = transcript

    return audio_transcripts_map
コード例 #13
0
def map_audio_transcripts_generic():
    """
    Maps an audio folder to its transcription file
    :return: Dict
    """
    audio_transcripts_map = dict()

    transcript_file_paths = get_files_full_path(
        settings.TRANSCRIPTIONS_DATA_PATH)
    audio_file_paths = get_files_full_path(settings.AUDIO_DATA_PATH)

    for i, transcript_file in enumerate(transcript_file_paths):
        transcriptions = read_file_content(transcript_file)
        for j, transcript in enumerate(transcriptions):
            transcript = transcript.rstrip()
            audio_file_path = audio_file_paths[j]
            audio_transcripts_map[audio_file_path] = transcript

    return audio_transcripts_map
コード例 #14
0
ファイル: templates.py プロジェクト: outlyerapp/dlcli
def put_manifest(url='',
                 org='',
                 account='',
                 key='',
                 name='',
                 path='',
                 timeout=60,
                 **kwargs):
    content = yaml.safe_load(
        utils.read_file_content(os.path.join(path, 'package.yaml')))
    return put(utils.build_api_url(url,
                                   org,
                                   account,
                                   endpoint='templates/private/%s' % name),
               headers={
                   'Authorization': "Bearer " + key,
                   "Content-Type": "application/json"
               },
               data=json.dumps(content),
               timeout=timeout)
コード例 #15
0
ファイル: dashboards.py プロジェクト: outlyerapp/dlcli
def import_dashboard(url='',
                     org='',
                     account='',
                     key='',
                     file_path='',
                     timeout=60,
                     **kwargs):
    dashboard_name = os.path.splitext(os.path.basename(file_path))[0]
    dashboard_yaml = utils.read_file_content(file_path)
    print "restoring dashboard %s" % dashboard_name
    return put(utils.build_api_url(url,
                                   org,
                                   account,
                                   endpoint='dashboards/%s' % dashboard_name),
               headers={
                   'Authorization': "Bearer " + key,
                   "Content-Type": "application/yaml",
                   "Accept-Encoding": "identity"
               },
               data=dashboard_yaml,
               timeout=timeout)
コード例 #16
0
ファイル: templates.py プロジェクト: outlyerapp/dlcli
def put_rule(url='',
             org='',
             account='',
             key='',
             path='',
             template='',
             timeout=60,
             **kwargs):
    rule_name = os.path.splitext(os.path.basename(path))[0]
    rule_content = utils.read_file_content(path)
    return post(utils.build_api_url(url,
                                    org,
                                    account,
                                    endpoint='/templates/private/%s/rules' %
                                    template),
                headers={
                    'Authorization': "Bearer " + key,
                    "Content-Type": "application/yaml"
                },
                data=rule_content,
                timeout=timeout)
コード例 #17
0
ファイル: plugins.py プロジェクト: dataloop/dlcli
def import_plugin(url='', org='', account='', key='', plugin_path='', timeout=60, **kwargs):
    plugin_name = os.path.splitext(os.path.basename(plugin_path))[0]
    plugin_extension = os.path.splitext(os.path.basename(plugin_path))[1]
    plugin_content = utils.read_file_content(plugin_path)
    payload = {
        "name": plugin_name,
        "extension": plugin_extension.replace('.', ''),
        "content": base64.b64encode(plugin_content)
    }
    print "restoring plugin %s" % plugin_name
    resp = requests.post(utils.build_api_url(url, org, account,
                                             endpoint='plugins'),
                         headers={'Authorization': "Bearer " + key},
                         data=payload, timeout=timeout)

    if resp.status_code == 422:
        resp = requests.patch(utils.build_api_url(url, org, account,
                                                  endpoint='plugins/%s' % plugin_name),
                              headers={'Authorization': "Bearer " + key},
                              data=payload, timeout=timeout)
    return resp
コード例 #18
0
ファイル: templates.py プロジェクト: outlyerapp/dlcli
def put_dashboard(url='',
                  org='',
                  account='',
                  key='',
                  path='',
                  template='',
                  timeout=60,
                  **kwargs):
    dashboard_name = os.path.splitext(os.path.basename(path))[0]
    dashboard_yaml = utils.read_file_content(path)
    return put(
        utils.build_api_url(url,
                            org,
                            account,
                            endpoint='/templates/private/%s/dashboards/%s' %
                            (template, dashboard_name)),
        headers={
            'Authorization': "Bearer " + key,
            "Content-Type": "application/yaml"
        },
        data=dashboard_yaml,
        timeout=timeout)
コード例 #19
0
ファイル: rpc.py プロジェクト: 2dotstwice/dlcli
def run_local(url='', org='', account='', key='', plugin_path='', agent_list='', **kwargs):
    plugin_name = os.path.splitext(os.path.basename(plugin_path))
    plugin_content = utils.read_file_content(plugin_path)
    requests = (grequests.post(
        utils.build_api_url(url,
                            org,
                            account,
                            endpoint='rpc' + '/run'),
        data={
            'name': plugin_name,
            'agent': agent_id,
            'content': base64.b64encode(plugin_content),
            'encoding': 'base64',
            'shell': '',
            'params': '',
            'type': 'INPROCESS'
        },
        callback=set_meta(agent_id),
        headers={'Authorization': "Bearer " + key}) for agent_id in agent_list)
    data = []
    for resp in grequests.imap(requests, size=10):
        data.append([resp.meta, resp.json()])
    return data
コード例 #20
0
ファイル: links.py プロジェクト: dataloop/dlcli
def import_link(url='', org='', account='', key='', link_path='', timeout=60, **kwargs):
    link_json = json.loads(utils.read_file_content(link_path))
    return post(utils.build_api_url(url, org, account,
                                    endpoint='links'),
                headers={'Authorization': "Bearer " + key},
                data=link_json, timeout=timeout)