From 80e99a2d290b10ed908320c97ca11874aac422b0 Mon Sep 17 00:00:00 2001 From: Jesse Jaggars Date: Tue, 14 Feb 2012 09:27:36 -0600 Subject: adding root_symlink support under tarfiles and fixing getOption behavior --- sos/plugins/__init__.py | 6 +++++- sos/utilities.py | 10 ++++++++++ tests/option_tests.py | 10 ++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 68c5b477..576196de 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -311,7 +311,9 @@ class Plugin(object): for name, parms in izip(self.optNames, self.optParms): if _check(name): - return parms['enabled'] + val = parms['enabled'] + if val != None: + return val for key, value in self.cInfo.get('global_plugin_options', {}).iteritems(): if _check(key): @@ -442,6 +444,8 @@ class Plugin(object): if not (status == 127 or status == 32512): # if not command_not_found outfn_strip = outfn[len(self.cInfo['cmddir'])+1:] self.archive.add_string(shout, outfn) + if root_symlink: + self.archive.add_link(outfn, root_symlink) else: self.soslog.debug("could not run command: %s" % exe) outfn = None diff --git a/sos/utilities.py b/sos/utilities.py index e91586de..015c6c8e 100644 --- a/sos/utilities.py +++ b/sos/utilities.py @@ -296,6 +296,9 @@ class Archive(object): name = os.path.split(self._name)[-1] return os.path.join(name, src.lstrip(os.sep)) + def add_link(self, dest, link_name): + pass + class TarFileArchive(Archive): @@ -329,6 +332,13 @@ class TarFileArchive(Archive): tar_info.mtime = time.time() self.tarfile.addfile(tar_info, StringIO(content)) + def add_link(self, dest, link_name): + tar_info = tarfile.TarInfo(name=self.prepend(link_name)) + tar_info.type = tarfile.SYMTYPE + tar_info.linkname = dest + tar_info.mtime = time.time() + self.tarfile.addfile(tar_info, None) + def open_file(self, name): try: self.tarfile.close() diff --git a/tests/option_tests.py b/tests/option_tests.py index 06f048a4..03804dec 100644 --- a/tests/option_tests.py +++ b/tests/option_tests.py @@ -10,9 +10,13 @@ class GlobalOptionTest(unittest.TestCase): self.commons = { 'global_plugin_options': { 'test_option': 'foobar', + 'baz': None, + 'empty_global': True, }, } self.plugin = Plugin(self.commons) + self.plugin.optNames = ['baz', 'empty'] + self.plugin.optParms = [{'enabled': False}, {'enabled': None}] def test_simple_lookup(self): self.assertEquals(self.plugin.getOption('test_option'), 'foobar') @@ -20,5 +24,11 @@ class GlobalOptionTest(unittest.TestCase): def test_multi_lookup(self): self.assertEquals(self.plugin.getOption(('not_there', 'test_option')), 'foobar') + def test_cascade(self): + self.assertEquals(self.plugin.getOption(('baz')), False) + + def test_none_should_cascade(self): + self.assertEquals(self.plugin.getOption(('empty', 'empty_global')), True) + if __name__ == "__main__": unittest.main() -- cgit