Пример #1
0
    def received_message(self, message):
        message = json.loads(str(message))

        if self.print_job_info and 'job' in message and message['job'] not in self.seen_jobs:
            self.seen_jobs[message['job']] = dxpy.describe(message['job'])
            print get_find_jobs_string(self.seen_jobs[message['job']], has_children=False, show_outputs=False)

        if message.get('source') == 'SYSTEM' and message.get('msg') == 'END_LOG':
            self.close()
        elif self.msg_callback:
            self.msg_callback(message)
        else:
            print self.msg_output_format.format(**message)
Пример #2
0
    def closed(self, code, reason):
        self.closed_code, self.closed_reason = code, reason

        if self.closed_code != 1000:
            try:
                error = json.loads(self.closed_reason)
                raise DXJobLogStreamingException("Error while streaming job logs: {type}: {message}\n".format(**error))
            except (KeyError, ValueError):
                error = "Error while streaming job logs: {code} {reason}\n".format(code=self.closed_code,
                                                                                   reason=self.closed_reason)
                raise DXJobLogStreamingException(error)
        elif self.print_job_info:
            for job_id in self.seen_jobs:
                print get_find_jobs_string(dxpy.describe(job_id), has_children=False)
Пример #3
0
def interactive_help(in_class, param_desc, prompt):
    is_array = param_desc['class'].startswith("array:")
    print_param_help(param_desc)
    print
    array_help_str = ', or <ENTER> to finish the list of inputs'
    if in_class in dx_data_classes:
        # Class is some sort of data object
        if dxpy.WORKSPACE_ID is not None:
            proj_name = None
            try:
                proj_name = dxpy.DXHTTPRequest('/' + dxpy.WORKSPACE_ID + '/describe', {})['name']
            except:
                pass
            if proj_name is not None:
                print 'Your current working directory is ' + proj_name + ':' + os.environ.get('DX_CLI_WD', '/')
        while True:
            print 'Pick an option to find input data:'
            try:
                opt_num = pick(['List and choose from available data in the current project',
                                'List and choose from available data in the DNAnexus Reference Genomes project',
                                'Select another project to list and choose available data',
                                'Select an output from a previously-run job (current project only)',
                                'Return to original prompt (specify an ID or path directly)'])
            except KeyboardInterrupt:
                opt_num = 4
            if opt_num == 0:
                query_project = dxpy.WORKSPACE_ID
            elif opt_num == 1:
                query_project = dxpy.find_one_project(name="Reference Genomes", public=True, level="VIEW")['id']
            elif opt_num == 2:
                project_generator = dxpy.find_projects(level='VIEW', describe=True, explicit_perms=True)
                print '\nProjects to choose from:'
                query_project = paginate_and_pick(project_generator, (lambda result: result['describe']['name']))['id']
            if opt_num in range(3):
                result_generator = dxpy.find_data_objects(classname=in_class,
                                                          typename=param_desc.get('type'),
                                                          describe=True,
                                                          project=query_project)
                print '\nAvailable data:'
                result_choice = paginate_and_pick(result_generator,
                                                  (lambda result: get_ls_l_desc(result['describe'])))
                if result_choice == 'none found':
                    print 'No compatible data found'
                    continue
                elif result_choice == 'none picked':
                    continue
                else:
                    return [result_choice['project'] + ':' + result_choice['id']]
            elif opt_num == 3:
                # Select from previous jobs in current project
                result_generator = dxpy.find_jobs(project=dxpy.WORKSPACE_ID,
                                                  describe=True,
                                                  parent_job="none")
                print
                print 'Previously-run jobs to choose from:'
                result_choice = paginate_and_pick(result_generator,
                                                  (lambda result: get_find_jobs_string(result['describe'],
                                                                                       has_children=False,
                                                                                       single_result=True)),
                                                  filter_fn=(lambda result: result['describe']['state'] not in ['unresponsive', 'terminating', 'terminated', 'failed']))
                if result_choice == 'none found':
                    print 'No jobs found'
                    continue
                elif result_choice == 'none picked':
                    continue
                else:
                    if 'output' in result_choice['describe'] and result_choice['describe']['output'] != None:
                        keys = result_choice['describe']['output'].keys()
                    else:
                        exec_handler = dxpy.get_handler(result_choice.get('app', result_choice['applet']))
                        exec_desc = exec_handler.describe()
                        if 'outputSpec' not in exec_desc:
                            # This if block will either continue, return, or raise
                            print 'No output spec found for the executable'
                            try:
                                field = raw_input('Output field to use (^C or <ENTER> to cancel): ')
                                if field == '':
                                    continue
                                else:
                                    return [result_choice['id'] + ':' + field]
                            except KeyboardInterrupt:
                                continue
                        else:
                            keys = exec_desc['outputSpec'].keys()
                    if len(keys) > 1:
                        print '\nOutput fields to choose from:'
                        field_choice = pick(keys)
                        return [result_choice['id'] + ':' + keys[field_choice]]
                    elif len(keys) == 1:
                        print 'Using the only output field: ' + keys[0]
                        return [result_choice['id'] + ':' + keys[0]]
                    else:
                        print 'No available output fields'
            else:
                print fill('Enter an ID or path (<TAB> twice for compatible ' + in_class + 's in current directory)' + (array_help_str if is_array else ''))
                return shlex.split(raw_input(prompt))
    else:
        if in_class == 'boolean':
            if is_array:
                print fill('Enter "true", "false"' + array_help_str)
            else:
                print fill('Enter "true" or "false"')
        elif in_class == 'string' and is_array:
                print fill('Enter a nonempty string' + array_help_str)
        elif (in_class == 'float' or in_class == 'int') and is_array:
            print fill('Enter a number' + array_help_str)
        elif in_class == 'hash':
            print fill('Enter a quoted JSON hash')
        result = raw_input(prompt)
        if in_class == 'string':
            return [result]
        else:
            return shlex.split(result)