diff options
| author | Sebastian Kuhnert | 2008-08-25 17:24:32 +0000 |
|---|---|---|
| committer | Sebastian Kuhnert | 2008-08-25 17:24:32 +0000 |
| commit | 375c3c020e9357160b94aae78723adb2485aaf81 (patch) | |
| tree | 9395ed3e816dadfc6503d70f168f39c03bc62614 /texall | |
| parent | 37b5728aca04d2aa94f285ce9a25aff7c2308cd4 (diff) | |
| download | exercisesheets-375c3c020e9357160b94aae78723adb2485aaf81.tar.gz exercisesheets-375c3c020e9357160b94aae78723adb2485aaf81.tar.bz2 exercisesheets-375c3c020e9357160b94aae78723adb2485aaf81.zip | |
texall script: show name of input files for piped commands
Diffstat (limited to 'texall')
| -rwxr-xr-x | texall | 51 |
1 files changed, 48 insertions, 3 deletions
@@ -78,7 +78,48 @@ if os.path.exists("/dev/null"): null = file("/dev/null", "wb") else: null = file("nul:", "wb") + +# platform checking: +iswindows = (sys.platform == "win32") + +# provide a copy of os.path.relpath from python 2.6 +if not iswindows: + def relpath(path, start=os.path.curdir): + """Return a relative version of a path""" + + start_list = os.path.abspath(start).split(os.path.sep) + path_list = os.path.abspath(path).split(os.path.sep) + # Work out how much of the filepath is shared by start and path. + i = len(os.path.commonprefix([start_list, path_list])) + + rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:] + return os.path.join(*rel_list) +else: + def relpath(path, start=os.path.curdir): + """Return a relative version of a path""" + + start_list = os.path.abspath(start).split(os.path.sep) + path_list = os.path.abspath(path).split(os.path.sep) + if start_list[0].lower() != path_list[0].lower(): + unc_path, rest = os.path.splitunc(path) + unc_start, rest = os.path.splitunc(start) + if bool(unc_path) ^ bool(unc_start): + raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)" + % (path, start)) + else: + raise ValueError("path is on drive %s, start on drive %s" + % (path_list[0], start_list[0])) + # Work out how much of the filepath is shared by start and path. + for i in range(min(len(start_list), len(path_list))): + if start_list[i].lower() != path_list[i].lower(): + break + else: + i += 1 + + rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:] + return os.path.join(*rel_list) + path = os.path.expandvars("$PATH") if path == "$PATH": path = os.path.defpath @@ -426,7 +467,11 @@ def run(arglist, dirname, reason="", inf=None, outf=None, stderr=None): stderr -- file to be used as stderr """ if options.verbosity: - print " running %s%s..."%(" ".join(arglist), reason) + redir ="" + if hasattr(inf, "name") and inf.name != "" and inf.name[0] != "<": + name = relpath(inf.name, dirname) + redir = " < %s"%name + print " running %s%s%s..."%(" ".join(arglist), redir, reason) if options.act: master, slave = None, None @@ -434,7 +479,7 @@ def run(arglist, dirname, reason="", inf=None, outf=None, stderr=None): if isinstance(inf, file): stdin = inf inf = None - elif options.showoutput and not subprocess.mswindows: + elif options.showoutput and not iswindows: master, slave = pty.openpty() master = os.fdopen(master, "rw") stdin=slave @@ -446,7 +491,7 @@ def run(arglist, dirname, reason="", inf=None, outf=None, stderr=None): if isinstance(outf, file): stdout = outf outf = None - elif options.showoutput and not subprocess.mswindows: + elif options.showoutput and not iswindows: if slave == None: master, slave = pty.openpty() master = os.fdopen(master, "rw") |
