def setUp(self):
     from comoonics.sos.sosreport import SosReport
     _options=Values()
     for _key, _value in self.OPTIONS.items():
         setattr(_options, _key, _value)
     self._sosreport=SosReport(_options)
     self._sosreport.checkrootuid=False
     self._sosreport.pluginpaths={"../plugins_test": "comoonics.sos.plugins_test"}
class testSosReportBase(unittest.TestCase):
    RESULT_FILENAMES=[]
    OPTIONS={}
    def setUp(self):
        from comoonics.sos.sosreport import SosReport
        _options=Values()
        for _key, _value in self.OPTIONS.items():
            setattr(_options, _key, _value)
        self._sosreport=SosReport(_options)
        self._sosreport.checkrootuid=False
        self._sosreport.pluginpaths={"../plugins_test": "comoonics.sos.plugins_test"}
    def testSosReport(self):
        import tarfile
        import os.path
        self._sosreport.main()
        _tarfile=tarfile.open(self._sosreport.policy.report_file)
        for _tarinfo in _tarfile:
            if _tarinfo.isfile():
                self.failUnless(os.path.basename(_tarinfo.name) in self.RESULT_FILENAMES, "%s not in %s" %(os.path.basename(_tarinfo.name), self.RESULT_FILENAMES))
 def __init__(self):
     super(SosReportPlugin, self).__init__("sosreport")
     self._sosreport=SosReport()
     self.addCommand("listplugins", self.doListPlugins)
     self.addCommand("main", self.doMain)
     from optparse import OptionParser, Option
     
     self.cmdParser = OptionParser_extended(option_class=SosOption)
     self.cmdParser.add_option("-l", "--list-plugins", action="store_true", \
                              dest="listPlugins", default=False, \
                              help="list plugins and available plugin options")
     self.cmdParser.add_option("-n", "--skip-plugins", action="extend", \
                              dest="noplugins", type="string", \
                              help="skip these plugins", default = [])
     self.cmdParser.add_option("-e", "--enable-plugins", action="extend", \
                              dest="enableplugins", type="string", \
                              help="enable these plugins", default = [])
     self.cmdParser.add_option("-o", "--only-plugins", action="extend", \
                              dest="onlyplugins", type="string", \
                              help="enable these plugins only", default = [])
     self.cmdParser.add_option("-k", action="extend", \
                              dest="plugopts", type="string", \
                              help="plugin options in plugname.option=value format (see -l)")
     self.cmdParser.add_option("-a", "--alloptions", action="store_true", \
                              dest="usealloptions", default=False, \
                              help="enable all options for loaded plugins")
     self.cmdParser.add_option("-u", "--upload", action="store_true", \
                              dest="upload", default=False, \
                              help="upload the report to Red Hat support")
     self.cmdParser.add_option("--batch", action="store_true", \
                              dest="batch", default=False, \
                              help="do not ask any question (batch mode)")
     self.cmdParser.add_option("--no-colors", action="store_true", \
                              dest="nocolors", default=False, \
                              help="do not use terminal colors for text")
     self.cmdParser.add_option("-v", "--verbose", action="count", \
                              dest="verbosity", \
                              help="increase verbosity")
     self.cmdParser.add_option("--debug", action="count", \
                              dest="debug", \
                              help="enabling debugging")
     self.cmdParser.add_option("--no-progressbar", action="store_false", \
                              dest="progressbar", default=True, \
                              help="do not display a progress bar.")
     self.cmdParser.add_option("--no-multithread", action="store_true", \
                              dest="nomultithread", \
                              help="disable multi-threaded gathering mode (slower)", default=False)
class SosReportPlugin(Plugin):
    """
    Plugin for fenceacksv to use the sosreport from redhat
    """
    def __init__(self):
        super(SosReportPlugin, self).__init__("sosreport")
        self._sosreport=SosReport()
        self.addCommand("listplugins", self.doListPlugins)
        self.addCommand("main", self.doMain)
        from optparse import OptionParser, Option
        
        self.cmdParser = OptionParser_extended(option_class=SosOption)
        self.cmdParser.add_option("-l", "--list-plugins", action="store_true", \
                                 dest="listPlugins", default=False, \
                                 help="list plugins and available plugin options")
        self.cmdParser.add_option("-n", "--skip-plugins", action="extend", \
                                 dest="noplugins", type="string", \
                                 help="skip these plugins", default = [])
        self.cmdParser.add_option("-e", "--enable-plugins", action="extend", \
                                 dest="enableplugins", type="string", \
                                 help="enable these plugins", default = [])
        self.cmdParser.add_option("-o", "--only-plugins", action="extend", \
                                 dest="onlyplugins", type="string", \
                                 help="enable these plugins only", default = [])
        self.cmdParser.add_option("-k", action="extend", \
                                 dest="plugopts", type="string", \
                                 help="plugin options in plugname.option=value format (see -l)")
        self.cmdParser.add_option("-a", "--alloptions", action="store_true", \
                                 dest="usealloptions", default=False, \
                                 help="enable all options for loaded plugins")
        self.cmdParser.add_option("-u", "--upload", action="store_true", \
                                 dest="upload", default=False, \
                                 help="upload the report to Red Hat support")
        self.cmdParser.add_option("--batch", action="store_true", \
                                 dest="batch", default=False, \
                                 help="do not ask any question (batch mode)")
        self.cmdParser.add_option("--no-colors", action="store_true", \
                                 dest="nocolors", default=False, \
                                 help="do not use terminal colors for text")
        self.cmdParser.add_option("-v", "--verbose", action="count", \
                                 dest="verbosity", \
                                 help="increase verbosity")
        self.cmdParser.add_option("--debug", action="count", \
                                 dest="debug", \
                                 help="enabling debugging")
        self.cmdParser.add_option("--no-progressbar", action="store_false", \
                                 dest="progressbar", default=True, \
                                 help="do not display a progress bar.")
        self.cmdParser.add_option("--no-multithread", action="store_true", \
                                 dest="nomultithread", \
                                 help="disable multi-threaded gathering mode (slower)", default=False)
    def doListPlugins(self, *params, **kwds):
        """
        Lists all available plugins.
        """
        _params=list(params)
        (__cmdLineOpts__, __cmdLineArgs__)=self.cmdParser.parse_args(_params)
        self._sosreport.listPlugins()
        
    def doMain(self, *params, **kwds):
        _params=list(params)
        (__cmdLineOpts__, __cmdLineArgs__)=self.cmdParser.parse_args(_params)
        self._sosreport.main()
        
    def help(self, _command=None):
        if not _command:
            return self.cmdParser.format_help()
        else:
            return super(SosReportPlugin, self).help(_command)