aboutsummaryrefslogtreecommitdiffstats
path: root/plugins_overview.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugins_overview.py')
-rw-r--r--plugins_overview.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/plugins_overview.py b/plugins_overview.py
index 46bcbf5a..d847548c 100644
--- a/plugins_overview.py
+++ b/plugins_overview.py
@@ -8,7 +8,7 @@
# - list of paths it forbits to collect (add_forbidden_path)
# - list of commands it calls (add_cmd_output)
#
-# Output of the script:
+# Output of the script:
# - a JSON object with plugins in keys
# - or CSV format in case "csv" cmdline is provided
#
@@ -29,9 +29,11 @@ PLUGDIR = 'sos/report/plugins'
plugs_data = {} # the map of all plugins data to collect
plugcontent = '' # content of plugin file just being processed
+
# method to parse an item of a_s_c/a_c_o/.. methods
# we work on an assumption the item is a string quoted by \" or optionally
-# by \'. If we detect at least 2 such chars in the item, take what is between those.
+# by \'. If we detect at least 2 such chars in the item, take what is between
+# those.
def add_valid_item(dest, item):
for qoutemark in "\"\'":
split = item.split(qoutemark)
@@ -39,13 +41,14 @@ def add_valid_item(dest, item):
dest.append(split[1])
return
-# method to find in `plugcontent` all items of given method (a_c_s/a_c_o/..) split
-# by comma; add each valid item to the `dest` list
+
+# method to find in `plugcontent` all items of given method (a_c_s/a_c_o/..)
+# split by comma; add each valid item to the `dest` list
def add_all_items(method, dest, wrapopen='\(', wrapclose='\)'):
regexp = "%s%s(.*?)%s" % (method, wrapopen, wrapclose)
for match in re.findall(regexp, plugcontent, flags=re.MULTILINE|re.DOTALL):
# tuple of distros ended by either (class|from|import)
- if isinstance(match,tuple):
+ if isinstance(match, tuple):
for item in list(match):
if item not in ['class', 'from', 'import']:
for it in item.split(','):
@@ -63,7 +66,8 @@ def add_all_items(method, dest, wrapopen='\(', wrapclose='\)'):
else:
add_valid_item(dest, match)
-# main body: traverse report's plugins directory and for each plugin, grep for
+
+# main body: traverse report's plugins directory and for each plugin, grep for
# add_copy_spec / add_forbidden_path / add_cmd_output there
for plugfile in sorted(os.listdir(PLUGDIR)):
# ignore non-py files and __init__.py
@@ -73,7 +77,8 @@ for plugfile in sorted(os.listdir(PLUGDIR)):
# if plugname != 'bcache':
# continue
plugs_data[plugname] = {
- 'sourcecode': 'https://github.com/sosreport/sos/blob/main/sos/report/plugins/%s.py' % plugname,
+ 'sourcecode': 'https://github.com/sosreport/sos/blob/'
+ f'main/sos/report/plugins/{plugname}.py',
'distros': [],
'profiles': [],
'packages': [],
@@ -84,8 +89,13 @@ for plugfile in sorted(os.listdir(PLUGDIR)):
'journals': [],
'env': [],
}
- plugcontent = open(os.path.join(PLUGDIR, plugfile)).read().replace('\n','')
- add_all_items("from sos.report.plugins import ", plugs_data[plugname]['distros'], wrapopen='', wrapclose='(class|from|import)')
+ plugcontent = open(os.path.join(PLUGDIR, plugfile)).read().replace('\n', '')
+ add_all_items(
+ "from sos.report.plugins import ",
+ plugs_data[plugname]['distros'],
+ wrapopen='',
+ wrapclose='(class|from|import)'
+ )
add_all_items("profiles = ", plugs_data[plugname]['profiles'], wrapopen='')
add_all_items("packages = ", plugs_data[plugname]['packages'], wrapopen='')
add_all_items("add_copy_spec", plugs_data[plugname]['copyspecs'])
@@ -98,7 +108,8 @@ for plugfile in sorted(os.listdir(PLUGDIR)):
# print output; if "csv" is cmdline argument, print in CSV format, else JSON
if (len(sys.argv) > 1) and (sys.argv[1] == "csv"):
- print("plugin;url;distros;profiles;packages;copyspecs;forbidden;commands;service_status;journals;env_vars")
+ print("plugin;url;distros;profiles;packages;copyspecs;forbidden;commands;"
+ "service_status;journals;env_vars")
for plugname in plugs_data.keys():
plugin = plugs_data[plugname]
# determine max number of lines - usually "max(len(copyspec),len(commands))"
@@ -109,10 +120,10 @@ if (len(sys.argv) > 1) and (sys.argv[1] == "csv"):
for key in plugkeys:
maxline = max(maxline, len(plugin[key]))
for line in range(maxline):
- out = ";" if line>0 else ("%s;%s" % (plugname, plugin['sourcecode']))
+ out = ";" if line > 0 else f"{plugname};{plugin['sourcecode']}"
for key in plugkeys:
out += ";"
- if line<len(plugin[key]):
+ if line < len(plugin[key]):
out += plugin[key][line]
print(out)
else: