diff --git a/atoi.py b/atoi.py new file mode 100644 index 0000000..e53ec92 --- /dev/null +++ b/atoi.py @@ -0,0 +1,6 @@ + +def atoi(v): + try: + return int(v or 0) + except ValueError: + return 0 diff --git a/helpers.py b/helpers.py index d72a944..be968dd 100644 --- a/helpers.py +++ b/helpers.py @@ -2,13 +2,6 @@ import sys, os, errno import vars -def atoi(v): - try: - return int(v or 0) - except ValueError: - return 0 - - def unlink(f): """Delete a file at path 'f' if it currently exists. @@ -68,7 +61,10 @@ else: def debug(s): - if vars.DEBUG: + if vars.DEBUG >= 1: + _log('redo: %s%s' % (vars.DEPTH, s)) +def debug2(s): + if vars.DEBUG >= 2: _log('redo: %s%s' % (vars.DEPTH, s)) diff --git a/jwack.py b/jwack.py index a23a1bf..a9c45d7 100644 --- a/jwack.py +++ b/jwack.py @@ -2,6 +2,7 @@ # beware the jobberwack # import sys, os, errno, select, fcntl +import atoi _toplevel = 0 _mytokens = 1 @@ -14,13 +15,6 @@ def _debug(s): sys.stderr.write('jwack#%d: %s' % (os.getpid(),s)) -def _atoi(v): - try: - return int(v or 0) - except ValueError: - return 0 - - def _release(n): global _mytokens _debug('release(%d)\n' % n) @@ -60,8 +54,8 @@ def setup(maxjobs): s = flags[ofs+len(FIND):] (arg,junk) = s.split(' ', 1) (a,b) = arg.split(',', 1) - a = _atoi(a) - b = _atoi(b) + a = atoi.atoi(a) + b = atoi.atoi(b) if a <= 0 or b <= 0: raise ValueError('invalid --jobserver-fds: %r' % arg) try: diff --git a/redo.py b/redo.py index 2b50198..b37b9ad 100755 --- a/redo.py +++ b/redo.py @@ -1,6 +1,6 @@ #!/usr/bin/python import sys, os, subprocess, glob, time, random -import options, jwack +import options, jwack, atoi optspec = """ redo [targets...] @@ -16,7 +16,7 @@ o = options.Options('redo', optspec) targets = extra or ['all'] if opt.debug: - os.environ['REDO_DEBUG'] = '1' + os.environ['REDO_DEBUG'] = str(opt.debug or 0) if opt.verbose: os.environ['REDO_VERBOSE'] = '1' if opt.shuffle: @@ -67,6 +67,7 @@ def _possible_do_files(t): def find_do_file(t): for dofile,basename,ext in _possible_do_files(t): + debug2('%s: %s ?\n' % (t, dofile)) if os.path.exists(dofile): add_dep(t, 'm', dofile) return dofile,basename,ext @@ -214,7 +215,7 @@ if not vars.DEPTH: os.environ['PATH'] = ':'.join(dirnames) + ':' + os.environ['PATH'] try: - j = atoi(opt.jobs or 1) + j = atoi.atoi(opt.jobs or 1) if j < 1 or j > 1000: err('invalid --jobs value: %r\n' % opt.jobs) jwack.setup(j) diff --git a/vars.py b/vars.py index 22aada3..ae24865 100644 --- a/vars.py +++ b/vars.py @@ -1,8 +1,9 @@ import os +import atoi TARGET = os.environ.get('REDO_TARGET', '') DEPTH = os.environ.get('REDO_DEPTH', '') -DEBUG = os.environ.get('REDO_DEBUG', '') and 1 or 0 +DEBUG = atoi.atoi(os.environ.get('REDO_DEBUG', '')) VERBOSE = os.environ.get('REDO_VERBOSE', '') and 1 or 0 SHUFFLE = os.environ.get('REDO_SHUFFLE', '') and 1 or 0 STARTDIR = os.environ.get('REDO_STARTDIR', '')