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:
parent
65cf1c9854
commit
ded14507b0
19 changed files with 142 additions and 142 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue