def filterx10dir(srcdir, tgtdir, verbose=True): """ filters x10 source files found in the directory whose absolute path is srcdir and all of that directories subtree. The output is written to corresponding directories under the directory whose absolute path is tgtdir. tgtdir and all subdirectories will be created as need be. We assume srcdir is NOT the same as tgtdir: indeed we insist that tgtdir not be in srcdir's directory tree at all! """ if verbose: print("x10 output directory: '" + tgtdir + "'") if osutils.isinsubdir(srcdir, tgtdir): raise Exception(tgtdir+" is a subdirectory of "+srcdir) x10srclength = len(srcdir) if not srcdir.endswith(osutils.FILE_SEPARATOR): x10srclength += 1 _warnings.clear() for nextdir, dirs, files in os.walk(srcdir): if osutils.isdotfirst(nextdir): continue; if verbose: print("x10 source directory: '" + nextdir + "'") nexttgt = join(tgtdir, nextdir[x10srclength:]) if not os.path.isdir(nexttgt): if verbose: print("...had to create " + nexttgt) os.path.mkdir(nexttgt) for file in files: if file.endswith(".x10"): if verbose: print("\t" + file) filterx10(join(nextdir, file), join(nexttgt, file), verbose)
def rewriteAllFilesIn(self, dirpath): for subdirpath, dirnames, filenames in os.walk(dirpath): # Skip dotted directories. if osutils.isdotfirst(subdirpath): continue for filename in filenames: if filename.endswith(".tex"): self.rewrite(os.path.join(subdirpath, filename))
def scanAllFilesIn(self, dirpath): for subdirpath, dirnames, filenames in os.walk(dirpath): # Skip dotted directories. if osutils.isdotfirst(subdirpath): continue for filename in filenames: if filename.endswith(".x10"): self.scanFile(subdirpath + "/" + filename)
def trimmify(self, here, there): global verbose for subhere, subdirsHere, filesHere in os.walk(here): if osutils.isdotfirst(subhere): continue relPathFromHere = os.path.relpath(subhere, here) for fileHere in filesHere: sourcePathToHere = os.path.join(here, subhere, fileHere) targetPathToThere = os.path.join(there, relPathFromHere, fileHere) if verbose: print("trimming " + fileHere+ " -> " + targetPathToThere) self.trimFile(sourcePathToHere, targetPathToThere)
def trimmify(self, here, there): global verbose for subhere, subdirsHere, filesHere in os.walk(here): if osutils.isdotfirst(subhere): continue relPathFromHere = os.path.relpath(subhere, here) for fileHere in filesHere: sourcePathToHere = os.path.join(here, subhere, fileHere) targetPathToThere = os.path.join(there, relPathFromHere, fileHere) if verbose: print("trimming " + fileHere + " -> " + targetPathToThere) self.trimFile(sourcePathToHere, targetPathToThere)
def importx10totexdir(texdir, backupdir, x10root, verbose=True): """ import the x10 code fragments requested by the .tex files in the directory tree whose root's absolute path is texdir. If the import is successful, the source file is updated and the original source is saved in the directory whose absolute path is backupdir. The saved original has a timestamp added to its file name for uniqueness. """ _warnings.clear() for srcdir, dirs, files in os.walk(texdir): if verbose: print("source directory: " + srcdir+" backup "+backupdir) if osutils.isdotfirst(srcdir): # skip "hidden" directories continue; for file in files: if file.endswith(".tex"): texin = join(srcdir, file) if verbose: print("\tProcessing " + texin) texout = texin+".cow" importx10totex(texin, texout, x10root, verbose) timestamp = osutils.timestamp()[2:-2] backup = os.path.join(backupdir, file[:-3] + timestamp + ".tex") rc = subprocess.call(["cp", texin, backup]) if rc == 0: rc = subprocess.call(["rm", texin]) if rc == 0: rc = subprocess.call(["mv", texout, texin]) if rc != 0: raise Exception("mv " + texout + " " + texin + " failed: rc = "+str(rc)) else: raise Exception("rm " + texit + " failed: rc =" + str(rc)) else: raise Exception("cp " + texin + " " + backup + " failed: rc=" + str(rc))