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
|
import sys, os, errno, stat, signal, time
|
||||||
from . import cycles, env, jobserver, logs, state, paths
|
from . import cycles, env, jobserver, logs, state, paths
|
||||||
from .helpers import unlink, close_on_exec
|
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):
|
def _nice(t):
|
||||||
|
|
@ -52,7 +52,7 @@ def start_stdin_log_reader(status, details, pretty, color,
|
||||||
os.dup2(w, 1)
|
os.dup2(w, 1)
|
||||||
os.dup2(w, 2)
|
os.dup2(w, 2)
|
||||||
os.close(w)
|
os.close(w)
|
||||||
check_tty(sys.stderr, env.v.COLOR)
|
logs.setup(tty=sys.stderr, pretty=False, color=False)
|
||||||
else:
|
else:
|
||||||
# child
|
# child
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
import sys, os
|
import sys, os
|
||||||
from . import env, state
|
from . import env, logs, state
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
env.inherit()
|
env.inherit()
|
||||||
|
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||||
|
|
||||||
me = os.path.join(env.v.STARTDIR,
|
me = os.path.join(env.v.STARTDIR,
|
||||||
os.path.join(env.v.PWD, env.v.TARGET))
|
os.path.join(env.v.PWD, env.v.TARGET))
|
||||||
f = state.File(name=me)
|
f = state.File(name=me)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import os, sys, traceback
|
import os, sys, traceback
|
||||||
from . import env, state, builder, jobserver, deps
|
from . import env, builder, deps, jobserver, logs, state
|
||||||
from .logs import debug2, err
|
from .logs import debug2, err
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -24,6 +24,8 @@ def main():
|
||||||
builder.start_stdin_log_reader(
|
builder.start_stdin_log_reader(
|
||||||
status=True, details=True,
|
status=True, details=True,
|
||||||
pretty=True, color=True, debug_locks=False, debug_pids=False)
|
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:
|
if env.v.TARGET and not env.v.UNLOCKED:
|
||||||
me = os.path.join(env.v.STARTDIR,
|
me = os.path.join(env.v.STARTDIR,
|
||||||
os.path.join(env.v.PWD, env.v.TARGET))
|
os.path.join(env.v.PWD, env.v.TARGET))
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
import sys, os
|
import sys, os
|
||||||
from . import env, state
|
from . import env, logs, state
|
||||||
from .logs import err
|
from .logs import err
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
env.inherit()
|
env.inherit()
|
||||||
|
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||||
|
|
||||||
me = os.path.join(env.v.STARTDIR,
|
me = os.path.join(env.v.STARTDIR,
|
||||||
os.path.join(env.v.PWD, env.v.TARGET))
|
os.path.join(env.v.PWD, env.v.TARGET))
|
||||||
f = state.File(name=me)
|
f = state.File(name=me)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import sys, os
|
import sys, os
|
||||||
from . import env, state, deps
|
from . import deps, env, logs, state
|
||||||
from .logs import err
|
|
||||||
|
|
||||||
cache = {}
|
cache = {}
|
||||||
|
|
||||||
|
|
@ -19,10 +18,11 @@ def log_override(name):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv[1:]) != 0:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
state.init([])
|
state.init([])
|
||||||
|
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
for f in state.files():
|
for f in state.files():
|
||||||
if f.is_target():
|
if f.is_target():
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
import sys, os, traceback
|
import sys, os, traceback
|
||||||
from . import env, options, state, builder, jobserver
|
from . import builder, env, jobserver, logs, options, state
|
||||||
from .atoi import atoi
|
from .atoi import atoi
|
||||||
from .logs import warn, err
|
from .logs import warn, err
|
||||||
|
|
||||||
|
|
@ -86,6 +86,9 @@ def main():
|
||||||
status=opt.status, details=opt.details,
|
status=opt.status, details=opt.details,
|
||||||
pretty=opt.pretty, color=opt.color,
|
pretty=opt.pretty, color=opt.color,
|
||||||
debug_locks=opt.debug_locks, debug_pids=opt.debug_pids)
|
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:
|
for t in targets:
|
||||||
if os.path.exists(t):
|
if os.path.exists(t):
|
||||||
f = state.File(name=t)
|
f = state.File(name=t)
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
import sys, os
|
import sys, os
|
||||||
from . import state, env
|
from . import env, logs, state
|
||||||
from .logs import err
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
state.init([])
|
|
||||||
if len(sys.argv[1:]) != 0:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
|
state.init([])
|
||||||
|
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||||
|
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
for f in state.files():
|
for f in state.files():
|
||||||
if f.is_source():
|
if f.is_source():
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,21 @@
|
||||||
import sys, os
|
import sys, os
|
||||||
from . import env, state
|
from . import env, logs, state
|
||||||
from .logs import err, debug2
|
from .logs import debug2
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
env.inherit()
|
|
||||||
if len(sys.argv) > 1:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
if os.isatty(0):
|
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)
|
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'
|
# 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
|
# 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
|
# to support python 2.4 and above without any stupid warnings, so let's
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
import sys, os
|
import sys, os
|
||||||
from . import env, state
|
from . import env, logs, state
|
||||||
from .logs import err
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
state.init([])
|
|
||||||
if len(sys.argv[1:]) != 0:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
|
state.init([])
|
||||||
|
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||||
|
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
for f in state.files():
|
for f in state.files():
|
||||||
if f.is_target():
|
if f.is_target():
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
import sys, os
|
import sys, os
|
||||||
from . import env, state
|
from . import env, logs, state
|
||||||
from .logs import err
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
env.inherit()
|
|
||||||
if len(sys.argv[1:]) < 2:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
|
env.inherit()
|
||||||
|
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||||
|
|
||||||
target = sys.argv[1]
|
target = sys.argv[1]
|
||||||
deps = sys.argv[2:]
|
deps = sys.argv[2:]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
import sys, os
|
import sys, os
|
||||||
from . import env, paths
|
from . import env, logs, paths
|
||||||
from .logs import err
|
from .logs import err
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
env.init_no_state()
|
|
||||||
if len(sys.argv[1:]) != 1:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
|
env.init_no_state()
|
||||||
|
logs.setup(tty=sys.stderr, pretty=env.v.PRETTY, color=env.v.COLOR)
|
||||||
|
|
||||||
want = sys.argv[1]
|
want = sys.argv[1]
|
||||||
if not want:
|
if not want:
|
||||||
err('cannot build the empty target ("").\n')
|
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
|
RED = GREEN = YELLOW = BOLD = PLAIN = None
|
||||||
|
|
||||||
|
|
||||||
def check_tty(tty, color):
|
def _check_tty(tty, color):
|
||||||
global RED, GREEN, YELLOW, BOLD, PLAIN
|
global RED, GREEN, YELLOW, BOLD, PLAIN
|
||||||
color_ok = tty.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:
|
if (color and color_ok) or color >= 2:
|
||||||
|
|
@ -106,21 +106,14 @@ _log = None
|
||||||
|
|
||||||
def setup(tty, pretty, color):
|
def setup(tty, pretty, color):
|
||||||
global _log
|
global _log
|
||||||
if pretty or env.v.PRETTY:
|
if pretty:
|
||||||
check_tty(tty, color=color)
|
_check_tty(tty, color=color)
|
||||||
_log = PrettyLog(tty=tty)
|
_log = PrettyLog(tty=tty)
|
||||||
else:
|
else:
|
||||||
_log = RawLog(tty=tty)
|
_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):
|
def write(s):
|
||||||
_maybe_setup()
|
|
||||||
_log.write(s)
|
_log.write(s)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue