Make calls to logs.setup() explicit in each cmd.
Further reducing magic implicit behaviour to make code easier to follow.
This commit is contained in:
parent
474e12eed8
commit
4d2b4cfccb
12 changed files with 49 additions and 39 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import sys, os, errno, stat, signal, time
|
||||
from . import cycles, env, jobserver, logs, state, paths
|
||||
from .helpers import unlink, close_on_exec
|
||||
from .logs import debug2, err, warn, meta, check_tty
|
||||
from .logs import debug2, err, warn, meta
|
||||
|
||||
|
||||
def _nice(t):
|
||||
|
|
@ -52,7 +52,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, env.v.COLOR)
|
||||
logs.setup(tty=sys.stderr, pretty=False, color=False)
|
||||
else:
|
||||
# child
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import sys, os
|
||||
from . import env, state
|
||||
from . import env, logs, state
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
env.inherit()
|
||||
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||
|
||||
me = os.path.join(env.v.STARTDIR,
|
||||
os.path.join(env.v.PWD, env.v.TARGET))
|
||||
f = state.File(name=me)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import os, sys, traceback
|
||||
from . import env, state, builder, jobserver, deps
|
||||
from . import env, builder, deps, jobserver, logs, state
|
||||
from .logs import debug2, err
|
||||
|
||||
|
||||
|
|
@ -24,6 +24,8 @@ def main():
|
|||
builder.start_stdin_log_reader(
|
||||
status=True, details=True,
|
||||
pretty=True, color=True, debug_locks=False, debug_pids=False)
|
||||
else:
|
||||
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||
if env.v.TARGET and not env.v.UNLOCKED:
|
||||
me = os.path.join(env.v.STARTDIR,
|
||||
os.path.join(env.v.PWD, env.v.TARGET))
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
import sys, os
|
||||
from . import env, state
|
||||
from . import env, logs, state
|
||||
from .logs import err
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
env.inherit()
|
||||
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||
|
||||
me = os.path.join(env.v.STARTDIR,
|
||||
os.path.join(env.v.PWD, env.v.TARGET))
|
||||
f = state.File(name=me)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import sys, os
|
||||
from . import env, state, deps
|
||||
from .logs import err
|
||||
from . import deps, env, logs, state
|
||||
|
||||
cache = {}
|
||||
|
||||
|
|
@ -19,10 +18,11 @@ def log_override(name):
|
|||
|
||||
def main():
|
||||
if len(sys.argv[1:]) != 0:
|
||||
err('%s: no arguments expected.\n' % sys.argv[0])
|
||||
sys.stderr.write('%s: no arguments expected.\n' % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
state.init([])
|
||||
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||
cwd = os.getcwd()
|
||||
for f in state.files():
|
||||
if f.is_target():
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
import sys, os, traceback
|
||||
from . import env, options, state, builder, jobserver
|
||||
from . import builder, env, jobserver, logs, options, state
|
||||
from .atoi import atoi
|
||||
from .logs import warn, err
|
||||
|
||||
|
|
@ -86,6 +86,9 @@ def main():
|
|||
status=opt.status, details=opt.details,
|
||||
pretty=opt.pretty, color=opt.color,
|
||||
debug_locks=opt.debug_locks, debug_pids=opt.debug_pids)
|
||||
else:
|
||||
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||
|
||||
for t in targets:
|
||||
if os.path.exists(t):
|
||||
f = state.File(name=t)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
import sys, os
|
||||
from . import state, env
|
||||
from .logs import err
|
||||
from . import env, logs, state
|
||||
|
||||
|
||||
def main():
|
||||
state.init([])
|
||||
if len(sys.argv[1:]) != 0:
|
||||
err('%s: no arguments expected.\n' % sys.argv[0])
|
||||
sys.stderr.write('%s: no arguments expected.\n' % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
state.init([])
|
||||
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||
|
||||
cwd = os.getcwd()
|
||||
for f in state.files():
|
||||
if f.is_source():
|
||||
|
|
|
|||
|
|
@ -1,18 +1,21 @@
|
|||
import sys, os
|
||||
from . import env, state
|
||||
from .logs import err, debug2
|
||||
from . import env, logs, state
|
||||
from .logs import debug2
|
||||
|
||||
|
||||
def main():
|
||||
env.inherit()
|
||||
if len(sys.argv) > 1:
|
||||
err('%s: no arguments expected.\n' % sys.argv[0])
|
||||
sys.stderr.write('%s: no arguments expected.\n' % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
if os.isatty(0):
|
||||
err('%s: you must provide the data to stamp on stdin\n' % sys.argv[0])
|
||||
sys.stderr.write('%s: you must provide the data to stamp on stdin\n'
|
||||
% sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
env.inherit()
|
||||
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||
|
||||
# hashlib is only available in python 2.5 or higher, but the 'sha'
|
||||
# module produces a DeprecationWarning in python 2.6 or higher. We want
|
||||
# to support python 2.4 and above without any stupid warnings, so let's
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
import sys, os
|
||||
from . import env, state
|
||||
from .logs import err
|
||||
from . import env, logs, state
|
||||
|
||||
|
||||
def main():
|
||||
state.init([])
|
||||
if len(sys.argv[1:]) != 0:
|
||||
err('%s: no arguments expected.\n' % sys.argv[0])
|
||||
sys.stderr.write('%s: no arguments expected.\n' % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
state.init([])
|
||||
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||
|
||||
cwd = os.getcwd()
|
||||
for f in state.files():
|
||||
if f.is_target():
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
import sys, os
|
||||
from . import env, state
|
||||
from .logs import err
|
||||
from . import env, logs, state
|
||||
|
||||
|
||||
def main():
|
||||
env.inherit()
|
||||
if len(sys.argv[1:]) < 2:
|
||||
err('%s: at least 2 arguments expected.\n' % sys.argv[0])
|
||||
sys.stderr.write('%s: at least 2 arguments expected.\n' % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
env.inherit()
|
||||
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||
|
||||
target = sys.argv[1]
|
||||
deps = sys.argv[2:]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
import sys, os
|
||||
from . import env, paths
|
||||
from . import env, logs, paths
|
||||
from .logs import err
|
||||
|
||||
|
||||
def main():
|
||||
env.init_no_state()
|
||||
if len(sys.argv[1:]) != 1:
|
||||
err('%s: exactly one argument expected.\n' % sys.argv[0])
|
||||
sys.stderr.write('%s: exactly one argument expected.\n' % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
env.init_no_state()
|
||||
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||
|
||||
want = sys.argv[1]
|
||||
if not want:
|
||||
err('cannot build the empty target ("").\n')
|
||||
|
|
|
|||
13
redo/logs.py
13
redo/logs.py
|
|
@ -4,7 +4,7 @@ from . import env
|
|||
RED = GREEN = YELLOW = BOLD = PLAIN = None
|
||||
|
||||
|
||||
def check_tty(tty, color):
|
||||
def _check_tty(tty, color):
|
||||
global RED, GREEN, YELLOW, BOLD, PLAIN
|
||||
color_ok = tty.isatty() and (os.environ.get('TERM') or 'dumb') != 'dumb'
|
||||
if (color and color_ok) or color >= 2:
|
||||
|
|
@ -106,21 +106,14 @@ _log = None
|
|||
|
||||
def setup(tty, pretty, color):
|
||||
global _log
|
||||
if pretty or env.v.PRETTY:
|
||||
check_tty(tty, color=color)
|
||||
if pretty:
|
||||
_check_tty(tty, color=color)
|
||||
_log = PrettyLog(tty=tty)
|
||||
else:
|
||||
_log = RawLog(tty=tty)
|
||||
|
||||
|
||||
def _maybe_setup():
|
||||
# FIXME: explicitly initialize in each program, for clarity
|
||||
if not _log:
|
||||
setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||
|
||||
|
||||
def write(s):
|
||||
_maybe_setup()
|
||||
_log.write(s)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue