Skip to content

Commit 6aae7bf

Browse files
committed
9pm.py: make verbose global and andd vcprint()
Signed-off-by: Richard Alpe <[email protected]>
1 parent 77ab4a9 commit 6aae7bf

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

9pm.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
DATABASE = ""
2121
SCRATCHDIR = ""
2222
LOGDIR = None
23+
VERBOSE = False
2324

2425
if "TCLLIBPATH" in os.environ:
2526
os.environ["TCLLIBPATH"] = os.environ["TCLLIBPATH"] + " " + LIB_TCL_PATH
@@ -44,6 +45,12 @@ def cprint(color, *args, **kwargs):
4445
print(*args, **kwargs)
4546
sys.stdout.write(pcolor.reset)
4647

48+
def vcprint(color, *args, **kwargs):
49+
global VERBOSE
50+
51+
if VERBOSE:
52+
cprint(color, *args, **kwargs)
53+
4754
def execute(args, test, output_log):
4855
proc = subprocess.Popen([test['case']] + args, stdout=subprocess.PIPE)
4956
skip_suite = False
@@ -123,8 +130,7 @@ def run_onfail(args, test):
123130
print("\n{}Running onfail \"{}\" for test {}{}" . format(pcolor.cyan, test['onfail'],
124131
test['name'], pcolor.reset))
125132

126-
if args.verbose:
127-
cprint(pcolor.faint, f"Executing onfail {onfail['case']} for test {test['case']}")
133+
vcprint(pcolor.faint, f"Executing onfail {onfail['case']} for test {test['case']}")
128134

129135
with open(os.path.join(LOGDIR, "on-fail.log"), 'a') as log:
130136
log.write(f"\n\nON FAIL START")
@@ -145,9 +151,8 @@ def run_test(args, test):
145151

146152
return True, True, False
147153

148-
if args.verbose:
149-
cprint(pcolor.faint, f"Test File: {test['case']}")
150-
cprint(pcolor.faint, f"Test Cmdl: {opts}")
154+
vcprint(pcolor.faint, f"Test File: {test['case']}")
155+
vcprint(pcolor.faint, f"Test Cmdl: {opts}")
151156

152157
with open(os.path.join(LOGDIR, test['outfile']), 'a') as output:
153158
skip_suite, skip, err = execute(opts, test, output)
@@ -276,8 +281,11 @@ def parse_suite(suite_path, parent_suite_path, options, name=None):
276281
if 'test-spec' in suite['settings']:
277282
test_spec_path = get_test_spec_path(case['case'], suite['settings']['test-spec'])
278283
if os.path.exists(test_spec_path):
284+
vcprint(pcolor.faint, f"Found test specification: {test_spec_path} for {case['case']}")
279285
case['test-spec'] = test_spec_path
280286
case['test-spec-sha'] = calculate_sha1sum(test_spec_path)
287+
else:
288+
vcprint(pcolor.faint, f"No test specification for {case['case']} ({test_spec_path})")
281289

282290
if not os.path.isfile(case['case']):
283291
print("error, test case not found {}" . format(case['case']))
@@ -557,8 +565,7 @@ def parse_proj_config(root_path, args):
557565
path = args.proj
558566

559567
if path:
560-
if args.verbose:
561-
cprint(pcolor.faint, f"Using project config: {path}")
568+
vcprint(pcolor.faint, f"Using project config: {path}")
562569
os.environ["NINEPM_PROJ_CONFIG"] = path
563570
else:
564571
print("error, can't find any 9pm project config")
@@ -585,8 +592,7 @@ def parse_rc(root_path, args):
585592
path = next((os.path.expanduser(f) for f in files if os.path.exists(os.path.expanduser(f))), None)
586593

587594
if path:
588-
if args.verbose:
589-
cprint(pcolor.faint, f"Using RC: {path}")
595+
vcprint(pcolor.faint, f"Using RC: {path}")
590596
else:
591597
print("error, can't find any 9pm.rc file")
592598
sys.exit(1)
@@ -675,31 +681,31 @@ def main():
675681
global DATABASE
676682
global SCRATCHDIR
677683
global LOGDIR
684+
global VERBOSE
678685

679686
sha = ""
680687
if (sha := run_git_cmd(ROOT_PATH, ['rev-parse', 'HEAD'])):
681688
sha = f"({sha[:10]})"
682689
cprint(pcolor.yellow, "9PM - Simplicity is the ultimate sophistication {}" . format(sha))
683690

684691
args = parse_cmdline()
692+
VERBOSE = args.verbose
685693

686694
rc = parse_rc(ROOT_PATH, args)
687695

688696
LOGDIR = setup_log_dir(rc['LOG_PATH'])
689-
if args.verbose:
690-
cprint(pcolor.faint, f"Logging to: {LOGDIR}")
697+
698+
vcprint(pcolor.faint, f"Logging to: {LOGDIR}")
691699

692700
proj = parse_proj_config(ROOT_PATH, args)
693701

694702
scratch = tempfile.mkdtemp(suffix='', prefix='9pm_', dir='/tmp')
695-
if args.verbose:
696-
cprint(pcolor.faint, f"Created scratch dir: {scratch}")
703+
vcprint(pcolor.faint, f"Created scratch dir: {scratch}")
697704
SCRATCHDIR = scratch
698705
atexit.register(shutil.rmtree, SCRATCHDIR)
699706

700707
db = tempfile.NamedTemporaryFile(suffix='_db', prefix='9pm_', dir=scratch)
701-
if args.verbose:
702-
cprint(pcolor.faint, f"Created databasefile: {db.name}")
708+
vcprint(pcolor.faint, f"Created databasefile: {db.name}")
703709
DATABASE = db.name
704710

705711
if 'PROJECT-NAME' in proj:

0 commit comments

Comments
 (0)