Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

The only thing in helpers.py that needed vars.py was the log stuff.

So put it in its own file.  Now it's safer to import and use helpers even if
you can't safely touch vars.
  • Loading branch information...
commit e18fa85d58415d0e92be872dac32da46e76ba334 1 parent 1abaf77
apenwarr authored
3  builder.py
... ... @@ -1,6 +1,7 @@
1 1 import sys, os, errno, stat
2 2 import vars, jwack, state
3   -from helpers import log, log_, debug, debug2, err, warn, unlink, close_on_exec
  3 +from helpers import unlink, close_on_exec
  4 +from log import log, log_, debug, debug2, err, warn
4 5
5 6
6 7 def _possible_do_files(t):
50 helpers.py
... ... @@ -1,5 +1,5 @@
1   -import sys, os, errno, fcntl
2   -import vars
  1 +import os, errno, fcntl
  2 +from atoi import atoi
3 3
4 4
5 5 def unlink(f):
@@ -15,52 +15,6 @@ def unlink(f):
15 15 pass # it doesn't exist, that's what you asked for
16 16
17 17
18   -def log_(s):
19   - sys.stdout.flush()
20   - if vars.DEBUG_PIDS:
21   - sys.stderr.write('%d %s' % (os.getpid(), s))
22   - else:
23   - sys.stderr.write(s)
24   - sys.stderr.flush()
25   -
26   -
27   -def _clog(s):
28   - log_('\x1b[32mredo %s\x1b[1m%s\x1b[m' % (vars.DEPTH, s))
29   -def _bwlog(s):
30   - log_('redo %s%s' % (vars.DEPTH, s))
31   -
32   -def _cerr(s):
33   - log_('\x1b[31mredo: %s\x1b[1m%s\x1b[m' % (vars.DEPTH, s))
34   -def _bwerr(s):
35   - log_('redo: %s%s' % (vars.DEPTH, s))
36   -
37   -def _cwarn(s):
38   - log_('\x1b[33mredo: %s\x1b[1m%s\x1b[m' % (vars.DEPTH, s))
39   -def _bwwarn(s):
40   - log_('redo: %s%s' % (vars.DEPTH, s))
41   -
42   -
43   -if os.isatty(2):
44   - log = _clog
45   - err = _cerr
46   - warn = _cwarn
47   -else:
48   - log = _bwlog
49   - err = _bwerr
50   - warn = _bwwarn
51   -
52   -
53   -def debug(s):
54   - if vars.DEBUG >= 1:
55   - log_('redo: %s%s' % (vars.DEPTH, s))
56   -def debug2(s):
57   - if vars.DEBUG >= 2:
58   - log_('redo: %s%s' % (vars.DEPTH, s))
59   -def debug3(s):
60   - if vars.DEBUG >= 3:
61   - log_('redo: %s%s' % (vars.DEPTH, s))
62   -
63   -
64 18 def close_on_exec(fd, yes):
65 19 fl = fcntl.fcntl(fd, fcntl.F_GETFD)
66 20 fl &= ~fcntl.FD_CLOEXEC
7 jwack.py
@@ -2,7 +2,7 @@
2 2 # beware the jobberwack
3 3 #
4 4 import sys, os, errno, select, fcntl, signal
5   -import atoi
  5 +from helpers import atoi, close_on_exec
6 6
7 7 _toplevel = 0
8 8 _mytokens = 1
@@ -83,8 +83,8 @@ def setup(maxjobs):
83 83 s = flags[ofs+len(FIND):]
84 84 (arg,junk) = s.split(' ', 1)
85 85 (a,b) = arg.split(',', 1)
86   - a = atoi.atoi(a)
87   - b = atoi.atoi(b)
  86 + a = atoi(a)
  87 + b = atoi(b)
88 88 if a <= 0 or b <= 0:
89 89 raise ValueError('invalid --jobserver-fds: %r' % arg)
90 90 try:
@@ -242,7 +242,6 @@ def start_job(reason, jobfunc, donefunc):
242 242 finally:
243 243 _debug('exit: %d\n' % rv)
244 244 os._exit(rv)
245   - from helpers import close_on_exec
246 245 close_on_exec(r, True)
247 246 os.close(w)
248 247 pd = Job(reason, pid, donefunc)
49 log.py
... ... @@ -0,0 +1,49 @@
  1 +import sys, os
  2 +import vars
  3 +
  4 +def log_(s):
  5 + sys.stdout.flush()
  6 + if vars.DEBUG_PIDS:
  7 + sys.stderr.write('%d %s' % (os.getpid(), s))
  8 + else:
  9 + sys.stderr.write(s)
  10 + sys.stderr.flush()
  11 +
  12 +
  13 +def _clog(s):
  14 + log_('\x1b[32mredo %s\x1b[1m%s\x1b[m' % (vars.DEPTH, s))
  15 +def _bwlog(s):
  16 + log_('redo %s%s' % (vars.DEPTH, s))
  17 +
  18 +def _cerr(s):
  19 + log_('\x1b[31mredo: %s\x1b[1m%s\x1b[m' % (vars.DEPTH, s))
  20 +def _bwerr(s):
  21 + log_('redo: %s%s' % (vars.DEPTH, s))
  22 +
  23 +def _cwarn(s):
  24 + log_('\x1b[33mredo: %s\x1b[1m%s\x1b[m' % (vars.DEPTH, s))
  25 +def _bwwarn(s):
  26 + log_('redo: %s%s' % (vars.DEPTH, s))
  27 +
  28 +
  29 +if os.isatty(2):
  30 + log = _clog
  31 + err = _cerr
  32 + warn = _cwarn
  33 +else:
  34 + log = _bwlog
  35 + err = _bwerr
  36 + warn = _bwwarn
  37 +
  38 +
  39 +def debug(s):
  40 + if vars.DEBUG >= 1:
  41 + log_('redo: %s%s' % (vars.DEPTH, s))
  42 +def debug2(s):
  43 + if vars.DEBUG >= 2:
  44 + log_('redo: %s%s' % (vars.DEPTH, s))
  45 +def debug3(s):
  46 + if vars.DEBUG >= 3:
  47 + log_('redo: %s%s' % (vars.DEPTH, s))
  48 +
  49 +
2  redo-always.py
... ... @@ -1,7 +1,7 @@
1 1 #!/usr/bin/python
2 2 import sys, os
3 3 import vars, state
4   -from helpers import err
  4 +from log import err
5 5
6 6
7 7 try:
3  redo-ifchange.py
... ... @@ -1,7 +1,8 @@
1 1 #!/usr/bin/python
2 2 import sys, os, errno, stat
3 3 import vars, state, builder, jwack
4   -from helpers import debug, debug2, err, unlink
  4 +from helpers import unlink
  5 +from log import debug, debug2, err
5 6
6 7 def _nice(t):
7 8 return state.relpath(os.path.join(vars.BASE, t), vars.STARTDIR)
2  redo-ifcreate.py
... ... @@ -1,7 +1,7 @@
1 1 #!/usr/bin/python
2 2 import sys, os
3 3 import vars, state
4   -from helpers import err
  4 +from log import err
5 5
6 6
7 7 try:
2  redo-oob.py
... ... @@ -1,7 +1,7 @@
1 1 #!/usr/bin/python
2 2 import sys, os
3 3 import state
4   -from helpers import err
  4 +from log import err
5 5
6 6 if len(sys.argv[1:]) < 2:
7 7 err('%s: at least 2 arguments expected.\n' % sys.argv[0])
2  redo-stamp.py
... ... @@ -1,7 +1,7 @@
1 1 #!/usr/bin/python
2 2 import sys, os
3 3 import vars, state
4   -from helpers import err, debug2
  4 +from log import err, debug2
5 5
6 6 if len(sys.argv) > 1:
7 7 err('%s: no arguments expected.\n' % sys.argv[0])
9 redo.py
... ... @@ -1,6 +1,7 @@
1 1 #!/usr/bin/python
2 2 import sys, os
3   -import options, jwack, atoi
  3 +import options
  4 +from helpers import atoi
4 5
5 6 optspec = """
6 7 redo [targets...]
@@ -57,15 +58,15 @@
57 58 os.environ['REDO'] = os.path.abspath(sys.argv[0])
58 59
59 60
60   -import vars, state, builder
61   -from helpers import err
  61 +import vars, state, builder, jwack
  62 +from log import err
62 63
63 64
64 65 if is_root:
65 66 state.init()
66 67
67 68 try:
68   - j = atoi.atoi(opt.jobs or 1)
  69 + j = atoi(opt.jobs or 1)
69 70 if j < 1 or j > 1000:
70 71 err('invalid --jobs value: %r\n' % opt.jobs)
71 72 jwack.setup(j)
6 state.py
... ... @@ -1,7 +1,7 @@
1 1 import sys, os, errno, glob, stat, fcntl, sqlite3
2 2 import vars
3   -from helpers import unlink, err, debug2, debug3, close_on_exec
4   -import helpers
  3 +from helpers import unlink, close_on_exec
  4 +from log import err, debug2, debug3
5 5
6 6 SCHEMA_VER=1
7 7 TIMEOUT=60
@@ -97,7 +97,6 @@ def _write(q, l):
97 97 return
98 98 global _wrote
99 99 _wrote += 1
100   - #helpers.log_('W: %r %r\n' % (q,l))
101 100 db().execute(q, l)
102 101
103 102
@@ -106,7 +105,6 @@ def commit():
106 105 return
107 106 global _wrote
108 107 if _wrote:
109   - #helpers.log_("COMMIT (%d)\n" % _wrote)
110 108 db().commit()
111 109 _wrote = 0
112 110
6 vars.py
... ... @@ -1,5 +1,5 @@
1 1 import os
2   -import atoi
  2 +from atoi import atoi
3 3
4 4 if not os.environ.get('REDO'):
5 5 import sys
@@ -10,7 +10,7 @@
10 10 PWD = os.environ.get('REDO_PWD', '')
11 11 TARGET = os.environ.get('REDO_TARGET', '')
12 12 DEPTH = os.environ.get('REDO_DEPTH', '')
13   -DEBUG = atoi.atoi(os.environ.get('REDO_DEBUG', ''))
  13 +DEBUG = atoi(os.environ.get('REDO_DEBUG', ''))
14 14 DEBUG_LOCKS = os.environ.get('REDO_DEBUG_LOCKS', '') and 1 or 0
15 15 DEBUG_PIDS = os.environ.get('REDO_DEBUG_PIDS', '') and 1 or 0
16 16 VERBOSE = os.environ.get('REDO_VERBOSE', '') and 1 or 0
@@ -18,7 +18,7 @@
18 18 KEEP_GOING = os.environ.get('REDO_KEEP_GOING', '') and 1 or 0
19 19 SHUFFLE = os.environ.get('REDO_SHUFFLE', '') and 1 or 0
20 20 STARTDIR = os.environ['REDO_STARTDIR']
21   -RUNID = atoi.atoi(os.environ.get('REDO_RUNID')) or None
  21 +RUNID = atoi(os.environ.get('REDO_RUNID')) or None
22 22 BASE = os.environ['REDO_BASE']
23 23 while BASE and BASE.endswith('/'):
24 24 BASE = BASE[:-1]

0 comments on commit e18fa85

Please sign in to comment.
Something went wrong with that request. Please try again.