Expanded debug log
This commit is contained in:
parent
f1775766e7
commit
27d348bf9c
4 changed files with 48 additions and 2 deletions
|
|
@ -1,12 +1,17 @@
|
||||||
"""WizardKit: Executable functions"""
|
"""WizardKit: Executable functions"""
|
||||||
#vim: sts=2 sw=2 ts=2
|
#vim: sts=2 sw=2 ts=2
|
||||||
|
|
||||||
|
import logging
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
|
|
||||||
|
# STATIC VARIABLES
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
def build_cmd_kwargs(cmd, minimized=False, pipe=True, shell=False, **kwargs):
|
def build_cmd_kwargs(cmd, minimized=False, pipe=True, shell=False, **kwargs):
|
||||||
"""Build kwargs for use by subprocess functions, returns dict.
|
"""Build kwargs for use by subprocess functions, returns dict.
|
||||||
|
|
@ -14,6 +19,11 @@ def build_cmd_kwargs(cmd, minimized=False, pipe=True, shell=False, **kwargs):
|
||||||
Specifically subprocess.run() and subprocess.Popen().
|
Specifically subprocess.run() and subprocess.Popen().
|
||||||
NOTE: If no encoding specified then UTF-8 will be used.
|
NOTE: If no encoding specified then UTF-8 will be used.
|
||||||
"""
|
"""
|
||||||
|
LOG.debug(
|
||||||
|
'cmd: %s, minimized: %s, pipe: %s, shell: %s',
|
||||||
|
cmd, minimized, pipe, shell,
|
||||||
|
)
|
||||||
|
LOG.debug('kwargs: %s', kwargs)
|
||||||
cmd_kwargs = {
|
cmd_kwargs = {
|
||||||
'args': cmd,
|
'args': cmd,
|
||||||
'shell': shell,
|
'shell': shell,
|
||||||
|
|
@ -43,11 +53,13 @@ def build_cmd_kwargs(cmd, minimized=False, pipe=True, shell=False, **kwargs):
|
||||||
cmd_kwargs['stdout'] = subprocess.PIPE
|
cmd_kwargs['stdout'] = subprocess.PIPE
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
|
LOG.debug('cmd_kwargs: %s', cmd_kwargs)
|
||||||
return cmd_kwargs
|
return cmd_kwargs
|
||||||
|
|
||||||
|
|
||||||
def get_procs(name, exact=True):
|
def get_procs(name, exact=True):
|
||||||
"""Get process object(s) based on name, returns list of proc objects."""
|
"""Get process object(s) based on name, returns list of proc objects."""
|
||||||
|
LOG.debug('name: %s, exact: %s', name, exact)
|
||||||
processes = []
|
processes = []
|
||||||
regex = f'^{name}$' if exact else name
|
regex = f'^{name}$' if exact else name
|
||||||
|
|
||||||
|
|
@ -69,6 +81,10 @@ def kill_procs(name, exact=True, force=False, timeout=30):
|
||||||
If force is True then it will wait until timeout specified and then
|
If force is True then it will wait until timeout specified and then
|
||||||
send SIGKILL to any processes still alive.
|
send SIGKILL to any processes still alive.
|
||||||
"""
|
"""
|
||||||
|
LOG.debug(
|
||||||
|
'name: %s, exact: %s, force: %s, timeout: %s',
|
||||||
|
name, exact, force, timeout,
|
||||||
|
)
|
||||||
target_procs = get_procs(name, exact=exact)
|
target_procs = get_procs(name, exact=exact)
|
||||||
for proc in target_procs:
|
for proc in target_procs:
|
||||||
proc.terminate()
|
proc.terminate()
|
||||||
|
|
@ -80,8 +96,13 @@ def kill_procs(name, exact=True, force=False, timeout=30):
|
||||||
proc.kill()
|
proc.kill()
|
||||||
|
|
||||||
|
|
||||||
def popen_program(cmd, pipe=False, minimized=False, shell=False, **kwargs):
|
def popen_program(cmd, minimized=False, pipe=False, shell=False, **kwargs):
|
||||||
"""Run program and return a subprocess.Popen object."""
|
"""Run program and return a subprocess.Popen object."""
|
||||||
|
LOG.debug(
|
||||||
|
'cmd: %s, minimized: %s, pipe: %s, shell: %s',
|
||||||
|
cmd, minimized, pipe, shell,
|
||||||
|
)
|
||||||
|
LOG.debug('kwargs: %s', kwargs)
|
||||||
cmd_kwargs = build_cmd_kwargs(
|
cmd_kwargs = build_cmd_kwargs(
|
||||||
cmd,
|
cmd,
|
||||||
minimized=minimized,
|
minimized=minimized,
|
||||||
|
|
@ -95,6 +116,11 @@ def popen_program(cmd, pipe=False, minimized=False, shell=False, **kwargs):
|
||||||
|
|
||||||
def run_program(cmd, check=True, pipe=True, shell=False, **kwargs):
|
def run_program(cmd, check=True, pipe=True, shell=False, **kwargs):
|
||||||
"""Run program and return a subprocess.CompletedProcess object."""
|
"""Run program and return a subprocess.CompletedProcess object."""
|
||||||
|
LOG.debug(
|
||||||
|
'cmd: %s, check: %s, pipe: %s, shell: %s',
|
||||||
|
cmd, check, pipe, shell,
|
||||||
|
)
|
||||||
|
LOG.debug('kwargs: %s', kwargs)
|
||||||
cmd_kwargs = build_cmd_kwargs(
|
cmd_kwargs = build_cmd_kwargs(
|
||||||
cmd,
|
cmd,
|
||||||
check=check,
|
check=check,
|
||||||
|
|
@ -108,6 +134,7 @@ def run_program(cmd, check=True, pipe=True, shell=False, **kwargs):
|
||||||
|
|
||||||
def wait_for_procs(name, exact=True, timeout=None):
|
def wait_for_procs(name, exact=True, timeout=None):
|
||||||
"""Wait for all process matching name."""
|
"""Wait for all process matching name."""
|
||||||
|
LOG.debug('name: %s, exact: %s, timeout: %s', name, exact, timeout)
|
||||||
target_procs = get_procs(name, exact=exact)
|
target_procs = get_procs(name, exact=exact)
|
||||||
results = psutil.wait_procs(target_procs, timeout=timeout)
|
results = psutil.wait_procs(target_procs, timeout=timeout)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,20 @@
|
||||||
"""WizardKit: I/O Functions"""
|
"""WizardKit: I/O Functions"""
|
||||||
# vim: sts=2 sw=2 ts=2
|
# vim: sts=2 sw=2 ts=2
|
||||||
|
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
import pathlib
|
|
||||||
|
|
||||||
|
# STATIC VARIABLES
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
def delete_empty_folders(path):
|
def delete_empty_folders(path):
|
||||||
"""Recursively delete all empty folders in path."""
|
"""Recursively delete all empty folders in path."""
|
||||||
|
LOG.debug('path: %s', path)
|
||||||
|
|
||||||
# Delete empty subfolders first
|
# Delete empty subfolders first
|
||||||
for item in os.scandir(path):
|
for item in os.scandir(path):
|
||||||
if item.is_dir():
|
if item.is_dir():
|
||||||
|
|
@ -29,6 +34,11 @@ def delete_folder(path, force=False, ignore_errors=False):
|
||||||
NOTE: Exceptions are not caught by this function,
|
NOTE: Exceptions are not caught by this function,
|
||||||
ignore_errors is passed to shutil.rmtree to allow partial deletions.
|
ignore_errors is passed to shutil.rmtree to allow partial deletions.
|
||||||
"""
|
"""
|
||||||
|
LOG.debug(
|
||||||
|
'path: %s, force: %s, ignore_errors: %s',
|
||||||
|
path, force, ignore_errors,
|
||||||
|
)
|
||||||
|
|
||||||
if force:
|
if force:
|
||||||
shutil.rmtree(path, ignore_errors=ignore_errors)
|
shutil.rmtree(path, ignore_errors=ignore_errors)
|
||||||
else:
|
else:
|
||||||
|
|
@ -41,6 +51,11 @@ def delete_item(path, force=False, ignore_errors=False):
|
||||||
NOTE: Exceptions are not caught by this function,
|
NOTE: Exceptions are not caught by this function,
|
||||||
ignore_errors is passed to delete_folder to allow partial deletions.
|
ignore_errors is passed to delete_folder to allow partial deletions.
|
||||||
"""
|
"""
|
||||||
|
LOG.debug(
|
||||||
|
'path: %s, force: %s, ignore_errors: %s',
|
||||||
|
path, force, ignore_errors,
|
||||||
|
)
|
||||||
|
|
||||||
path = pathlib.Path(path)
|
path = pathlib.Path(path)
|
||||||
if path.is_dir():
|
if path.is_dir():
|
||||||
delete_folder(path, force=force, ignore_errors=ignore_errors)
|
delete_folder(path, force=force, ignore_errors=ignore_errors)
|
||||||
|
|
@ -50,6 +65,7 @@ def delete_item(path, force=False, ignore_errors=False):
|
||||||
|
|
||||||
def non_clobbering_path(path):
|
def non_clobbering_path(path):
|
||||||
"""Update path as needed to non-existing path, returns pathlib.Path."""
|
"""Update path as needed to non-existing path, returns pathlib.Path."""
|
||||||
|
LOG.debug('path: %s', path)
|
||||||
path = pathlib.Path(path)
|
path = pathlib.Path(path)
|
||||||
name = path.name
|
name = path.name
|
||||||
new_path = None
|
new_path = None
|
||||||
|
|
@ -71,6 +87,7 @@ def non_clobbering_path(path):
|
||||||
raise FileExistsError(new_path)
|
raise FileExistsError(new_path)
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
|
LOG.debug('new path: %s', new_path)
|
||||||
return new_path
|
return new_path
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ from wk.exe import run_program
|
||||||
from wk.io import non_clobber_path
|
from wk.io import non_clobber_path
|
||||||
from wk.std import GenericError, GenericWarning
|
from wk.std import GenericError, GenericWarning
|
||||||
|
|
||||||
|
|
||||||
# STATIC VARIABLES
|
# STATIC VARIABLES
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
REG_MSISERVER = r'HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\MSIServer'
|
REG_MSISERVER = r'HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\MSIServer'
|
||||||
|
|
|
||||||
|
|
@ -868,6 +868,7 @@ def print_warning(msg, log=True, **kwargs):
|
||||||
|
|
||||||
def set_title(title):
|
def set_title(title):
|
||||||
"""Set window title."""
|
"""Set window title."""
|
||||||
|
LOG.debug('title: %s', title)
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
os.system(f'title {title}')
|
os.system(f'title {title}')
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue