def postinit(self):
        self._submenu_opts = deque()
        self._sections = {}

        try:
            if os.geteuid() != 0:
                raise Exception(
                    _('This command requires root user '
                      'privileges.'))
            self.yumhelper = YumDownloadHelper()
            self.yumhelper.setup_debug_repos()
            self.pkgAry = self.yumhelper.find_package(self.yumquery)
            if not self.pkgAry:
                raise EmptyValueError(
                    _('%s was not available from any of the following'
                      ' yum repositories: %s') %
                    (self.yumquery, ', '.join(self.yumhelper.get_repoids())))

            for pkg in self.pkgAry:
                if hasattr(pkg, 'evr'):
                    pkgevr = pkg.evr
                else:
                    pkgevr = "%s:%s-%s" % (pkg.epoch, pkg.version, pkg.release)
                doc = u''
                doc += '%-40s %-20s %-16s' % (pkg.name, pkgevr, pkg.repoid)
                disp_opt_doc = u'%s-%s (%s)' % (pkg.name, pkgevr, pkg.repoid)
                packed_pkg = {'yumhelper': self.yumhelper, 'package': pkg}
                disp_opt = ObjectDisplayOption(disp_opt_doc,
                                               'interactive_action',
                                               packed_pkg)
                self._submenu_opts.append(disp_opt)
                self._sections[disp_opt] = doc
        except NoReposError, nre:
            print nre
            raise
    def postinit(self):
        self._submenu_opts = deque()
        self._sections = {}

        try:
            if os.geteuid() != 0:
                raise Exception(_('This command requires root user '
                                  'privileges.'))
            self.yumhelper = YumDownloadHelper()
            self.yumhelper.setup_debug_repos()
            self.pkgAry = self.yumhelper.find_package(self.yumquery)
            if not self.pkgAry:
                raise EmptyValueError(
                        _('%s was not available from any of the following'
                          ' yum repositories: %s') % (self.yumquery,
                                    ', '.join(self.yumhelper.get_repoids())))

            for pkg in self.pkgAry:
                if hasattr(pkg, 'evr'):
                    pkgevr = pkg.evr
                else:
                    pkgevr = "%s:%s-%s" % (pkg.epoch, pkg.version, pkg.release)
                doc = u''
                doc += '%-40s %-20s %-16s' % (pkg.name, pkgevr, pkg.repoid)
                disp_opt_doc = u'%s-%s (%s)' % (pkg.name, pkgevr, pkg.repoid)
                packed_pkg = {'yumhelper': self.yumhelper,
                              'package': pkg}
                disp_opt = ObjectDisplayOption(disp_opt_doc,
                                               'interactive_action',
                                               packed_pkg)
                self._submenu_opts.append(disp_opt)
                self._sections[disp_opt] = doc
        except NoReposError, nre:
            print nre
            raise
 def postinit(self):
     try:
         if os.geteuid() != 0:
             raise Exception(
                 _('This command requires root user '
                   'privileges.'))
         if len(self.pkgAry) == 0:
             self.yumhelper = YumDownloadHelper()
             self.yumhelper.setup_debug_repos()
             self.pkgAry = self.yumhelper.find_package(self.yumquery)
             if not self.pkgAry:
                 raise EmptyValueError(
                     _('%s was not available from any of the following'
                       ' yum repositories: %s') % (self.yumquery, ', '.join(
                           self.yumhelper.get_repoids())))
     except NoReposError, nre:
         print nre
         raise
 def postinit(self):
     try:
         if os.geteuid() != 0:
             raise Exception(_("This command requires root user " "privileges."))
         if len(self.pkgAry) == 0:
             self.yumhelper = YumDownloadHelper()
             self.yumhelper.setup_debug_repos()
             self.pkgAry = self.yumhelper.find_package(self.yumquery)
             if not self.pkgAry:
                 raise EmptyValueError(
                     _("%s was not available from any of the following" " yum repositories: %s")
                     % (self.yumquery, ", ".join(self.yumhelper.get_repoids()))
                 )
     except NoReposError, nre:
         print nre
         raise
class ListKernelDebugs(InteractivePlugin):
    plugin_name = 'findkerneldebugs'
    pkgAry = None
    _submenu_opts = None
    _sections = None
    yumhelper = None
    yumquery = None

    @classmethod
    def get_usage(cls):
        '''
        The usage statement that will be printed by OptionParser.

        Example:
            - %prog -c CASENUMBER [options] <comment text here>
        Important: %prog is a OptionParser built-in.  Use it!
        '''
        return _('%prog <package name>')

    @classmethod
    def get_desc(cls):
        '''
        The description statement that will be printed by OptionParser.

        Example:
            - 'Use the \'%s\' command to add a comment to a case.'\
             % cls.plugin_name
        '''
        return _('Use the \'%s\' command to search and install available '
                 'debug images.  Wildcards are allowed.  (requires root user '
                 'privileges)') % cls.plugin_name

    @classmethod
    def get_epilog(cls):
        '''
        The epilog string that will be printed by OptionParser.  Usually
        used to print an example of how to use the program.

        Example:
         Examples:
          - %s -c 12345678 Lorem ipsum dolor sit amet, consectetur adipisicing
          - %s -c 12345678
        '''
        return _("""Examples:
  - %s 2.6.32-343.el6
  - %s 2.6.18-128.*
  - %s -t xen 2.6.18-348.el5""") \
  % (cls.plugin_name, cls.plugin_name, cls.plugin_name)

    @classmethod
    def get_options(cls):
        '''
        Subclasses that need command line options should override this method
        and return an array of optparse.Option(s) to be used by the
        OptionParser.

        Example:
         return [Option("-f", "--file", action="store",
                        dest="filename", help='Some file'),
                 Option("-c", "--case",
                        action="store", dest="casenumber",
                        help='A case')]

         Would produce the following:
         Command (? for help): help mycommand

         Usage: mycommand [options]

         Use the 'mycommand' command to find a knowledge base solution by ID
         Options:
           -h, --help  show this help message and exit
           -f, --file  Some file
           -c, --case  A case
         Example:
          - mycommand -c 12345 -f abc.txt

        '''
        return [
            Option("-t",
                   "--variant",
                   dest="variant",
                   help=_('Select an alternative kernel variant'),
                   metavar=_('VARIANT'))
        ]

    def validate_args(self):
        msg = _('ERROR: %s requires a package name.') % \
                ListKernelDebugs.plugin_name

        if not self._line:
            if common.is_interactive():
                line = raw_input(
                    _('Please provide the text to search (or'
                      ' \'q\' to exit): '))
                line = str(line).strip()
                if line == 'q':
                    raise Exception()
                if str(line).strip():
                    self._line = line
            else:
                print msg
                raise Exception(msg)

        if len(self._args) == 0 and len(self._line) > 0:
            self._args = [self._line]

        if self._options['variant']:
            self.yumquery = 'kernel-%s-debuginfo-%s' % \
                (self._options['variant'], self._args[0])
        else:
            self.yumquery = 'kernel-debuginfo-%s' % (self._args[0])

    def get_intro_text(self):
        return _('\nType the number of the kernel debug package to install or '
                 '\'e\' to return to the previous menu.')

    def get_prompt_text(self):
        return _('Select a Debug Package: ')

    def get_sub_menu_options(self):
        return self._submenu_opts

    def postinit(self):
        self._submenu_opts = deque()
        self._sections = {}

        try:
            if os.geteuid() != 0:
                raise Exception(
                    _('This command requires root user '
                      'privileges.'))
            self.yumhelper = YumDownloadHelper()
            self.yumhelper.setup_debug_repos()
            self.pkgAry = self.yumhelper.find_package(self.yumquery)
            if not self.pkgAry:
                raise EmptyValueError(
                    _('%s was not available from any of the following'
                      ' yum repositories: %s') %
                    (self.yumquery, ', '.join(self.yumhelper.get_repoids())))

            for pkg in self.pkgAry:
                if hasattr(pkg, 'evr'):
                    pkgevr = pkg.evr
                else:
                    pkgevr = "%s:%s-%s" % (pkg.epoch, pkg.version, pkg.release)
                doc = u''
                doc += '%-40s %-20s %-16s' % (pkg.name, pkgevr, pkg.repoid)
                disp_opt_doc = u'%s-%s (%s)' % (pkg.name, pkgevr, pkg.repoid)
                packed_pkg = {'yumhelper': self.yumhelper, 'package': pkg}
                disp_opt = ObjectDisplayOption(disp_opt_doc,
                                               'interactive_action',
                                               packed_pkg)
                self._submenu_opts.append(disp_opt)
                self._sections[disp_opt] = doc
        except NoReposError, nre:
            print nre
            raise
        except EmptyValueError, eve:
            print eve
            raise
class GetKernelDebugPackages(Plugin):
    plugin_name = "getkerneldebug"
    yumhelper = None
    pkgAry = []
    yumquery = None

    @classmethod
    def get_usage(cls):
        """
        The usage statement that will be printed by OptionParser.

        Example:
            - %prog -c CASENUMBER [options] <comment text here>
        Important: %prog is a OptionParser built-in.  Use it!
        """
        return _("%prog <package name>")

    @classmethod
    def get_desc(cls):
        """
        The description statement that will be printed by OptionParser.

        Example:
            - 'Use the \'%s\' command to add a comment to a case.'\
             % cls.plugin_name
        """
        return (
            _(
                "Use the '%s' command to download available debug "
                "vmlinux images.  Wildcards are allowed.  (requires root user "
                "privileges)"
            )
            % cls.plugin_name
        )

    @classmethod
    def get_epilog(cls):
        """
        The epilog string that will be printed by OptionParser.  Usually
        used to print an example of how to use the program.

        Example:
         Examples:
          - %s -c 12345678 Lorem ipsum dolor sit amet, consectetur adipisicing
          - %s -c 12345678
        """
        return (
            _(
                """Examples:
  - %s 2.6.32-343.el6
  - %s 2.6.18-128.*
  - %s -t xen 2.6.18-348.el5"""
            )
            % (cls.plugin_name, cls.plugin_name, cls.plugin_name)
        )

    @classmethod
    def get_options(cls):
        """
        Subclasses that need command line options should override this method
        and return an array of optparse.Option(s) to be used by the
        OptionParser.

        Example:
         return [Option("-f", "--file", action="store",
                        dest="filename", help='Some file'),
                 Option("-c", "--case",
                        action="store", dest="casenumber",
                        help='A case')]

         Would produce the following:
         Command (? for help): help mycommand

         Usage: mycommand [options]

         Use the 'mycommand' command to find a knowledge base solution by ID
         Options:
           -h, --help  show this help message and exit
           -f, --file  Some file
           -c, --case  A case
         Example:
          - mycommand -c 12345 -f abc.txt

        """
        return [
            Option(
                "-n",
                "--noprompt",
                dest="noprompt",
                action="store_true",
                help=_("For multi-package installs do not " "ask for confirmation."),
                default=False,
            ),
            Option(
                "-t", "--variant", dest="variant", help=_("Select an alternative kernel variant"), metavar=_("VARIANT")
            ),
        ]

    def insert_obj(self, yumdict):
        """
        Allow insertion of a package object by launchhelper (when selecting
        from the list generated by list_kerneldebugs.py)
        """
        # Expand yumdict into our YumDownloadHelper and package
        self.yumhelper = yumdict["yumhelper"]
        # Package is
        self.pkgAry = [yumdict["package"]]

    def validate_args(self):
        # Launchhelper may have inserted a package object from earlier
        if not self._args:
            if len(self.pkgAry) == 0 or self.yumhelper == None:
                msg = _("ERROR: %s requires a package name.") % GetKernelDebugPackages.plugin_name
                print msg
                raise Exception(msg)
        # Otherwise, build a search string:
        else:
            if self._options["variant"]:
                self.yumquery = "kernel-%s-debuginfo-%s" % (self._options["variant"], self._line)
            else:
                self.yumquery = "kernel-debuginfo-%s" % (self._line)

    def postinit(self):
        try:
            if os.geteuid() != 0:
                raise Exception(_("This command requires root user " "privileges."))
            if len(self.pkgAry) == 0:
                self.yumhelper = YumDownloadHelper()
                self.yumhelper.setup_debug_repos()
                self.pkgAry = self.yumhelper.find_package(self.yumquery)
                if not self.pkgAry:
                    raise EmptyValueError(
                        _("%s was not available from any of the following" " yum repositories: %s")
                        % (self.yumquery, ", ".join(self.yumhelper.get_repoids()))
                    )
        except NoReposError, nre:
            print nre
            raise
        except EmptyValueError, eve:
            print eve
            raise
class ListKernelDebugs(InteractivePlugin):
    plugin_name = 'findkerneldebugs'
    pkgAry = None
    _submenu_opts = None
    _sections = None
    yumhelper = None
    yumquery = None

    @classmethod
    def get_usage(cls):
        '''
        The usage statement that will be printed by OptionParser.

        Example:
            - %prog -c CASENUMBER [options] <comment text here>
        Important: %prog is a OptionParser built-in.  Use it!
        '''
        return _('%prog <package name>')

    @classmethod
    def get_desc(cls):
        '''
        The description statement that will be printed by OptionParser.

        Example:
            - 'Use the \'%s\' command to add a comment to a case.'\
             % cls.plugin_name
        '''
        return _('Use the \'%s\' command to search and install available '
                 'debug images.  Wildcards are allowed.  (requires root user '
                 'privileges)') % cls.plugin_name

    @classmethod
    def get_epilog(cls):
        '''
        The epilog string that will be printed by OptionParser.  Usually
        used to print an example of how to use the program.

        Example:
         Examples:
          - %s -c 12345678 Lorem ipsum dolor sit amet, consectetur adipisicing
          - %s -c 12345678
        '''
        return _("""Examples:
  - %s 2.6.32-343.el6
  - %s 2.6.18-128.*
  - %s -t xen 2.6.18-348.el5""") \
  % (cls.plugin_name, cls.plugin_name, cls.plugin_name)

    @classmethod
    def get_options(cls):
        '''
        Subclasses that need command line options should override this method
        and return an array of optparse.Option(s) to be used by the
        OptionParser.

        Example:
         return [Option("-f", "--file", action="store",
                        dest="filename", help='Some file'),
                 Option("-c", "--case",
                        action="store", dest="casenumber",
                        help='A case')]

         Would produce the following:
         Command (? for help): help mycommand

         Usage: mycommand [options]

         Use the 'mycommand' command to find a knowledge base solution by ID
         Options:
           -h, --help  show this help message and exit
           -f, --file  Some file
           -c, --case  A case
         Example:
          - mycommand -c 12345 -f abc.txt

        '''
        return [Option("-t", "--variant", dest="variant",
                       help=_('Select an alternative kernel variant'),
                       metavar=_('VARIANT'))]

    def validate_args(self):
        msg = _('ERROR: %s requires a package name.') % \
                ListKernelDebugs.plugin_name

        if not self._line:
            if common.is_interactive():
                line = raw_input(_('Please provide the text to search (or'
                                   ' \'q\' to exit): '))
                line = str(line).strip()
                if line == 'q':
                    raise Exception()
                if str(line).strip():
                    self._line = line
            else:
                print msg
                raise Exception(msg)

        if len(self._args) == 0 and len(self._line) > 0:
            self._args = [self._line]

        if self._options['variant']:
            self.yumquery = 'kernel-%s-debuginfo-%s' % \
                (self._options['variant'], self._args[0])
        else:
            self.yumquery = 'kernel-debuginfo-%s' % (self._args[0])

    def get_intro_text(self):
        return _('\nType the number of the kernel debug package to install or '
                 '\'e\' to return to the previous menu.')

    def get_prompt_text(self):
        return _('Select a Debug Package: ')

    def get_sub_menu_options(self):
        return self._submenu_opts

    def postinit(self):
        self._submenu_opts = deque()
        self._sections = {}

        try:
            if os.geteuid() != 0:
                raise Exception(_('This command requires root user '
                                  'privileges.'))
            self.yumhelper = YumDownloadHelper()
            self.yumhelper.setup_debug_repos()
            self.pkgAry = self.yumhelper.find_package(self.yumquery)
            if not self.pkgAry:
                raise EmptyValueError(
                        _('%s was not available from any of the following'
                          ' yum repositories: %s') % (self.yumquery,
                                    ', '.join(self.yumhelper.get_repoids())))

            for pkg in self.pkgAry:
                if hasattr(pkg, 'evr'):
                    pkgevr = pkg.evr
                else:
                    pkgevr = "%s:%s-%s" % (pkg.epoch, pkg.version, pkg.release)
                doc = u''
                doc += '%-40s %-20s %-16s' % (pkg.name, pkgevr, pkg.repoid)
                disp_opt_doc = u'%s-%s (%s)' % (pkg.name, pkgevr, pkg.repoid)
                packed_pkg = {'yumhelper': self.yumhelper,
                              'package': pkg}
                disp_opt = ObjectDisplayOption(disp_opt_doc,
                                               'interactive_action',
                                               packed_pkg)
                self._submenu_opts.append(disp_opt)
                self._sections[disp_opt] = doc
        except NoReposError, nre:
            print nre
            raise
        except EmptyValueError, eve:
            print eve
            raise
class GetKernelDebugPackages(Plugin):
    plugin_name = 'getkerneldebug'
    yumhelper = None
    pkgAry = []
    yumquery = None

    @classmethod
    def get_usage(cls):
        '''
        The usage statement that will be printed by OptionParser.

        Example:
            - %prog -c CASENUMBER [options] <comment text here>
        Important: %prog is a OptionParser built-in.  Use it!
        '''
        return _('%prog <package name>')

    @classmethod
    def get_desc(cls):
        '''
        The description statement that will be printed by OptionParser.

        Example:
            - 'Use the \'%s\' command to add a comment to a case.'\
             % cls.plugin_name
        '''
        return _(
            'Use the \'%s\' command to download available debug '
            'vmlinux images.  Wildcards are allowed.  (requires root user '
            'privileges)') % cls.plugin_name

    @classmethod
    def get_epilog(cls):
        '''
        The epilog string that will be printed by OptionParser.  Usually
        used to print an example of how to use the program.

        Example:
         Examples:
          - %s -c 12345678 Lorem ipsum dolor sit amet, consectetur adipisicing
          - %s -c 12345678
        '''
        return _("""Examples:
  - %s 2.6.32-343.el6
  - %s 2.6.18-128.*
  - %s -t xen 2.6.18-348.el5""") \
  % (cls.plugin_name, cls.plugin_name, cls.plugin_name)

    @classmethod
    def get_options(cls):
        '''
        Subclasses that need command line options should override this method
        and return an array of optparse.Option(s) to be used by the
        OptionParser.

        Example:
         return [Option("-f", "--file", action="store",
                        dest="filename", help='Some file'),
                 Option("-c", "--case",
                        action="store", dest="casenumber",
                        help='A case')]

         Would produce the following:
         Command (? for help): help mycommand

         Usage: mycommand [options]

         Use the 'mycommand' command to find a knowledge base solution by ID
         Options:
           -h, --help  show this help message and exit
           -f, --file  Some file
           -c, --case  A case
         Example:
          - mycommand -c 12345 -f abc.txt

        '''
        return [
            Option("-n",
                   "--noprompt",
                   dest="noprompt",
                   action="store_true",
                   help=_('For multi-package installs do not '
                          'ask for confirmation.'),
                   default=False),
            Option("-t",
                   "--variant",
                   dest="variant",
                   help=_('Select an alternative kernel variant'),
                   metavar=_('VARIANT'))
        ]

    def insert_obj(self, yumdict):
        '''
        Allow insertion of a package object by launchhelper (when selecting
        from the list generated by list_kerneldebugs.py)
        '''
        # Expand yumdict into our YumDownloadHelper and package
        self.yumhelper = yumdict['yumhelper']
        # Package is
        self.pkgAry = [yumdict['package']]

    def validate_args(self):
        # Launchhelper may have inserted a package object from earlier
        if not self._args:
            if (len(self.pkgAry) == 0 or self.yumhelper == None):
                msg = _('ERROR: %s requires a package name.') % \
                    GetKernelDebugPackages.plugin_name
                print msg
                raise Exception(msg)
        # Otherwise, build a search string:
        else:
            if self._options['variant']:
                self.yumquery = 'kernel-%s-debuginfo-%s' % \
                    (self._options['variant'], self._line)
            else:
                self.yumquery = 'kernel-debuginfo-%s' % (self._line)

    def postinit(self):
        try:
            if os.geteuid() != 0:
                raise Exception(
                    _('This command requires root user '
                      'privileges.'))
            if len(self.pkgAry) == 0:
                self.yumhelper = YumDownloadHelper()
                self.yumhelper.setup_debug_repos()
                self.pkgAry = self.yumhelper.find_package(self.yumquery)
                if not self.pkgAry:
                    raise EmptyValueError(
                        _('%s was not available from any of the following'
                          ' yum repositories: %s') % (self.yumquery, ', '.join(
                              self.yumhelper.get_repoids())))
        except NoReposError, nre:
            print nre
            raise
        except EmptyValueError, eve:
            print eve
            raise