Move atoi() into atoi.py and add a new debug2() debug level.

atoi() was getting redundant, and unfortunately we can't easily load
helpers.py in some places where we'd want to, because it depends on vars.py.
So move it to its own module.
This commit is contained in:
Avery Pennarun 2010-11-16 04:13:17 -08:00
commit 94b0e7166e
5 changed files with 19 additions and 21 deletions

6
atoi.py Normal file
View file

@ -0,0 +1,6 @@
def atoi(v):
try:
return int(v or 0)
except ValueError:
return 0

View file

@ -2,13 +2,6 @@ import sys, os, errno
import vars import vars
def atoi(v):
try:
return int(v or 0)
except ValueError:
return 0
def unlink(f): def unlink(f):
"""Delete a file at path 'f' if it currently exists. """Delete a file at path 'f' if it currently exists.
@ -68,7 +61,10 @@ else:
def debug(s): 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)) _log('redo: %s%s' % (vars.DEPTH, s))

View file

@ -2,6 +2,7 @@
# beware the jobberwack # beware the jobberwack
# #
import sys, os, errno, select, fcntl import sys, os, errno, select, fcntl
import atoi
_toplevel = 0 _toplevel = 0
_mytokens = 1 _mytokens = 1
@ -14,13 +15,6 @@ def _debug(s):
sys.stderr.write('jwack#%d: %s' % (os.getpid(),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): def _release(n):
global _mytokens global _mytokens
_debug('release(%d)\n' % n) _debug('release(%d)\n' % n)
@ -60,8 +54,8 @@ def setup(maxjobs):
s = flags[ofs+len(FIND):] s = flags[ofs+len(FIND):]
(arg,junk) = s.split(' ', 1) (arg,junk) = s.split(' ', 1)
(a,b) = arg.split(',', 1) (a,b) = arg.split(',', 1)
a = _atoi(a) a = atoi.atoi(a)
b = _atoi(b) b = atoi.atoi(b)
if a <= 0 or b <= 0: if a <= 0 or b <= 0:
raise ValueError('invalid --jobserver-fds: %r' % arg) raise ValueError('invalid --jobserver-fds: %r' % arg)
try: try:

View file

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
import sys, os, subprocess, glob, time, random import sys, os, subprocess, glob, time, random
import options, jwack import options, jwack, atoi
optspec = """ optspec = """
redo [targets...] redo [targets...]
@ -16,7 +16,7 @@ o = options.Options('redo', optspec)
targets = extra or ['all'] targets = extra or ['all']
if opt.debug: if opt.debug:
os.environ['REDO_DEBUG'] = '1' os.environ['REDO_DEBUG'] = str(opt.debug or 0)
if opt.verbose: if opt.verbose:
os.environ['REDO_VERBOSE'] = '1' os.environ['REDO_VERBOSE'] = '1'
if opt.shuffle: if opt.shuffle:
@ -67,6 +67,7 @@ def _possible_do_files(t):
def find_do_file(t): def find_do_file(t):
for dofile,basename,ext in _possible_do_files(t): for dofile,basename,ext in _possible_do_files(t):
debug2('%s: %s ?\n' % (t, dofile))
if os.path.exists(dofile): if os.path.exists(dofile):
add_dep(t, 'm', dofile) add_dep(t, 'm', dofile)
return dofile,basename,ext return dofile,basename,ext
@ -214,7 +215,7 @@ if not vars.DEPTH:
os.environ['PATH'] = ':'.join(dirnames) + ':' + os.environ['PATH'] os.environ['PATH'] = ':'.join(dirnames) + ':' + os.environ['PATH']
try: try:
j = atoi(opt.jobs or 1) j = atoi.atoi(opt.jobs or 1)
if j < 1 or j > 1000: if j < 1 or j > 1000:
err('invalid --jobs value: %r\n' % opt.jobs) err('invalid --jobs value: %r\n' % opt.jobs)
jwack.setup(j) jwack.setup(j)

View file

@ -1,8 +1,9 @@
import os import os
import atoi
TARGET = os.environ.get('REDO_TARGET', '') TARGET = os.environ.get('REDO_TARGET', '')
DEPTH = os.environ.get('REDO_DEPTH', '') 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 VERBOSE = os.environ.get('REDO_VERBOSE', '') and 1 or 0
SHUFFLE = os.environ.get('REDO_SHUFFLE', '') and 1 or 0 SHUFFLE = os.environ.get('REDO_SHUFFLE', '') and 1 or 0
STARTDIR = os.environ.get('REDO_STARTDIR', '') STARTDIR = os.environ.get('REDO_STARTDIR', '')