diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2014-03-12 16:27:34 +0000 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2014-03-12 17:53:11 +0000 |
commit | ef4e4b60eeaef33fa5e4ee074c6736cd3412397b (patch) | |
tree | 6b7416c208e4d343274833427b47005e946b6a3a | |
parent | c55c58cf2dabf93c924c839c8ed045c18e31ba1c (diff) | |
download | sos-ef4e4b60eeaef33fa5e4ee074c6736cd3412397b.tar.gz |
Clean up get_cmd_path/make_cmd_path/make_cmd_dirs mess
Clean up the Plugin helper methods for handling command output
paths. This better matches the proposal in Issue #181 and
simplifies code for plugins that need to generate their own
paths under sos_commands/<plugin>/.
- Rename get_cmd_path() to get_cmd_output_path()
- Add an optional 'name' parameter to specify a subdirectory
name in the plugin's sos_commands/<plugin>/ directory.
- Default to creating directories if they do not exist
Finally fix up all existing users of get_cmd_path() to use the
new interface and remove handrolled uses of os.path.join(...) for
generating these paths.
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/plugins/__init__.py | 26 | ||||
-rw-r--r-- | sos/plugins/cluster.py | 2 | ||||
-rw-r--r-- | sos/plugins/foreman.py | 6 | ||||
-rw-r--r-- | sos/plugins/katello.py | 6 | ||||
-rw-r--r-- | sos/plugins/lvm2.py | 2 | ||||
-rw-r--r-- | sos/plugins/rhui.py | 8 | ||||
-rw-r--r-- | sos/plugins/satellite.py | 2 | ||||
-rw-r--r-- | sos/plugins/yum.py | 2 |
8 files changed, 18 insertions, 36 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 9b643aba..efb69500 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -512,26 +512,18 @@ class Plugin(object): """Run a program and collect the output""" self.collect_cmds.append( (exe, suggest_filename, root_symlink, timeout) ) - def get_cmd_path(self): + def get_cmd_output_path(self, name=None, make=True): """Return a path into which this module should store collected command output """ - return os.path.join(self.archive.get_tmp_dir(), - 'sos_commands', self.name()) - - def make_cmd_path(self, path): - """Return a string representing an absolute path within this - plug-in's command output directory by apending the relative path - name 'path'. - """ - return os.path.join(self.get_cmd_path(), path) - - - def make_cmd_dirs(self, path): - """Recursively create new subdirectories under this plug-in's - command output path. - """ - os.makedirs(self.make_cmd_path(path)) + cmd_output_path = os.path.join(self.archive.get_tmp_dir(), + 'sos_commands', self.name()) + if name: + cmd_output_path = os.path.join(cmd_output_path, name) + if make: + os.makedirs(cmd_output_path) + + return cmd_output_path def file_grep(self, regexp, *fnames): """Returns lines matched in fnames, where fnames can either be diff --git a/sos/plugins/cluster.py b/sos/plugins/cluster.py index 79574988..0b839fa1 100644 --- a/sos/plugins/cluster.py +++ b/sos/plugins/cluster.py @@ -97,7 +97,7 @@ class Cluster(Plugin, RedHatPlugin): "crm_from parameter '%s' is not a valid date: using default" % self.get_option('crm_from')) - crm_dest = os.path.join(self.get_cmd_path(), 'crm_report') + crm_dest = self.get_cmd_output_path(name='crm_report') self.add_cmd_output('crm_report -S -d --dest %s --from "%s"' % (crm_dest, crm_from)) diff --git a/sos/plugins/foreman.py b/sos/plugins/foreman.py index ab4dfcb3..a2f2881d 100644 --- a/sos/plugins/foreman.py +++ b/sos/plugins/foreman.py @@ -25,7 +25,5 @@ class Foreman(Plugin, RedHatPlugin): packages = ('foreman') def setup(self): - foreman_debug_path = os.path.join( - self.get_cmd_path(),"foreman-debug") - self.add_cmd_output("%s -q -a -d %s" - % ("foreman-debug", foreman_debug_path)) + self.add_cmd_output("%s -q -a -d %s" % ("foreman-debug", + self.get_cmd_output_path(name="foreman-debug"))) diff --git a/sos/plugins/katello.py b/sos/plugins/katello.py index 19993884..acf5d905 100644 --- a/sos/plugins/katello.py +++ b/sos/plugins/katello.py @@ -25,7 +25,5 @@ class Katello(Plugin, RedHatPlugin): packages = ('katello', 'katello-common', 'katello-headpin') def setup(self): - katello_debug_path = os.path.join( - self.get_cmd_path(),"katello-debug") - self.add_cmd_output("%s --notar -d %s" - % ("katello-debug", katello_debug_path)) + self.add_cmd_output("katello-debug --notar -d %s" + % self.get_cmd_output_path(name="katello-debug")) diff --git a/sos/plugins/lvm2.py b/sos/plugins/lvm2.py index 1a4d5896..102df267 100644 --- a/sos/plugins/lvm2.py +++ b/sos/plugins/lvm2.py @@ -34,7 +34,7 @@ class Lvm2(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin): if metadata: lvmdump_opts = "-a -m" cmd = lvmdump_cmd % (lvmdump_opts, - os.path.join(self.get_cmd_path(), "lvmdump")) + self.get_cmd_output_path(name="lvmdump")) self.add_cmd_output(cmd) def setup(self): diff --git a/sos/plugins/rhui.py b/sos/plugins/rhui.py index a291515f..f0413b4b 100644 --- a/sos/plugins/rhui.py +++ b/sos/plugins/rhui.py @@ -32,13 +32,7 @@ class Rhui(Plugin, RedHatPlugin): else: cds = "" - rhui_debug_dst_path = os.path.join(self.get_cmd_path(), - self.commons['cmddir'], self.name()) - try: - os.mkdir(rhui_debug_dst_path) - except: - return - + rhui_debug_dst_path = self.get_cmd_output_path() self.add_cmd_output("python %s %s --dir %s" % (self.rhui_debug_path, cds, rhui_debug_dst_path), suggest_filename="rhui-debug") diff --git a/sos/plugins/satellite.py b/sos/plugins/satellite.py index 7f4aafd3..474933a2 100644 --- a/sos/plugins/satellite.py +++ b/sos/plugins/satellite.py @@ -78,7 +78,7 @@ class Satellite(Plugin, RedHatPlugin): "/etc/tomcat6/", "/var/log/tomcat6/"]) if os.path.exists("spacewalk-debug"): self.add_cmd_output("spacewalk-debug --dir %s" - % os.path.join(self.get_cmd_path())) + % self.get_cmd_output_path(name="spacewalk-debug")) if self.proxy: self.add_copy_specs(["/etc/squid", "/var/log/squid"]) diff --git a/sos/plugins/yum.py b/sos/plugins/yum.py index aa8cb186..c978842b 100644 --- a/sos/plugins/yum.py +++ b/sos/plugins/yum.py @@ -49,7 +49,7 @@ class Yum(Plugin, RedHatPlugin): self.add_cmd_output("subscription-manager list --installed") self.add_cmd_output("subscription-manager list --consumed") self.add_cmd_output("rhsm-debug system --no-archive --destination %s" - % self.get_cmd_path()) + % self.get_cmd_output_path()) if self.get_option("yumlist"): # List various information about available packages |