Пример #1
0
    def _modify_params(self, **kw):
        if kw['reply']:
            raise NotImplementedError()
            # get comment kw['reply']
            #kw['comment-body'] = block_edit('Enter comment:').rstrip()

        if kw['comment_from']:
            try:
                if kw['comment_from'] == '-':
                    kw['comment-body'] = sys.stdin.read()
                else:
                    kw['comment-body'] = open(kw['comment_from'], 'r').read()
            except IOError as e:
                raise CliError('Unable to read file: {}: {}'.format(kw['comment_from'], e))

        if kw['comment_editor']:
            kw['comment-body'] = block_edit('Enter comment:').rstrip()

        return kw
Пример #2
0
    def _create_params(self, batch, **kw):
        # load description from file or stdin
        if kw['description_from']:
            try:
                if kw['description_from'] == '-':
                    kw['description'] = sys.stdin.read()
                else:
                    kw['description'] = open(kw['description_from'], 'r').read()
            except IOError as e:
                raise CliError('Unable to read file: {}: {}'.format(kw['description_from'], e))

        if not batch:
            self.log('Press Ctrl+C at any time to abort.')

            if not kw['product']:
                while not kw['product'] or len(kw['product']) < 1:
                    kw['product'] = get_input('Enter product: ')
            else:
                self.log('Enter product: {}'.format(kw['product']))

            if not kw['component']:
                while not kw['component'] or len(kw['component']) < 1:
                    kw['component'] = get_input('Enter component: ')
            else:
                self.log('Enter component: {}'.format(kw['component']))

            if not kw['version']:
                # Try to get the default version for the entered product by
                # naively assuming it has the highest ID
                params = {'names': [kw['product']], 'include_fields': ['versions']}
                r = self.service.query('Product.get', params)
                if r['products']:
                    default_version = r['products'][0]['versions'][-1]['name']
                else:
                    raise CliError('Product "{}" not found'.format(kw['product']))

                line = get_input('Enter version (default: {}): '.format(default_version))
                if len(line):
                    kw['version'] = line
                else:
                    kw['version'] = default_version
            else:
                self.log('Enter version: {}'.format(kw['version']))

            if not kw['summary']:
                while not kw['summary'] or len(kw['summary']) < 1:
                    kw['summary'] = get_input('Enter title: ')
            else:
                self.log('Enter title: {}'.format(kw['summary']))

            if not kw['description']:
                line = block_edit('Enter bug description: ')
                if len(line):
                    kw['description'] = line
            else:
                self.log('Enter bug description: {}'.format(kw['description']))

            if not kw['op_sys']:
                op_sys_msg = 'Enter operating system where this bug occurs: '
                line = get_input(op_sys_msg)
                if len(line):
                    kw['op_sys'] = line
            else:
                self.log('Enter operating system: {}'.format(kw['op_sys']))

            if not kw['platform']:
                platform_msg = 'Enter hardware platform where this bug occurs: '
                line = get_input(platform_msg)
                if len(line):
                    kw['platform'] = line
            else:
                self.log('Enter hardware platform: {}'.format(kw['platform']))

            if kw['priority'] is None:
                priority_msg = 'Enter priority (e.g. normal) (optional): '
                line = get_input(priority_msg)
                if len(line):
                    kw['priority'] = line
            else:
                self.log('Enter priority (optional): {}'.format(kw['priority']))

            if kw['severity'] is None:
                severity_msg = 'Enter severity (e.g. normal) (optional): '
                line = get_input(severity_msg)
                if len(line):
                    kw['severity'] = line
            else:
                self.log('Enter severity (optional): {}'.format(kw['severity']))

            if kw['target_milestone'] is None:
                milestone_msg = 'Enter target milestone (optional): '
                line = get_input(milestone_msg)
                if len(line):
                    kw['target_milestone'] = line
            else:
                self.log('Enter target milestone (optional): {}'.format(kw['target_milestone']))

            if kw['alias'] is None:
                alias_msg = 'Enter alias (optional): '
                line = get_input(alias_msg)
                if len(line):
                    kw['alias'] = line
            else:
                self.log('Enter alias (optional): {}'.format(kw['alias']))

            if kw['assigned_to'] is None:
                assign_msg = 'Enter assignee (e.g. [email protected]) (optional): '
                line = get_input(assign_msg)
                if len(line):
                    kw['assigned_to'] = line
            else:
                self.log('Enter assignee (optional): {}'.format(kw['assigned_to']))

            if kw['status'] is None:
                status_msg = 'Enter status (optional): '
                line = get_input(status_msg)
                if len(line):
                    kw['status'] = line
            else:
                self.log('Enter status (optional): {}'.format(kw['status']))

            if kw['cc'] is None:
                cc_msg = 'Enter CCs (comma separated) (optional): '
                line = get_input(cc_msg)
                if len(line):
                    kw['cc'] = line.split(',')
            else:
                self.log('Enter CCs (optional): {}'.format(', '.join(kw['cc'])))

            # the API doesn't support setting keywords while creating a bug
            #if kw['keywords'] is None:
            #    keywords_msg = 'Enter keywords (comma separated) (optional): '
            #    line = get_input(keywords_msg)
            #    if len(line):
            #        kw['keywords'] = line.split(',')
            #else:
            #    self.log('Enter keywords (optional): {}'.format(', '.join(kw['keywords'])))

            if kw['groups'] is None:
                groups_msg = 'Enter groups (comma separated) (optional): '
                line = get_input(groups_msg)
                if len(line):
                    kw['groups'] = line.split(',')
            else:
                self.log('Enter groups (optional): {}'.format(', '.join(kw['groups'])))

            if kw['append_command'] is None:
                kw['append_command'] = get_input('Append the output of the following command (leave blank for none): ')
            else:
                self.log('Append command (optional): {}'.format(kw['append_command']))

        # append the output from append_command to the description
        if kw['append_command'] is not None and kw['append_command'] != '':
            append_command_output = subprocess.check_output(kw['append_command'])
            kw['description'] = kw['description'] + '\n\n' + '$ ' + kw['append_command'] + '\n' + append_command_output

        options_log = []
        options_log.append('=' * self.columns)
        options_log.append('{:<12}: {}'.format('Product', kw['product']))
        options_log.append('{:<12}: {}'.format('Component', kw['component']))
        options_log.append('{:<12}: {}'.format('Version', kw['version']))
        options_log.append('{:<12}: {}'.format('Title', kw['summary']))
        options_log.append('{:<12}: {}'.format('OS', kw['op_sys']))
        options_log.append('{:<12}: {}'.format('Platform', kw['platform']))
        options_log.append('{:<12}: {}'.format('Priority', kw['priority']))
        options_log.append('{:<12}: {}'.format('Severity', kw['severity']))
        if kw['target_milestone'] is not None:
            options_log.append('{:<12}: {}'.format('Milestone', kw['target_milestone']))
        if kw['alias'] is not None:
            options_log.append('{:<12}: {}'.format('Alias', kw['alias']))
        if kw['assigned_to'] is not None:
            options_log.append('{:<12}: {}'.format('Assigned to', self.service._desuffix(kw['assigned_to'])))
            # add potentially missing domain suffix
            kw['assigned_to'] = self.service._resuffix(kw['assigned_to'])
        if kw['status'] is not None:
            options_log.append('{:<12}: {}'.format('Status', kw['status']))
        if kw['cc'] is not None:
            options_log.append('{:<12}: {}'.format('CC', ', '.join(map(self.service._desuffix, kw['cc']))))
            # add potentially missing domain suffixes
            kw['cc'] = list(map(self.service._resuffix, kw['cc']))
        #if kw['keywords'] is not None:
        #    options_log.append('{:<12}: {}'.format('Keywords', ', '.join(kw['keywords'])))
        if kw['groups'] is not None:
            options_log.append('{:<12}: {}'.format('Groups', ', '.join(kw['groups'])))
        options_log.append(self._header('-', 'Description'))
        if kw['description'] is not None:
            # interpret backslash escapes
            kw['description'] = kw['description'].decode('string_escape')
            options_log.append('{}'.format(kw['description']))
        options_log.append('=' * self.columns)

        return (options_log, kw)
Пример #3
0
 def _attach_params(self, **kw):
     if kw['comment'] is None:
         kw['comment'] = block_edit('Enter optional long description of attachment')
     return kw