diff options
| author | Sebastian Kuhnert | 2008-08-21 10:41:57 +0000 |
|---|---|---|
| committer | Sebastian Kuhnert | 2008-08-21 10:41:57 +0000 |
| commit | 6f15ced1c19e5e100624f3852113ed0e539d43ae (patch) | |
| tree | 3526e245bffb7af3361915e93d4ea74927d7f4b9 | |
| parent | cc2c1ffbfbf7608b6eab95ce57833458fb11a6ec (diff) | |
| download | exercisesheets-6f15ced1c19e5e100624f3852113ed0e539d43ae.tar.gz exercisesheets-6f15ced1c19e5e100624f3852113ed0e539d43ae.tar.bz2 exercisesheets-6f15ced1c19e5e100624f3852113ed0e539d43ae.zip | |
texall script: use rmligs if available
| -rwxr-xr-x | texall | 128 |
1 files changed, 118 insertions, 10 deletions
@@ -14,6 +14,9 @@ parser.add_option("-n", "--dry-run", parser.add_option("-f", "--force", action="store_true", dest="force", default=False, help="regenerate up-to-date files") +parser.add_option("-R", "--non-recursive", + action="store_false", dest="recurse", default=True, + help="disable recursion into subdirectories") parser.add_option("-s", "--summary", dest="summary", help="summarise failures and processed files at the end of the run (one of failures (default), files, both, no)", choices=("no","files","failures","both"), default="failures") @@ -29,6 +32,9 @@ parser.add_option("-i", "--ignore", parser.add_option("-p", "--required-pattern", action="store", dest="requiredpattern", default='^\\\\documentclass|%%% TeX-master: t', help="regular expression that must match the file content") +parser.add_option("-T", "--preserve-tempfiles", + action="store_false", dest="deletetempfiles", default=True, + help="preserve temporary files (default: delete)") (options, args) = parser.parse_args() interactionmode = "batchmode" @@ -53,16 +59,40 @@ def error(file, desc, warning=False): print msg errors.append(msg) +path = os.path.expandvars("$PATH") +if path == "$PATH": + path = os.path.defpath +path = path.split(os.path.pathsep) +def isinpath(name): + for p in path: + if os.path.isfile(os.path.join(p, name)): + return True + return False + + +if isinpath("rmligs"): + rmligs_name = "rmligs" +elif isinpath("rmligs-german"): + rmligs_name = "rmligs-german" +else: + rmligs_name = "" + error("rmligs", "Command not found. Please install rmligs (or rmligs-german) for optimal results", warning=True) + # iterate over all .tex files that are not ignored by -i or -p def alltexfiles(args): for a in args: if os.path.isfile(a): if re_texfile.match(a): - yield os.path.split(a) + (dirname, filename) = os.path.split(a) + if dirname == "": + dirname = "." + yield (dirname, filename) else: error(a, "is no tex file; skipped") elif os.path.isdir(a): for dir, subdirs, files in os.walk(a): + if not options.recurse: + subdirs[:] = [] for name in files: if re_texfile.match(name): if re_ignore.match(name): @@ -93,6 +123,20 @@ def texgrep(matcher, dirname, filename, recurse=False): else: f.close() +kpsepaths={} +def texpath(dirname,filename,pathtype="tex",progname="latex",extlist=[],allowsystemfiles=False): + if not kpsepaths.has_key((pathtype,progname)): + kpse=subprocess.Popen(["kpsepath", "-n", progname, pathtype], stdout=subprocess.PIPE) + (out,err)=kpse.communicate() + if kpse.wait() != 0: + error("kpsepath", "failed to get paths for %s"%pathtype) + kpsepaths[(pathtype,progname)] = out[:-1].split(":") + if os.path.isfile(os.path.join(dirname,filename)): + return os.path.join(dirname,filename) + for ext in extlist: + if os.path.isfile(os.path.join(dirname,filename+ext)): + return os.path.join(dirname,filename+ext) + RECURSIONDEPTH=10 re_inputinclude = re.compile('\\\\(input|include|@input)\\{([^}]*)\\}') re_usepackage = re.compile('\\\\usepackage(\\[.*?\\])?\\{([^}]*)\\}') @@ -176,6 +220,9 @@ def outdatedtexfiles(args): yield (dirname, texname, reason) else: for f in dependencies(dirname, texname): + if not os.path.isfile(f): + error(os.path.join(dirname,texname), "dependency not found: %s"%f, warning=True) + continue if pdftime < os.path.getmtime(f): if options.verbosity: reason = " (because %s is newer than .pdf)"%f @@ -199,22 +246,34 @@ def detecttextype(dirname, texname): return "latex" return "pdflatex" +re_rmligs = re.compile('\\\usepackage((\\[.*?\\])?\\{n?german\\}|\\[[^]]*?german[^]]*?\\]\\{babel\\})') +def detectrmligs(dirname, texname): + for m in texgrep(re_rmligs, dirname, texname, recurse=True): + return True + return False + MAXRUNS=5 def processtexfiles(args): for dirname, texname, reason in outdatedtexfiles(args): procfiles.append(os.path.normpath(os.path.join(dirname,texname))) if options.progress: print "processing %s%s..."%(os.path.normpath(os.path.join(dirname,texname)),reason) - # TODO: add support for pstricks/plain latex + + # support for pstricks/plain latex: tex = detecttextype(dirname, texname) - run([tex, "-interaction", interactionmode, texname], dirname) + + # detect usage of german/ngerman + rmligs = detectrmligs(dirname, texname) + + runtex(tex, texname, dirname, rmligs) + #strip .tex extension jobname=texname[:-4] # run bibtex if any bibfile changed: for bib in bibfiles(dirname, texname): bbl = os.path.normpath(os.path.join(dirname, jobname+".bbl")) - if options.force or not os.path.isfile(bbl) or os.path.getmtime(bbl) < os.path.getmtime(bib): + if options.force or not os.path.isfile(bbl) or os.path.getmtime(bbl) < os.path.getmtime(bib): reason = "" if options.verbosity: if not os.path.isfile(bbl): @@ -224,7 +283,7 @@ def processtexfiles(args): else: reason = " (because of --force)" run(["bibtex8", "--wolfgang", jobname], dirname, reason=reason) - run([tex, "-interaction", interactionmode, texname], dirname, reason=" (because of updated .bbl)") + runtex(tex, texname, dirname, rmligs, reason=" (because of updated .bbl)") break # check for undefined references and run requests @@ -242,7 +301,7 @@ def processtexfiles(args): if options.verbosity: reason = " (because of request in .aux file, priority %d)"%rp if req == "latex": - run([tex, "-interaction", interactionmode, texname], dirname, reason=reason) + runtex(tex, texname, dirname, rmligs, reason=reason) elif req == "bibtex": run(["bibtex8", "--wolfgang", jobname], dirname, reason=reason) else: @@ -256,12 +315,14 @@ def processtexfiles(args): idx = jobname + ".idx" if os.path.isfile(os.path.join(dirname, idx)): run(["makeindex", jobname], dirname, reason=" (because .idx file might have changed)") - run([tex, "-interaction", interactionmode, texname], dirname, reason=" (because .ind file might have changed)") + runtex(tex, texname, dirname, rmligs, reason=" (because .ind file might have changed)") if tex == "latex": run(["dvips", jobname+".dvi"], dirname) run(["ps2pdf", jobname+".ps"], dirname) + rmtempfile(jobname+"-rmligs.tex", dirname) + re_logmatcher = re.compile("^LaTeX Warning: There were undefined references\.$|^LaTeX Warning: Label\(s\) may have changed\. Rerun to get cross-references right\.$|^REQ:(\d+):(\w+):") def requests(logpath): reqs = {} @@ -306,19 +367,66 @@ def haderrors(dirname, jobname): f.close() return False -def run(arglist, dirname, reason=""): +def rmtempfile(filename, dirname): + fullname = os.path.join(dirname, filename) + if options.deletetempfiles and os.path.isfile(fullname): + if options.progress: + print " removing %s"%filename + os.remove(fullname) + +def run(arglist, dirname, reason="", infile=None, outfile=None): if options.verbosity>2: # use default output=None else: output=file("/dev/null") + if infile: + try: + stdin=open(os.path.join(dirname, infile), "r") + indesc=" < %s"%infile + except IOError, (errno, strerror): + if output: + output.close() + error(infile, "input file could not be read: %s"%strerror) + return + else: + stdin=None + indesc="" + if outfile: + try: + stdout=open(os.path.join(dirname, outfile), "w") + outdesc=" > %s"%outfile + except IOError, (errno, strerror): + if output: + output.close() + if stdin: + stdin.close() + error(outfile, "output file could not be read: %s"%strerror) + return + else: + stdout=output + outdesc="" if options.progress: - print " running %s%s..."%(" ".join(arglist),reason) + print " running %s%s%s%s..."%(" ".join(arglist), indesc, outdesc,reason) if options.act: - ret = subprocess.call(arglist, stdout=output, stderr=output, cwd=dirname) + ret = subprocess.call(arglist, stdin=stdin, stdout=stdout, stderr=output, cwd=dirname) if ret: error(dirname, "failed command: %s"%(" ".join(arglist))) + if output: + output.close() + if stdin: + stdin.close() + if stdout and stdout is not output: + stdout.close() +def runtex(tex, texname, dirname, rmligs=False, reason=""): + if rmligs and rmligs_name != "": + jobname=texname[:-4] + rmligsname=jobname+"-rmligs.tex" + run([rmligs_name, "-f"], dirname, infile=texname, outfile=rmligsname, reason=reason) + run([tex, "-interaction", interactionmode, "-jobname", jobname, rmligsname], dirname, reason) + else: + run([tex, "-interaction", interactionmode, texname], dirname, reason) # main program: try: |
