redo-whichdo: a command that explains the .do search path for a target.
For example: $ redo-whichdo a/b/c/.x.y - a/b/c.x.y.do - a/b/default.x.y.do - a/b/default.y.do - a/b/default.do - a/default.x.y.do - a/default.y.do - a/default.do - default.x.y.do - default.y.do + default.do 1 a/b/c.x.y 2 a/b/c.x.y Lines starting with '-' mean a potential .do file that did not exist, so we moved onto the next choice (but consider using redo-ifcreate in case it gets created). '+' means the .do file we actually chose. '1' and '2' are the $1 and $2 to pass along to the given .do file if you want to call it for the given target. (The output format is a little weird to make sure it's parseable with sh 'read x y' calls, even when filenames contain spaces or special characters.)
This commit is contained in:
parent
484ed925ad
commit
61d35d3972
3 changed files with 34 additions and 4 deletions
29
redo-whichdo.py
Executable file
29
redo-whichdo.py
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env python
|
||||
import sys, os
|
||||
|
||||
import vars_init
|
||||
vars_init.init([])
|
||||
|
||||
import builder
|
||||
from log import err
|
||||
|
||||
if len(sys.argv[1:]) != 1:
|
||||
err('%s: exactly one argument expected.\n' % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
want = sys.argv[1]
|
||||
for dodir,dofile,basedir,basename,ext in builder.possible_do_files(os.path.abspath(want)):
|
||||
dopath = os.path.join('/', dodir, dofile)
|
||||
relpath = os.path.relpath(dopath, '.')
|
||||
exists = os.path.exists(dopath)
|
||||
assert('\n' not in relpath)
|
||||
if exists:
|
||||
print '+', relpath
|
||||
assert('\n' not in basename)
|
||||
assert('\n' not in ext)
|
||||
print '1', basename+ext
|
||||
print '2', basename
|
||||
sys.exit(0)
|
||||
else:
|
||||
print '-', relpath
|
||||
sys.exit(1) # no appropriate dofile found
|
||||
Loading…
Add table
Add a link
Reference in a new issue