diff --git a/scripts/build-ufd b/scripts/build-ufd index 0159a3be..8bb04f63 100755 --- a/scripts/build-ufd +++ b/scripts/build-ufd @@ -10,5 +10,5 @@ if __name__ == '__main__': wk.kit.ufd.build_ufd() except SystemExit: raise - except: #pylint: disable=bare-except + except: # noqa: E722 wk.std.major_exception() diff --git a/scripts/hw-sensors b/scripts/hw-sensors index 3879cf2a..1f1393c9 100755 --- a/scripts/hw-sensors +++ b/scripts/hw-sensors @@ -42,5 +42,5 @@ if __name__ == '__main__': pass except SystemExit: raise - except: #pylint: disable=bare-except + except: # noqa: E722 wk.std.major_exception() diff --git a/scripts/mount-all-volumes b/scripts/mount-all-volumes index a359a88f..3adde487 100755 --- a/scripts/mount-all-volumes +++ b/scripts/mount-all-volumes @@ -37,5 +37,5 @@ if __name__ == '__main__': main() except SystemExit: raise - except: #pylint: disable=bare-except + except: # noqa: E722 wk.std.major_exception() diff --git a/scripts/mount-backup-shares b/scripts/mount-backup-shares index cc1dd437..d19ffaf6 100755 --- a/scripts/mount-backup-shares +++ b/scripts/mount-backup-shares @@ -25,5 +25,5 @@ if __name__ == '__main__': main() except SystemExit: raise - except: #pylint: disable=bare-except + except: # noqa: E722 wk.std.major_exception() diff --git a/scripts/msword-search b/scripts/msword-search index 33e1a7c7..a5aac0b6 100755 --- a/scripts/msword-search +++ b/scripts/msword-search @@ -6,6 +6,8 @@ import os import re import sys +import wk + # STATIC VARIABLES SCANDIR = os.getcwd() USAGE = '''Usage: {script} ... @@ -13,12 +15,6 @@ USAGE = '''Usage: {script} ... This script will search all doc/docx files below the current directory for the search-terms provided (case-insensitive).'''.format(script=__file__) - -# Init -sys.path.append(os.path.dirname(os.path.realpath(__file__))) -from functions.network import * -init_global_vars() - REGEX_DOC_FILES = re.compile(r'\.docx?$', re.IGNORECASE) @@ -34,10 +30,10 @@ def scan_file(file_path, search): match = False try: if entry.name.lower().endswith('.docx'): - result = run_program(['unzip', '-p', entry.path]) + result = wk.exe.run_program(['unzip', '-p', entry.path]) else: # Assuming .doc - result = run_program(['antiword', entry.path]) + result = wk.exe.run_program(['antiword', entry.path]) out = result.stdout.decode() match = re.search(search, out, re.IGNORECASE) except Exception: @@ -50,13 +46,13 @@ def scan_file(file_path, search): if __name__ == '__main__': try: # Prep - clear_screen() + wk.std.clear_screen() terms = [re.sub(r'\s+', r'\s*', t) for t in sys.argv[1:]] search = '({})'.format('|'.join(terms)) if len(sys.argv) == 1: # Print usage - print_standard(USAGE) + wk.std.print_standard(USAGE) else: matches = [] for entry in scan_for_docs(SCANDIR): @@ -64,21 +60,20 @@ if __name__ == '__main__': # Strip None values (i.e. non-matching entries) matches = [m for m in matches if m] if matches: - print_success('Found {} {}:'.format( + wk.std.print_success('Found {} {}:'.format( len(matches), 'Matches' if len(matches) > 1 else 'Match')) for match in matches: - print_standard(match) + wk.std.print_standard(match) else: - print_error('No matches found.') + wk.std.print_error('No matches found.') # Done - print_standard('\nDone.') + wk.std.print_standard('\nDone.') #pause("Press Enter to exit...") - exit_script() - except SystemExit as sys_exit: - exit_script(sys_exit.code) - except: - major_exception() + except SystemExit: + raise + except: # noqa: E722 + wk.std.major_exception() # vim: sts=2 sw=2 ts=2 diff --git a/scripts/unmount-backup-shares b/scripts/unmount-backup-shares index 44ad5f71..e7375c08 100755 --- a/scripts/unmount-backup-shares +++ b/scripts/unmount-backup-shares @@ -1,6 +1,5 @@ #!/usr/bin/env python3 """WizardKit: Unmount Backup Shares""" -# pylint: disable=invalid-name # vim: sts=2 sw=2 ts=2 import wk @@ -24,5 +23,5 @@ if __name__ == '__main__': main() except SystemExit: raise - except: #pylint: disable=bare-except + except: # noqa: E722 wk.std.major_exception() diff --git a/scripts/upload-logs b/scripts/upload-logs index 6921c5bc..61ba67bf 100755 --- a/scripts/upload-logs +++ b/scripts/upload-logs @@ -65,12 +65,11 @@ def upload_log_dir(reason='Testing'): server = wk.cfg.net.CRASH_SERVER dest = pathlib.Path(f'~/{reason}_{NOW.strftime("%Y-%m-%dT%H%M%S%z")}.txz') dest = dest.expanduser().resolve() - data = None # Compress LOG_DIR (relative to parent dir) os.chdir(LOG_DIR.parent) cmd = ['tar', 'caf', dest.name, LOG_DIR.name] - proc = wk.exe.run_program(cmd, check=False) + wk.exe.run_program(cmd, check=False) # Upload compressed data url = f'{server["Url"]}/{dest.name}' diff --git a/scripts/wk/exe.py b/scripts/wk/exe.py index 3511c510..5628754b 100644 --- a/scripts/wk/exe.py +++ b/scripts/wk/exe.py @@ -91,7 +91,7 @@ def build_cmd_kwargs(cmd, minimized=False, pipe=True, shell=False, **kwargs): # Strip sudo if appropriate if cmd[0] == 'sudo': - if os.name == 'posix' and os.geteuid() == 0: # pylint: disable=no-member + if os.name == 'posix' and os.geteuid() == 0: cmd.pop(0) # Add additional kwargs if applicable @@ -254,14 +254,14 @@ def stop_process(proc, graceful=True): # Graceful exit if graceful: - if os.name == 'posix' and os.geteuid() != 0: # pylint: disable=no-member + if os.name == 'posix' and os.geteuid() != 0: run_program(['sudo', 'kill', str(proc.pid)], check=False) else: proc.terminate() time.sleep(2) # Force exit - if os.name == 'posix' and os.geteuid() != 0: # pylint: disable=no-member + if os.name == 'posix' and os.geteuid() != 0: run_program(['sudo', 'kill', '-9', str(proc.pid)], check=False) else: proc.kill() diff --git a/scripts/wk/hw/cpu.py b/scripts/wk/hw/cpu.py index 6fb1ec8f..8458b918 100644 --- a/scripts/wk/hw/cpu.py +++ b/scripts/wk/hw/cpu.py @@ -105,13 +105,13 @@ def check_mprime_results(test_obj, working_dir) -> None: def start_mprime(working_dir, log_path) -> subprocess.Popen: """Start mprime and save filtered output to log, returns Popen object.""" set_apple_fan_speed('max') - proc_mprime = subprocess.Popen( # pylint: disable=consider-using-with + proc_mprime = subprocess.Popen( ['mprime', '-t'], cwd=working_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ) - proc_grep = subprocess.Popen( # pylint: disable=consider-using-with + proc_grep = subprocess.Popen( 'grep --ignore-case --invert-match --line-buffered stress.txt'.split(), stdin=proc_mprime.stdout, stdout=subprocess.PIPE, @@ -150,7 +150,7 @@ def start_sysbench(sensors, sensors_out, log_path, pane) -> SysbenchType: tmux_respawn_pane(pane, watch_file=log_path, watch_cmd='tail') # Start sysbench - filehandle_sysbench = open( # pylint: disable=consider-using-with + filehandle_sysbench = open( log_path, 'a', encoding='utf-8', ) proc_sysbench = exe.popen_program(sysbench_cmd, stdout=filehandle_sysbench) diff --git a/scripts/wk/hw/diags.py b/scripts/wk/hw/diags.py index ed23ea8d..7b7cb755 100644 --- a/scripts/wk/hw/diags.py +++ b/scripts/wk/hw/diags.py @@ -271,7 +271,7 @@ class State(): data.append('----') proc = exe.run_program(['smc', '-l']) data.extend(proc.stdout.splitlines()) - except Exception: # pylint: disable=broad-except + except Exception: LOG.ERROR('Error(s) encountered while exporting SMC data') data = [line.strip() for line in data] with open(f'{debug_dir}/smc.data', 'a', encoding='utf-8') as _f: diff --git a/scripts/wk/net.py b/scripts/wk/net.py index d797c470..3e9382a9 100644 --- a/scripts/wk/net.py +++ b/scripts/wk/net.py @@ -127,8 +127,8 @@ def mount_network_share(details, mount_point=None, read_write=False): '-t', 'cifs', '-o', ( f'{"rw" if read_write else "ro"}' - f',uid={os.getuid()}' # pylint: disable=no-member - f',gid={os.getgid()}' # pylint: disable=no-member + f',uid={os.getuid()}' + f',gid={os.getgid()}' f',username={username}' f',{"password=" if password else "guest"}{password}' ), diff --git a/scripts/wk/os/win.py b/scripts/wk/os/win.py index ba5eef3d..3b5c80e3 100644 --- a/scripts/wk/os/win.py +++ b/scripts/wk/os/win.py @@ -613,7 +613,7 @@ def is_booted_uefi(): # Get value from kernel32 API (firmware_type is updated by the call) try: kernel.GetFirmwareType(ctypes.byref(firmware_type)) - except Exception: # pylint: disable=broad-except + except Exception: # Ignore and set firmware_type back to zero firmware_type = ctypes.c_uint(0) diff --git a/scripts/wk/std.py b/scripts/wk/std.py index 3b174f6f..65fd69f0 100644 --- a/scripts/wk/std.py +++ b/scripts/wk/std.py @@ -434,7 +434,7 @@ class TryAndPrint(): pass else: message = str(_exception) - except Exception: # pylint: disable=broad-except + except Exception: # Just use the exception name instead pass @@ -442,7 +442,7 @@ class TryAndPrint(): if _exception.__class__.__name__ not in ('GenericError', 'GenericWarning'): try: message = f'{_exception.__class__.__name__}: {message}' - except Exception: # pylint: disable=broad-except + except Exception: message = f'UNKNOWN ERROR: {message}' # Fix multi-line messages @@ -454,7 +454,7 @@ class TryAndPrint(): ] lines[0] = lines[0].strip() message = '\n'.join(lines) - except Exception: # pylint: disable=broad-except + except Exception: pass # Done @@ -573,7 +573,7 @@ class TryAndPrint(): result_msg = self._format_exception_message(_exception) print_error(result_msg, log=False) f_exception = _exception - except Exception as _exception: # pylint: disable=broad-except + except Exception as _exception: # Unexpected exceptions if verbose: result_msg = self._format_exception_message(_exception) @@ -973,7 +973,7 @@ def save_pickles(obj_dict, out_path=None): continue with open(f'{out_path}/{name}.pickle', 'wb') as _f: pickle.dump(obj, _f, protocol=pickle.HIGHEST_PROTOCOL) - except Exception: # pylint: disable=broad-except + except Exception: LOG.error('Failed to save all the pickles', exc_info=True)