Replace more pylint sections with ruff
This commit is contained in:
parent
08294caffc
commit
9f66b151af
13 changed files with 35 additions and 42 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -42,5 +42,5 @@ if __name__ == '__main__':
|
|||
pass
|
||||
except SystemExit:
|
||||
raise
|
||||
except: #pylint: disable=bare-except
|
||||
except: # noqa: E722
|
||||
wk.std.major_exception()
|
||||
|
|
|
|||
|
|
@ -37,5 +37,5 @@ if __name__ == '__main__':
|
|||
main()
|
||||
except SystemExit:
|
||||
raise
|
||||
except: #pylint: disable=bare-except
|
||||
except: # noqa: E722
|
||||
wk.std.major_exception()
|
||||
|
|
|
|||
|
|
@ -25,5 +25,5 @@ if __name__ == '__main__':
|
|||
main()
|
||||
except SystemExit:
|
||||
raise
|
||||
except: #pylint: disable=bare-except
|
||||
except: # noqa: E722
|
||||
wk.std.major_exception()
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import os
|
|||
import re
|
||||
import sys
|
||||
|
||||
import wk
|
||||
|
||||
# STATIC VARIABLES
|
||||
SCANDIR = os.getcwd()
|
||||
USAGE = '''Usage: {script} <search-terms>...
|
||||
|
|
@ -13,12 +15,6 @@ USAGE = '''Usage: {script} <search-terms>...
|
|||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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}'
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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}'
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue