@@ -89,7 +89,6 @@ def get_repo_info():
8989 # 3.8, which is a supported environment for hotsos.
9090 with warnings .catch_warnings ():
9191 warnings .filterwarnings ("ignore" , category = DeprecationWarning )
92- # pylint: disable-next=W4902
9392 with resources .path ('hotsos' , '.repo-info' ) as repo_info :
9493 if repo_info and os .path .exists (repo_info ):
9594 with open (repo_info , encoding = 'utf-8' ) as fd :
@@ -103,7 +102,7 @@ def get_repo_info():
103102 return "unknown"
104103 # We really do want to catch all here since we don't care why it failed
105104 # but don't want to fail hard if it does.
106- except Exception : # pylint: disable=W0718
105+ except Exception : # pylint: disable=broad-exception-caught
107106 return "unknown"
108107
109108 return out .decode ().strip ()
@@ -126,7 +125,7 @@ def get_defs_path():
126125 defs = os .path .join (get_hotsos_root (), 'defs' )
127126 if not os .path .isdir (defs ):
128127 # pypi
129- with resources .path ('hotsos' , 'defs' ) as path : # pylint: disable=W4902
128+ with resources .path ('hotsos' , 'defs' ) as path :
130129 defs = path
131130
132131 if not os .path .isdir (defs ):
@@ -146,8 +145,6 @@ def get_templates_path():
146145 # source
147146 templates = os .path .join (get_hotsos_root (), 'templates' )
148147 if not os .path .isdir (templates ):
149- # pypi
150- # pylint: disable-next=W4902
151148 with resources .path ('hotsos' , 'templates' ) as path :
152149 templates = path
153150
@@ -257,7 +254,41 @@ def run_client(arguments, plugins_to_run, data_root_name, logmanager):
257254 return client .summary
258255
259256
260- # pylint: disable=R0915
257+ def init_config (arguments ):
258+ cfg = {'repo_info' : get_repo_info (),
259+ 'force_mode' : arguments .force ,
260+ 'hotsos_version' : get_version (),
261+ 'command_timeout' : arguments .command_timeout ,
262+ 'use_all_logs' : arguments .all_logs ,
263+ 'plugin_yaml_defs' : arguments .defs_path ,
264+ 'templates_path' : arguments .templates_path ,
265+ 'event_tally_granularity' : arguments .event_tally_granularity ,
266+ 'max_logrotate_depth' : arguments .max_logrotate_depth ,
267+ 'max_parallel_tasks' : arguments .max_parallel_tasks ,
268+ 'machine_readable' : arguments .machine_readable ,
269+ 'debug_mode' : arguments .debug ,
270+ 'scenario_filter' : arguments .scenario ,
271+ 'event_filter' : arguments .event }
272+ HotSOSConfig .set (** cfg )
273+
274+
275+ def set_tmpdir (tmpdir ):
276+ """
277+ If an alternate temporary directory is provided we set the necessary env
278+ vars so that this new location is used by default.
279+ """
280+ if tmpdir is None :
281+ return
282+
283+ if not os .path .isdir (tmpdir ):
284+ raise ValueError (f"temporary directory path '{ tmpdir } ' not found." )
285+
286+ for key in ['TMPDIR' , 'TEMP' , 'TMP' ]:
287+ os .environ [key ] = tmpdir
288+
289+ tempfile .tempdir = tmpdir
290+
291+
261292def main ():
262293 @click .command (name = 'hotsos' )
263294 @click .option ('--event' , default = '' ,
@@ -349,7 +380,7 @@ def main():
349380 '/tmp or /var/tmp' ))
350381 @set_plugin_options
351382 @click .argument ('data_root' , required = False , type = click .Path (exists = True ))
352- def cli (** kwargs ): # pylint: disable=too-many-branches
383+ def cli (** kwargs ):
353384 """
354385 Run this tool on a host or against a sosreport to perform
355386 analysis of specific applications and the host itself. A summary of
@@ -387,35 +418,17 @@ def cli(**kwargs): # pylint: disable=too-many-branches
387418 plugins_to_run .add ('hotsos' )
388419 plugins_to_run .add ('system' )
389420
390- _version = get_version ()
391421 if arguments .version :
392- print (_version )
422+ print (get_version () )
393423 return
394424
395- if arguments .tmp_dir is not None :
396- if not os .path .isdir (str (arguments .tmp_dir )):
397- print (f"The temporary directory { arguments .tmp_dir } does not"
398- " exist." )
399- return
400- for key in ['TMPDIR' , 'TEMP' , 'TMP' ]:
401- os .environ [key ] = arguments .tmp_dir
402- tempfile .tempdir = arguments .tmp_dir
403-
404- config = {'repo_info' : get_repo_info (),
405- 'force_mode' : arguments .force ,
406- 'hotsos_version' : _version ,
407- 'command_timeout' : arguments .command_timeout ,
408- 'use_all_logs' : arguments .all_logs ,
409- 'plugin_yaml_defs' : arguments .defs_path ,
410- 'templates_path' : arguments .templates_path ,
411- 'event_tally_granularity' : arguments .event_tally_granularity ,
412- 'max_logrotate_depth' : arguments .max_logrotate_depth ,
413- 'max_parallel_tasks' : arguments .max_parallel_tasks ,
414- 'machine_readable' : arguments .machine_readable ,
415- 'debug_mode' : arguments .debug ,
416- 'scenario_filter' : arguments .scenario ,
417- 'event_filter' : arguments .event }
418- HotSOSConfig .set (** config )
425+ try :
426+ set_tmpdir (arguments .tmp_dir )
427+ except ValueError as exc :
428+ sys .stderr .write (f'ERROR: { exc } \n ' )
429+ sys .exit (1 )
430+
431+ init_config (arguments )
419432
420433 with LoggingManager () as logmanager :
421434 with DataRootManager (
@@ -466,7 +479,7 @@ def cli(**kwargs): # pylint: disable=too-many-branches
466479 if out :
467480 sys .stdout .write (f"{ out } \n " )
468481
469- cli (prog_name = 'hotsos' ) # pylint: disable=no-value-for-parameter
482+ cli (prog_name = 'hotsos' )
470483
471484
472485def exit_if_os_version_not_supported_in_snap ():
0 commit comments