Rename vars{,_init}.py -> env{,_init}.py.

This fixes some pylint 'redefined builtins' warnings.  While I was
here, I fixed the others too by renaming a few local variables.
This commit is contained in:
Avery Pennarun 2018-12-04 23:34:28 -05:00
commit ded14507b0
19 changed files with 142 additions and 142 deletions

View file

@ -11,7 +11,7 @@ jobs=1
# We probably want to fix these eventually, but in the meantime, these
# ones are relatively harmless.
disable=redefined-builtin,multiple-imports,missing-docstring,wrong-import-position,locally-disabled,invalid-name,unused-argument,fixme,global-statement,redefined-variable-type,using-constant-test,unused-variable,file-ignored,simplifiable-if-statement
disable=multiple-imports,missing-docstring,wrong-import-position,locally-disabled,invalid-name,unused-argument,fixme,global-statement,redefined-variable-type,using-constant-test,unused-variable,file-ignored,simplifiable-if-statement,relative-import
[REPORTS]

View file

@ -1,12 +1,12 @@
import sys, os, errno, stat, signal, time
import vars, jobserver, state, paths
import env, jobserver, state, paths
from helpers import unlink, close_on_exec
import logs
from logs import debug2, err, warn, meta, check_tty
def _nice(t):
return state.relpath(t, vars.STARTDIR)
return state.relpath(t, env.STARTDIR)
def _try_stat(filename):
@ -53,7 +53,7 @@ def start_stdin_log_reader(status, details, pretty, color,
os.dup2(w, 1)
os.dup2(w, 2)
os.close(w)
check_tty(sys.stderr, vars.COLOR)
check_tty(sys.stderr, env.COLOR)
else:
# child
try:
@ -88,7 +88,7 @@ def start_stdin_log_reader(status, details, pretty, color,
def await_log_reader():
if not vars.LOG:
if not env.LOG:
return
if log_reader_pid > 0:
# never actually close fd#1 or fd#2; insanity awaits.
@ -110,7 +110,7 @@ class ImmediateReturn(Exception):
class BuildJob(object):
def __init__(self, t, sf, lock, shouldbuildfunc, donefunc):
self.t = t # original target name, not relative to vars.BASE
self.t = t # original target name, not relative to env.BASE
self.sf = sf
tmpbase = t
while not os.path.isdir(os.path.dirname(tmpbase) or '.'):
@ -140,7 +140,7 @@ class BuildJob(object):
except ImmediateReturn, e:
return self._after2(e.rv)
if vars.NO_OOB or dirty == True: # pylint: disable=singleton-comparison
if env.NO_OOB or dirty == True: # pylint: disable=singleton-comparison
self._start_do()
else:
self._start_unlocked(dirty)
@ -198,16 +198,16 @@ class BuildJob(object):
# temp output file name
state.relpath(os.path.abspath(self.tmpname2), dodir),
]
if vars.VERBOSE:
if env.VERBOSE:
argv[1] += 'v'
if vars.XTRACE:
if env.XTRACE:
argv[1] += 'x'
firstline = open(os.path.join(dodir, dofile)).readline().strip()
if firstline.startswith('#!/'):
argv[0:2] = firstline[2:].split(' ')
# make sure to create the logfile *before* writing the meta() about it.
# that way redo-log won't trace into an obsolete logfile.
if vars.LOG:
if env.LOG:
open(state.logname(self.sf.id), 'w')
# FIXME: put these variables somewhere else, instead of on-the-fly
# extending this class!
@ -236,13 +236,13 @@ class BuildJob(object):
# grab a lock.
here = os.getcwd()
def _fix(p):
return state.relpath(os.path.join(vars.BASE, p), here)
return state.relpath(os.path.join(env.BASE, p), here)
argv = (['redo-unlocked', _fix(self.sf.name)] +
list(set(_fix(d.name) for d in dirty)))
meta('check', state.target_relpath(self.t))
state.commit()
def run():
os.environ['REDO_DEPTH'] = vars.DEPTH + ' '
os.environ['REDO_DEPTH'] = env.DEPTH + ' '
# python ignores SIGPIPE
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
os.execvp(argv[0], argv)
@ -261,18 +261,18 @@ class BuildJob(object):
assert state.is_flushed()
dn = self.dodir
newp = os.path.realpath(dn)
os.environ['REDO_PWD'] = state.relpath(newp, vars.STARTDIR)
os.environ['REDO_PWD'] = state.relpath(newp, env.STARTDIR)
os.environ['REDO_TARGET'] = self.basename + self.ext
os.environ['REDO_DEPTH'] = vars.DEPTH + ' '
vars.add_lock(str(self.lock.fid))
os.environ['REDO_DEPTH'] = env.DEPTH + ' '
env.add_lock(str(self.lock.fid))
if dn:
os.chdir(dn)
os.dup2(self.f.fileno(), 1)
os.close(self.f.fileno())
close_on_exec(1, False)
if vars.LOG:
if env.LOG:
cur_inode = str(os.fstat(2).st_ino)
if not vars.LOG_INODE or cur_inode == vars.LOG_INODE:
if not env.LOG_INODE or cur_inode == env.LOG_INODE:
# .do script has *not* redirected stderr, which means we're
# using redo-log's log saving mode. That means subprocs
# should be logged to their own file. If the .do script
@ -290,7 +290,7 @@ class BuildJob(object):
del os.environ['REDO_LOG_INODE']
os.environ['REDO_LOG'] = ''
signal.signal(signal.SIGPIPE, signal.SIG_DFL) # python ignores SIGPIPE
if vars.VERBOSE or vars.XTRACE:
if env.VERBOSE or env.XTRACE:
logs.write('* %s' % ' '.join(self.argv).replace('\n', ' '))
os.execvp(self.argv[0], self.argv)
# FIXME: it would be nice to log the exit code to logf.
@ -387,7 +387,7 @@ class BuildJob(object):
def main(targets, shouldbuildfunc):
retcode = [0] # a list so that it can be reassigned from done()
if vars.SHUFFLE:
if env.SHUFFLE:
import random
random.shuffle(targets)
@ -397,9 +397,9 @@ def main(targets, shouldbuildfunc):
if rv:
retcode[0] = 1
if vars.TARGET and not vars.UNLOCKED:
me = os.path.join(vars.STARTDIR,
os.path.join(vars.PWD, vars.TARGET))
if env.TARGET and not env.UNLOCKED:
me = os.path.join(env.STARTDIR,
os.path.join(env.PWD, env.TARGET))
myfile = state.File(name=me)
selflock = state.Lock(state.LOG_LOCK_MAGIC + myfile.id)
else:
@ -435,7 +435,7 @@ def main(targets, shouldbuildfunc):
if not jobserver.has_token():
state.commit()
jobserver.ensure_token_or_cheat(t, cheat)
if retcode[0] and not vars.KEEP_GOING:
if retcode[0] and not env.KEEP_GOING:
break
if not state.check_sane():
err('.redo directory disappeared; cannot continue.\n')
@ -443,7 +443,7 @@ def main(targets, shouldbuildfunc):
break
f = state.File(name=t)
lock = state.Lock(f.id)
if vars.UNLOCKED:
if env.UNLOCKED:
lock.owned = True
else:
lock.trylock()
@ -478,7 +478,7 @@ def main(targets, shouldbuildfunc):
jobserver.ensure_token_or_cheat('self', cheat)
# at this point, we don't have any children holding any tokens, so
# it's okay to block below.
if retcode[0] and not vars.KEEP_GOING:
if retcode[0] and not env.KEEP_GOING:
break
if locked:
if not state.check_sane():
@ -521,7 +521,7 @@ def main(targets, shouldbuildfunc):
retcode[0] = 2
lock.unlock()
else:
BuildJob(t, state.File(id=fid), lock,
BuildJob(t, state.File(fid=fid), lock,
shouldbuildfunc, done).start()
lock = None
state.commit()

View file

@ -1,11 +1,11 @@
import sys, os
import vars, state
import env, state
def main():
try:
me = os.path.join(vars.STARTDIR,
os.path.join(vars.PWD, vars.TARGET))
me = os.path.join(env.STARTDIR,
os.path.join(env.PWD, env.TARGET))
f = state.File(name=me)
f.add_dep('m', state.ALWAYS)
always = state.File(name=state.ALWAYS)

View file

@ -1,16 +1,16 @@
import os, sys, traceback
import vars_init
vars_init.init(sys.argv[1:])
import env_init
env_init.init(sys.argv[1:])
import vars, state, builder, jobserver, deps
import env, state, builder, jobserver, deps
from logs import debug2, err
def should_build(t):
f = state.File(name=t)
if f.is_failed():
raise builder.ImmediateReturn(32)
dirty = deps.isdirty(f, depth='', max_changed=vars.RUNID,
dirty = deps.isdirty(f, depth='', max_changed=env.RUNID,
already_checked=[])
return f.is_generated, dirty == [f] and deps.DIRTY or dirty
@ -18,17 +18,17 @@ def should_build(t):
def main():
rv = 202
try:
if vars_init.is_toplevel and vars.LOG:
if env_init.is_toplevel and env.LOG:
builder.close_stdin()
builder.start_stdin_log_reader(
status=True, details=True,
pretty=True, color=True, debug_locks=False, debug_pids=False)
if vars.TARGET and not vars.UNLOCKED:
me = os.path.join(vars.STARTDIR,
os.path.join(vars.PWD, vars.TARGET))
if env.TARGET and not env.UNLOCKED:
me = os.path.join(env.STARTDIR,
os.path.join(env.PWD, env.TARGET))
f = state.File(name=me)
debug2('TARGET: %r %r %r\n'
% (vars.STARTDIR, vars.PWD, vars.TARGET))
% (env.STARTDIR, env.PWD, env.TARGET))
else:
f = me = None
debug2('redo-ifchange: not adding depends.\n')
@ -52,11 +52,11 @@ def main():
err('unexpected error: %r\n' % e)
rv = 1
except KeyboardInterrupt:
if vars_init.is_toplevel:
if env_init.is_toplevel:
builder.await_log_reader()
sys.exit(200)
state.commit()
if vars_init.is_toplevel:
if env_init.is_toplevel:
builder.await_log_reader()
sys.exit(rv)

View file

@ -1,12 +1,12 @@
import sys, os
import vars, state
import env, state
from logs import err
def main():
try:
me = os.path.join(vars.STARTDIR,
os.path.join(vars.PWD, vars.TARGET))
me = os.path.join(env.STARTDIR,
os.path.join(env.PWD, env.TARGET))
f = state.File(name=me)
for t in sys.argv[1:]:
if not t:

View file

@ -21,10 +21,10 @@ o = options.Options(optspec)
(opt, flags, extra) = o.parse(sys.argv[1:])
targets = extra
import vars_init
vars_init.init(list(targets))
import env_init
env_init.init(list(targets))
import vars, logs, state
import env, logs, state
topdir = os.getcwd()
already = set()
@ -64,7 +64,7 @@ def is_locked(fid):
def _fix_depth():
vars.DEPTH = len(depth) * ' '
env.DEPTH = len(depth) * ' '
def _rel(top, mydir, path):
@ -236,11 +236,11 @@ def main():
sys.exit(1)
if opt.status < 2 and not os.isatty(2):
opt.status = False
logs.setup(file=sys.stdout, pretty=opt.pretty, color=opt.color)
logs.setup(tty=sys.stdout, pretty=opt.pretty, color=opt.color)
if opt.debug_locks:
vars.DEBUG_LOCKS = 1
env.DEBUG_LOCKS = 1
if opt.debug_pids:
vars.DEBUG_PIDS = 1
env.DEBUG_PIDS = 1
if opt.ack_fd:
# Write back to owner, to let them know we started up okay and
# will be able to see their error output, so it's okay to close

View file

@ -1,9 +1,9 @@
import sys, os
import vars_init
vars_init.init([])
import env_init
env_init.init([])
import vars, state, deps
import env, state, deps
from logs import err
if len(sys.argv[1:]) != 0:
@ -32,12 +32,12 @@ def main():
if f.is_target():
if deps.isdirty(f,
depth='',
max_changed=vars.RUNID,
max_changed=env.RUNID,
already_checked=[],
is_checked=is_checked,
set_checked=set_checked,
log_override=log_override):
print state.relpath(os.path.join(vars.BASE, f.name), cwd)
print state.relpath(os.path.join(env.BASE, f.name), cwd)
if __name__ == '__main__':

View file

@ -71,18 +71,18 @@ if opt.no_log:
if opt.no_color:
os.environ['REDO_COLOR'] = '0'
import vars_init
vars_init.init(targets)
import env_init
env_init.init(targets)
import vars, state, builder, jobserver
import env, state, builder, jobserver
from logs import warn, err
def main():
try:
j = atoi(opt.jobs or 1)
if vars_init.is_toplevel and (vars.LOG or j > 1):
if env_init.is_toplevel and (env.LOG or j > 1):
builder.close_stdin()
if vars_init.is_toplevel and vars.LOG:
if env_init.is_toplevel and env.LOG:
builder.start_stdin_log_reader(
status=opt.status, details=opt.details,
pretty=opt.pretty, color=opt.color,
@ -91,8 +91,8 @@ def main():
if os.path.exists(t):
f = state.File(name=t)
if not f.is_generated:
warn('%s: exists and not marked as generated; not redoing.\n'
% f.nicename())
warn(('%s: exists and not marked as generated; ' +
'not redoing.\n') % f.nicename())
state.rollback()
if j < 1 or j > 1000:
@ -112,11 +112,11 @@ def main():
traceback.print_exc(100, sys.stderr)
err('unexpected error: %r\n' % e)
retcode = 1
if vars_init.is_toplevel:
if env_init.is_toplevel:
builder.await_log_reader()
sys.exit(retcode)
except KeyboardInterrupt:
if vars_init.is_toplevel:
if env_init.is_toplevel:
builder.await_log_reader()
sys.exit(200)

View file

@ -1,9 +1,9 @@
import sys, os
import vars_init
vars_init.init([])
import env_init
env_init.init([])
import state, vars
import state, env
from logs import err
@ -15,7 +15,7 @@ def main():
cwd = os.getcwd()
for f in state.files():
if f.is_source():
print state.relpath(os.path.join(vars.BASE, f.name), cwd)
print state.relpath(os.path.join(env.BASE, f.name), cwd)
if __name__ == '__main__':

View file

@ -1,5 +1,5 @@
import sys, os
import vars, state
import env, state
from logs import err, debug2
@ -32,11 +32,11 @@ def main():
csum = sh.hexdigest()
if not vars.TARGET:
if not env.TARGET:
sys.exit(0)
me = os.path.join(vars.STARTDIR,
os.path.join(vars.PWD, vars.TARGET))
me = os.path.join(env.STARTDIR,
os.path.join(env.PWD, env.TARGET))
f = state.File(name=me)
changed = (csum != f.csum)
debug2('%s: old = %s\n' % (f.name, f.csum))

View file

@ -1,9 +1,9 @@
import sys, os
import vars_init
vars_init.init([])
import env_init
env_init.init([])
import state, vars
import state, env
from logs import err
@ -15,7 +15,7 @@ def main():
cwd = os.getcwd()
for f in state.files():
if f.is_target():
print state.relpath(os.path.join(vars.BASE, f.name), cwd)
print state.relpath(os.path.join(env.BASE, f.name), cwd)
if __name__ == '__main__':

View file

@ -1,7 +1,7 @@
import sys, os
import vars_init
vars_init.init_no_state()
import env_init
env_init.init_no_state()
import paths
from logs import err

View file

@ -1,5 +1,5 @@
import os
import vars, state
import env, state
from logs import debug
CLEAN = 0
@ -16,7 +16,7 @@ def isdirty(f, depth, max_changed,
# is unaffected
already_checked = list(already_checked) + [f.id]
if vars.DEBUG >= 1:
if env.DEBUG >= 1:
debug('%s?%s %r,%r\n'
% (depth, f.nicename(), f.is_generated, f.is_override))
@ -28,10 +28,10 @@ def isdirty(f, depth, max_changed,
return DIRTY
if f.changed_runid > max_changed:
debug('%s-- DIRTY (built %d > %d; %d)\n'
% (depth, f.changed_runid, max_changed, vars.RUNID))
% (depth, f.changed_runid, max_changed, env.RUNID))
return DIRTY # has been built more recently than parent
if is_checked(f):
if vars.DEBUG >= 1:
if env.DEBUG >= 1:
debug('%s-- CLEAN (checked)\n' % depth)
return CLEAN # has already been checked during this session
if not f.stamp:
@ -65,7 +65,7 @@ def isdirty(f, depth, max_changed,
for mode, f2 in f.deps():
dirty = CLEAN
if mode == 'c':
if os.path.exists(os.path.join(vars.BASE, f2.name)):
if os.path.exists(os.path.join(env.BASE, f2.name)):
debug('%s-- DIRTY (created)\n' % depth)
dirty = DIRTY
elif mode == 'm':

View file

@ -76,7 +76,7 @@
import sys, os, errno, select, fcntl, signal
from atoi import atoi
from helpers import close_on_exec
import state, vars
import state, env
_toplevel = 0
_mytokens = 1
@ -343,7 +343,7 @@ def ensure_token_or_cheat(reason, cheatfunc):
if not has_token():
assert _mytokens == 0
n = cheatfunc()
_debug('%s: %s: cheat = %d\n' % (vars.TARGET, reason, n))
_debug('%s: %s: cheat = %d\n' % (env.TARGET, reason, n))
if n > 0:
_mytokens += n
_cheats += n

View file

@ -1,12 +1,12 @@
import os, re, sys, time
import vars
import env
RED = GREEN = YELLOW = BOLD = PLAIN = None
def check_tty(file, color):
def check_tty(tty, color):
global RED, GREEN, YELLOW, BOLD, PLAIN
color_ok = file.isatty() and (os.environ.get('TERM') or 'dumb') != 'dumb'
color_ok = tty.isatty() and (os.environ.get('TERM') or 'dumb') != 'dumb'
if (color and color_ok) or color >= 2:
# ...use ANSI formatting codes.
# pylint: disable=bad-whitespace
@ -24,8 +24,8 @@ def check_tty(file, color):
class RawLog(object):
def __init__(self, file):
self.file = file
def __init__(self, tty):
self.file = tty
def write(self, s):
assert '\n' not in s
@ -39,17 +39,17 @@ REDO_RE = re.compile(r'@@REDO:([^@]+)@@ (.*)$')
class PrettyLog(object):
def __init__(self, file):
def __init__(self, tty):
self.topdir = os.getcwd()
self.file = file
self.file = tty
def _pretty(self, pid, color, s):
if vars.DEBUG_PIDS:
if env.DEBUG_PIDS:
redo = '%-6d redo ' % pid
else:
redo = 'redo '
self.file.write(
''.join([color, redo, vars.DEPTH,
''.join([color, redo, env.DEPTH,
BOLD if color else '', s, PLAIN, '\n']))
def write(self, s):
@ -58,8 +58,8 @@ class PrettyLog(object):
sys.stderr.flush()
g = REDO_RE.match(s)
if g:
all = g.group(0)
self.file.write(s[:-len(all)])
capture = g.group(0)
self.file.write(s[:-len(capture)])
words = g.group(1).split(':')
text = g.group(2)
kind, pid, _ = words[0:3]
@ -75,17 +75,17 @@ class PrettyLog(object):
rv = int(rv)
if rv:
self._pretty(pid, RED, '%s (exit %d)' % (name, rv))
elif vars.VERBOSE or vars.XTRACE or vars.DEBUG:
elif env.VERBOSE or env.XTRACE or env.DEBUG:
self._pretty(pid, GREEN, '%s (done)' % name)
self.file.write('\n')
elif kind == 'locked':
if vars.DEBUG_LOCKS:
if env.DEBUG_LOCKS:
self._pretty(pid, GREEN, '%s (locked...)' % text)
elif kind == 'waiting':
if vars.DEBUG_LOCKS:
if env.DEBUG_LOCKS:
self._pretty(pid, GREEN, '%s (WAITING)' % text)
elif kind == 'unlocked':
if vars.DEBUG_LOCKS:
if env.DEBUG_LOCKS:
self._pretty(pid, GREEN, '%s (...unlocked!)' % text)
elif kind == 'error':
self.file.write(''.join([RED, 'redo: ',
@ -104,17 +104,17 @@ class PrettyLog(object):
_log = None
def setup(file, pretty, color):
def setup(tty, pretty, color):
global _log
if pretty or vars.PRETTY:
check_tty(file, color=color)
_log = PrettyLog(file=file)
if pretty or env.PRETTY:
check_tty(tty, color=color)
_log = PrettyLog(tty=tty)
else:
_log = RawLog(file=file)
_log = RawLog(tty=tty)
# FIXME: explicitly initialize in each program, for clarity
setup(file=sys.stderr, pretty=vars.PRETTY, color=vars.COLOR)
setup(tty=sys.stderr, pretty=env.PRETTY, color=env.COLOR)
def write(s):
@ -139,16 +139,16 @@ def warn(s):
meta('warning', s)
def debug(s):
if vars.DEBUG >= 1:
if env.DEBUG >= 1:
s = s.rstrip()
meta('debug', s)
def debug2(s):
if vars.DEBUG >= 2:
if env.DEBUG >= 2:
s = s.rstrip()
meta('debug', s)
def debug3(s):
if vars.DEBUG >= 3:
if env.DEBUG >= 3:
s = s.rstrip()
meta('debug', s)

View file

@ -1,5 +1,5 @@
import os
import vars
import env
from logs import debug2
@ -15,7 +15,7 @@ def _default_do_files(filename):
def possible_do_files(t):
dirname, filename = os.path.split(t)
yield (os.path.join(vars.BASE, dirname), "%s.do" % filename,
yield (os.path.join(env.BASE, dirname), "%s.do" % filename,
'', filename, '')
# It's important to try every possibility in a directory before resorting
@ -24,7 +24,7 @@ def possible_do_files(t):
# the former one might just be an artifact of someone embedding my project
# into theirs as a subdir. When they do, my rules should still be used
# for building my project in *all* cases.
t = os.path.normpath(os.path.join(vars.BASE, t))
t = os.path.normpath(os.path.join(env.BASE, t))
dirname, filename = os.path.split(t)
dirbits = dirname.split('/')
# since t is an absolute path, dirbits[0] is always '', so we don't

View file

@ -1,5 +1,5 @@
import sys, os, errno, stat, fcntl, sqlite3
import vars
import env
from helpers import unlink, close_on_exec, join
from logs import warn, debug2, debug3
@ -50,7 +50,7 @@ def db():
if _db:
return _db
dbdir = '%s/.redo' % vars.BASE
dbdir = '%s/.redo' % env.BASE
dbfile = '%s/db.sqlite3' % dbdir
try:
os.mkdir(dbdir)
@ -60,7 +60,7 @@ def db():
else:
raise
_lockfile = os.open(os.path.join(vars.BASE, '.redo/locks'),
_lockfile = os.open(os.path.join(env.BASE, '.redo/locks'),
os.O_RDWR | os.O_CREAT, 0666)
close_on_exec(_lockfile, True)
@ -110,11 +110,11 @@ def db():
_db.execute("insert into Runid values (1000000000)")
_db.execute("insert into Files (name) values (?)", [ALWAYS])
if not vars.RUNID:
if not env.RUNID:
_db.execute("insert into Runid values "
" ((select max(id)+1 from Runid))")
vars.RUNID = _db.execute("select last_insert_rowid()").fetchone()[0]
os.environ['REDO_RUNID'] = str(vars.RUNID)
env.RUNID = _db.execute("select last_insert_rowid()").fetchone()[0]
os.environ['REDO_RUNID'] = str(env.RUNID)
_db.commit()
return _db
@ -159,7 +159,7 @@ _insane = None
def check_sane():
global _insane
if not _insane:
_insane = not os.path.exists('%s/.redo' % vars.BASE)
_insane = not os.path.exists('%s/.redo' % env.BASE)
return not _insane
@ -183,18 +183,18 @@ def relpath(t, base):
return join('/', tparts)
# Return a path for t, if cwd were the dirname of vars.TARGET.
# Return a path for t, if cwd were the dirname of env.TARGET.
# This is tricky! STARTDIR+PWD is the directory for the *dofile*, when
# the dofile was started. However, inside the dofile, someone may have done
# a chdir to anywhere else. vars.TARGET is relative to the dofile path, so
# a chdir to anywhere else. env.TARGET is relative to the dofile path, so
# we have to first figure out where the dofile was, then find TARGET relative
# to that, then find t relative to that.
#
# FIXME: find some cleaner terminology for all these different paths.
def target_relpath(t):
dofile_dir = os.path.abspath(os.path.join(vars.STARTDIR, vars.PWD))
dofile_dir = os.path.abspath(os.path.join(env.STARTDIR, env.PWD))
target_dir = os.path.abspath(
os.path.dirname(os.path.join(dofile_dir, vars.TARGET)))
os.path.dirname(os.path.join(dofile_dir, env.TARGET)))
return relpath(t, target_dir)
@ -230,13 +230,13 @@ class File(object):
# These warnings are a result of the weird way this class is
# initialized, which we should fix, and then re-enable warning.
# pylint: disable=attribute-defined-outside-init
def _init_from_idname(self, id, name, allow_add):
def _init_from_idname(self, fid, name, allow_add):
q = ('select %s from Files ' % join(', ', _file_cols))
if id != None:
if fid != None:
q += 'where rowid=?'
l = [id]
l = [fid]
elif name != None:
name = (name == ALWAYS) and ALWAYS or relpath(name, vars.BASE)
name = (name == ALWAYS) and ALWAYS or relpath(name, env.BASE)
q += 'where name=?'
l = [name]
else:
@ -245,7 +245,7 @@ class File(object):
row = d.execute(q, l).fetchone()
if not row:
if not name:
raise KeyError('No file with id=%r name=%r' % (id, name))
raise KeyError('No file with id=%r name=%r' % (fid, name))
elif not allow_add:
raise KeyError('No file with name=%r' % (name,))
try:
@ -262,14 +262,14 @@ class File(object):
(self.id, self.name, self.is_generated, self.is_override,
self.checked_runid, self.changed_runid, self.failed_runid,
self.stamp, self.csum) = cols
if self.name == ALWAYS and self.changed_runid < vars.RUNID:
self.changed_runid = vars.RUNID
if self.name == ALWAYS and self.changed_runid < env.RUNID:
self.changed_runid = env.RUNID
def __init__(self, id=None, name=None, cols=None, allow_add=True):
def __init__(self, fid=None, name=None, cols=None, allow_add=True):
if cols:
self._init_from_cols(cols)
else:
self._init_from_idname(id, name, allow_add=allow_add)
self._init_from_idname(fid, name, allow_add=allow_add)
def __repr__(self):
return "File(%r)" % (self.nicename(),)
@ -288,7 +288,7 @@ class File(object):
self.id])
def set_checked(self):
self.checked_runid = vars.RUNID
self.checked_runid = env.RUNID
def set_checked_save(self):
self.set_checked()
@ -296,14 +296,14 @@ class File(object):
def set_changed(self):
debug2('BUILT: %r (%r)\n' % (self.name, self.stamp))
self.changed_runid = vars.RUNID
self.changed_runid = env.RUNID
self.failed_runid = None
self.is_override = False
def set_failed(self):
debug2('FAILED: %r\n' % self.name)
self.update_stamp()
self.failed_runid = vars.RUNID
self.failed_runid = env.RUNID
if self.stamp != STAMP_MISSING:
# if we failed and the target file still exists,
# then we're generated.
@ -362,13 +362,13 @@ class File(object):
return True
def is_checked(self):
return self.checked_runid and self.checked_runid >= vars.RUNID
return self.checked_runid and self.checked_runid >= env.RUNID
def is_changed(self):
return self.changed_runid and self.changed_runid >= vars.RUNID
return self.changed_runid and self.changed_runid >= env.RUNID
def is_failed(self):
return self.failed_runid and self.failed_runid >= vars.RUNID
return self.failed_runid and self.failed_runid >= env.RUNID
def deps(self):
if self.is_override or not self.is_generated:
@ -401,7 +401,7 @@ class File(object):
def _read_stamp_st(self, statfunc):
try:
st = statfunc(os.path.join(vars.BASE, self.name))
st = statfunc(os.path.join(env.BASE, self.name))
except OSError:
return False, STAMP_MISSING
if stat.S_ISDIR(st.st_mode):
@ -431,7 +431,7 @@ class File(object):
return pre
def nicename(self):
return relpath(os.path.join(vars.BASE, self.name), vars.STARTDIR)
return relpath(os.path.join(env.BASE, self.name), env.STARTDIR)
def files():
@ -442,7 +442,7 @@ def files():
def logname(fid):
"""Given the id of a File, return the filename of its build log."""
return os.path.join(vars.BASE, '.redo', 'log.%d' % fid)
return os.path.join(env.BASE, '.redo', 'log.%d' % fid)
# FIXME: I really want to use fcntl F_SETLK, F_SETLKW, etc here. But python
@ -466,7 +466,7 @@ class Lock(object):
def check(self):
assert not self.owned
if str(self.fid) in vars.get_locks():
if str(self.fid) in env.get_locks():
# Lock already held by parent: cyclic dependence
raise CyclicDependencyError()