示例#1
0
    def _parse_sections(self, case):
        '''
        Find available sections, format, and put in dictionary.
        '''
        try:
            # Info (all cases should have this):
            doc = u''
            doc += '\n%s%s%s\n' % (Constants.BOLD,
                                   Constants.CASE_DETAILS,
                                   Constants.END)
            doc += '%s%s%s\n' % (Constants.BOLD,
                                 str(self.ruler * Constants.MAX_RULE),
                                 Constants.END)
            doc += '%-20s  %-40s\n' % (Constants.CASE_NUMBER,
                                       case.get_caseNumber())
            doc += '%-20s  %-40s\n' % (Constants.CASE_TYPE,
                                       case.get_type())
            doc += '%-20s  %-40s\n' % (Constants.CASE_SEVERITY,
                                       case.get_severity())
            doc += '%-20s  %-40s\n' % (Constants.CASE_STATUS,
                                       case.get_status())
            doc += '%-20s  %-40s\n\n' % (Constants.CASE_AID,
                                         case.get_alternateId())
            doc += '%-20s  %-40s\n' % (Constants.CASE_PROD,
                                       case.get_product())
            doc += '%-20s  %-40s\n' % (Constants.CASE_VER,
                                       case.get_version())

            if case.get_entitlement() is None:
                doc += '%-20s  %-40s\n' % (Constants.CASE_SLA, ' ')
            else:
                doc += '%-20s  %-40s\n' % (Constants.CASE_SLA,
                                        case.get_entitlement().get_sla())
            doc += '%-20s  %-40s\n' % (Constants.CASE_OWNER,
                                       case.get_contactName())
            doc += '%-20s  %-40s\n\n' % (Constants.CASE_RHOWN,
                                         case.get_owner())
            if case.group:
                doc += '%-20s  %-40s\n' % (Constants.CASE_GRP,
                                           case.group.get_name())
            else:
                doc += '%-20s  %-40s\n' % (Constants.CASE_GRP, 'None')
            doc += '%-20s  %-40s\n' % (Constants.CASE_OPENED,
                            common.iso8601tolocal(case.get_createdDate()))
            doc += '%-20s  %-40s\n' % (Constants.CASE_OPENEDBY,
                                       case.get_createdBy())
            doc += '%-20s  %-40s\n' % (Constants.CASE_UPDATED,
                        common.iso8601tolocal(case.get_lastModifiedDate()))
            doc += '%-20s  %-40s\n\n' % (Constants.CASE_UPDATEDBY,
                            case.get_lastModifiedBy())
            doc += '%-20s  %-40s\n\n' % (Constants.CASE_SUMMARY,
                                         case.get_summary())
            disp_opt = DisplayOption(Constants.CASE_DETAILS,
                                         'interactive_action')
            self._submenu_opts.append(disp_opt)
            self._sections[disp_opt] = doc

            if common.is_interactive():
                disp_opt = DisplayOption(Constants.CASE_MODIFY,
                                         'interactive_action')
                self._submenu_opts.append(disp_opt)

            # Description
            des = case.get_description()
            if des is not None:
                doc = u''
                doc += '\n%s%s%s\n' % (Constants.BOLD,
                                       Constants.CASE_DESCRIPTION,
                                       Constants.END)
                doc += '%s%s%s\n' % (Constants.BOLD,
                                     str(self.ruler * Constants.MAX_RULE),
                                     Constants.END)
                doc += '%s\n' % des
                disp_opt = DisplayOption(Constants.CASE_DESCRIPTION,
                                         'interactive_action')
                self._submenu_opts.append(disp_opt)
                self._sections[disp_opt] = doc

            # Comments
            commentAry = case.get_comments()
            num_comments = len(commentAry)
            if commentAry is not None and num_comments > 0:
                doc = u''
                doc += '\n%s%s%s\n' % (Constants.BOLD,
                                       Constants.CASE_DISCUSSION,
                                       Constants.END)
                doc += '%s%s%s\n' % (Constants.BOLD,
                                     str(self.ruler * Constants.MAX_RULE),
                                     Constants.END)
                for i, cmt in enumerate(commentAry):
                    cmt_type = 'private'
                    if cmt.get_public():
                        cmt_type = 'public'
                    doc += '%-20s  #%s %s(%s)%s\n' % \
                           (Constants.COMMENT, num_comments-i,
                            Constants.BOLD if cmt_type == 'private' else
                            Constants.END, cmt_type, Constants.END)
                    doc += '%-20s  %-40s\n' % (Constants.CASE_CMT_AUTHOR,
                                               cmt.get_lastModifiedBy())
                    doc += '%-20s  %-40s\n\n' % (Constants.CASE_CMT_DATE,
                            common.iso8601tolocal(cmt.get_lastModifiedDate()))
                    doc += cmt.get_text()
                    doc += '\n\n%s%s%s\n\n' % (Constants.BOLD,
                                               str('-' * Constants.MAX_RULE),
                                               Constants.END)
                disp_opt = DisplayOption(Constants.CASE_DISCUSSION,
                                         'interactive_action')
                self._submenu_opts.append(disp_opt)
                self._sections[disp_opt] = doc

            recommendAry = case.get_recommendations()
            if recommendAry is not None and len(recommendAry) > 0:
                doc = u''
                doc += '\n%s%s%s\n' % (Constants.BOLD,
                                       Constants.CASE_RECOMMENDATIONS,
                                       Constants.END)
                doc += '%s%s%s\n' % (Constants.BOLD,
                                     str(self.ruler * Constants.MAX_RULE),
                                     Constants.END)

                # For de-duplication this is now in a helper module,
                # generate_metadata will return the formatted doc for non-
                # interactive prompts, plus the prompt for interactive users.
                disp_opt, recdoc = recommendationprompter.generate_metadata(
                                                                recommendAry)
                doc += recdoc

                self._submenu_opts.append(disp_opt)
                self._sections[disp_opt] = doc

            # Get Attachments

            disp_opt = DisplayOption(Constants.CASE_GET_ATTACH,
                                         'interactive_action')
            self._submenu_opts.append(disp_opt)
            self._sections[disp_opt] = Constants.CASE_GET_ATTACH

            # Add Attachment
            disp_opt = DisplayOption(Constants.CASE_ADD_ATTACH,
                                         'interactive_action')
            self._submenu_opts.append(disp_opt)
            self._sections[disp_opt] = Constants.CASE_ADD_ATTACH

            # Comment
            disp_opt = DisplayOption(Constants.CASE_ADD_COMMENT,
                                         'interactive_action')
            self._submenu_opts.append(disp_opt)
            self._sections[disp_opt] = Constants.CASE_ADD_COMMENT
        except Exception:
            msg = _('ERROR: problem parsing the cases.')
            print msg
            logger.log(logging.WARNING, msg)
            return False
        return True
    def non_interactive_action(self):
        api = None
        try:
            api = apihelper.get_api()

            case = api.im.makeCase()
            case.summary = self._options['summary']
            case.product = self._options['product']
            case.version = self._options['version']
            case.description = self._options['description']
            case.severity = self._options['severity']
            if self._options['casegroup']:
                case.folderNumber = self._options['casegroupnumber']

            if common.is_interactive():
                line = raw_input(
                    _('Would see if there is a solution to this '
                      'problem before opening a support case? (y/N) '))
                line = str(line).strip().lower()
                if line == 'y':
                    recommendations = api.problems.diagnoseCase(case)
                    recprompt, recdoc = \
                        recommendationprompter.generate_metadata(
                                                            recommendations)
                    lh = LaunchHelper(GenericPrompt)
                    lh.run('', recprompt, prompt=_(\
                           'Selection (q returns to case creation menu): '))
                    line = raw_input(\
                                _('Would you still like to open the support'
                                  ' case? (Y/n) '))
                    if line.lower() == 'n':
                        print _('Thank you for using Red Hat Access')
                        return

            cs = api.cases.add(case)
            if cs.get_caseNumber() is None:
                msg = _("ERROR: There was a problem creating your case.")
                print msg
                raise Exception(msg)
            self._caseNumber = cs.get_caseNumber()
            print '%s%s%s' % (Constants.BOLD, str(
                '-' * Constants.MAX_RULE), Constants.END)
            msg = _("Support case %s has successfully been opened.\n") % \
                self._caseNumber
            print msg
            logger.log(logging.INFO, msg)

            # Attach a file
            if self._options['attachment']:
                lh = LaunchHelper(AddAttachment)
                lh.run('-c %s -d \'[RHST] File %s \' %s' %
                       (self._caseNumber,
                        os.path.basename(self._options['attachment']),
                        self._options['attachment']))
            elif (os.geteuid() == 0):
                sys.stdout.write(
                    _('Would you like Red Hat Support Tool to automatically generate and\n'
                      'attach a SoS report to %s now? (y/N) ') %
                    (self._caseNumber))
                line = raw_input()

                line = str(line).strip()
                if line == 'y':
                    # retval = os.system('sosreport')
                    p = sub.Popen(['sosreport', '--batch'],
                                  stdout=sub.PIPE,
                                  stderr=sub.STDOUT)
                    output = p.communicate()[0].split('\n')
                    for out in output:
                        if '.tar.' in out:
                            path = str(out).strip()
                            lh = LaunchHelper(AddAttachment)
                            lh.run('-c %s %s' % (self._caseNumber, path))
                            break
            else:
                print _(
                'Please attach a SoS report to support case %s. Create a SoS report as\n'
                'the root user and execute the following command to attach the SoS report\n'
                'directly to the case:\n'
                ' redhat-support-tool addattachment -c %s <path to sosreport>\n') % \
    (self._caseNumber, self._caseNumber)

            if not self._options['attachment']:
                line = raw_input(
                    _('Would you like to attach a file to %s '
                      'at this time? (y/N) ') % self._caseNumber)
                line = str(line).strip()
                if line == 'y':
                    lh = LaunchHelper(AddAttachment)
                    lh.run('-c %s' % (self._caseNumber))
示例#3
0
    def non_interactive_action(self):
        api = None
        try:
            api = apihelper.get_api()

            case = api.im.makeCase()
            case.summary = self._options['summary']
            case.product = self._options['product']
            case.version = self._options['version']
            case.description = self._options['description']
            case.severity = self._options['severity']
            if self._options['casegroup']:
                case.folderNumber = self._options['casegroupnumber']

            if common.is_interactive():
                line = raw_input(_('Would see if there is a solution to this '
                            'problem before opening a support case? (y/N) '))
                line = str(line).strip().lower()
                if line == 'y':
                    recommendations = api.problems.diagnoseCase(case)
                    recprompt, recdoc = \
                        recommendationprompter.generate_metadata(
                                                            recommendations)
                    lh = LaunchHelper(GenericPrompt)
                    lh.run('', recprompt, prompt=_(\
                           'Selection (q returns to case creation menu): '))
                    line = raw_input(\
                                _('Would you still like to open the support'
                                  ' case? (Y/n) '))
                    if line.lower() == 'n':
                        print _('Thank you for using Red Hat Access')
                        return

            cs = api.cases.add(case)
            if cs.get_caseNumber() is None:
                msg = _("ERROR: There was a problem creating your case.")
                print msg
                raise Exception(msg)
            self._caseNumber = cs.get_caseNumber()
            print '%s%s%s' % (Constants.BOLD,
                                      str('-' * Constants.MAX_RULE),
                                      Constants.END)
            msg = _("Support case %s has successfully been opened.\n") % \
                self._caseNumber
            print msg
            logger.log(logging.INFO, msg)

            # Attach a file
            if self._options['attachment']:
                lh = LaunchHelper(AddAttachment)
                lh.run('-c %s -d \'[RHST] File %s \' %s' % (
                                self._caseNumber,
                                os.path.basename(self._options['attachment']),
                                self._options['attachment']))
            elif (os.geteuid() == 0):
                sys.stdout.write(_(
    'Would you like Red Hat Support Tool to automatically generate and\n'
    'attach a SoS report to %s now? (y/N) ') % (self._caseNumber))
                line = raw_input()

                line = str(line).strip()
                if line == 'y':
                    # retval = os.system('sosreport')
                    p = sub.Popen(['sosreport', '--batch'],
                                  stdout=sub.PIPE, stderr=sub.STDOUT)
                    output = p.communicate()[0].split('\n')
                    for out in output:
                        if '.tar.' in out:
                            path = str(out).strip()
                            lh = LaunchHelper(AddAttachment)
                            lh.run('-c %s %s' % (self._caseNumber, path))
                            break
            else:
                print _(
   'Please attach a SoS report to support case %s. Create a SoS report as\n'
   'the root user and execute the following command to attach the SoS report\n'
   'directly to the case:\n'
   ' redhat-support-tool addattachment -c %s <path to sosreport>\n') % \
    (self._caseNumber, self._caseNumber)

            if not self._options['attachment']:
                line = raw_input(_('Would you like to attach a file to %s '
                                   'at this time? (y/N) ') % self._caseNumber)
                line = str(line).strip()
                if line == 'y':
                    lh = LaunchHelper(AddAttachment)
                    lh.run('-c %s' % (self._caseNumber))
        except EmptyValueError, eve:
            msg = _('ERROR: %s') % str(eve)
            print msg
            logger.log(logging.WARNING, msg)
            raise
示例#4
0
                self._sections[disp_opt] = doc

            recommendAry = case.get_recommendations()
            if recommendAry is not None and len(recommendAry) > 0:
                doc = u''
                doc += '\n%s%s%s\n' % (Constants.BOLD,
                                       Constants.CASE_RECOMMENDATIONS,
                                       Constants.END)
                doc += '%s%s%s\n' % (Constants.BOLD,
                                     str(self.ruler * Constants.MAX_RULE),
                                     Constants.END)

                # For de-duplication this is now in a helper module,
                # generate_metadata will return the formatted doc for non-
                # interactive prompts, plus the prompt for interactive users.
                disp_opt, recdoc = recommendationprompter.generate_metadata(
                    recommendAry)
                doc += recdoc

                self._submenu_opts.append(disp_opt)
                self._sections[disp_opt] = doc

            # Get Attachments

            disp_opt = DisplayOption(Constants.CASE_GET_ATTACH,
                                     'interactive_action')
            self._submenu_opts.append(disp_opt)
            self._sections[disp_opt] = Constants.CASE_GET_ATTACH

            # Add Attachment
            disp_opt = DisplayOption(Constants.CASE_ADD_ATTACH,
                                     'interactive_action')