apenwarr-redo/redo/cmd_whichdo.py
Avery Pennarun 9b6d1eeb6e env and env_init: Eliminate weird auto-initialization of globals.
Merge the two files into env, and make each command explicitly call the
function that sets it up in the way that's needed for that command.

This means we can finally just import all the modules at the top of
each file, without worrying about import order.  Phew.

While we're here, remove the weird auto-appending-'all'-to-targets
feature in env.init().  Instead, do it explicitly, and only from redo and
redo-ifchange, only if is_toplevel and no other targets are given.
2018-12-05 02:27:04 -05:00

31 lines
784 B
Python

import sys, os
import env, 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.exit(1)
want = sys.argv[1]
if not want:
err('cannot build the empty target ("").\n')
sys.exit(204)
abswant = os.path.abspath(want)
pdf = paths.possible_do_files(abswant)
for dodir, dofile, basedir, basename, ext in pdf:
dopath = os.path.join('/', dodir, dofile)
relpath = os.path.relpath(dopath, '.')
exists = os.path.exists(dopath)
assert '\n' not in relpath
print relpath
if exists:
sys.exit(0)
sys.exit(1) # no appropriate dofile found
if __name__ == '__main__':
main()