def check(f, lines): if f.fileType != "tex": return None if tools.isGnuplotLatexFile(lines): return None dependencies = [] starts = [] target = f.fname for l in lines: if "\\includegraphics" in l and "{" in l and "}" in l: filename = tools.charactersBetween(l, "{", "}") if fileUtils.getFileType(filename) is None or fileUtils.getFileType(filename) == "": possibleExtensions = [".png", ".bmp", ".gif", ".jpg", ".pdf"] possibleExtensions = possibleExtensions + [x.upper() for x in possibleExtensions] found = False for fileEnding in possibleExtensions: if os.path.isfile(filename + fileEnding): logging.info("Found a file named " + filename + fileEnding + ", will assume that this file is meant by") logging.info(l.replace("\n", "")) filename = filename + fileEnding found = True break if not found: logging.info("Didn't find a file with this name, ignoring this dependency:" + str(l.replace("\n", ""))) continue starts.append(filename) if len(starts) == 0: return None return Dependency(starts = starts, targets = target, runCommandOnStartFile = False, printOutput = False)
def check(f, lines): if f.fileType != "tex": return None if tools.isGnuplotLatexFile(lines): return None dependencies = [] starts = [] target = f.fname for l in lines: if "subimport" in l: path = tools.charactersBetween(l, "{", "}") fname = tools.charactersBetween(l, "{", "}", l.find(path)) filename = path + fname starts.append(filename + ".tex") if len(starts) == 0: return None return Dependency(starts = starts, targets = target, runCommandOnStartFile = False, printOutput = False)
def check(f, lines): if f.fileType != "gpi": return None dependencies = [] start = f.fname targets = [] for l in lines: if "set output" in l: if l.count("\"") == 2: targets.append(tools.charactersBetween(l, "\"", "\"")) elif l.count("\'") == 2: targets.append(tools.charactersBetween(l, "\'", "\'")) else: # This occurs with lines like 'set output pic'.x.'.gpi' which sets outputfiles dynamically (should happen very rarely). Just ignore it continue if len(targets) == 0: return None return Dependency(starts = start, targets = targets, command = "gnuplot", printOutput = True)
def check(f, lines): if f.fileType != "gpi": return None dependencies = [] starts = [] target = f.fname for l in lines: if "load" in l: if l.count("\"") == 2: starts.append(tools.charactersBetween(l, "\"", "\"")) elif l.count("\'") == 2: starts.append(tools.charactersBetween(l, "\'", "\'")) else: # This occurs with lines like 'load template'.x.'.gpi' which load files dynamically (should happen very rarely). Just ignore it continue if len(starts) == 0: return None return Dependency(starts = starts, targets = target, runCommandOnStartFile = False, printOutput = False)
def check(f, lines): if f.fileType != "tex": return None if tools.isGnuplotLatexFile(lines): return None dependencies = [] starts = [] target = f.fname for l in lines: if "\\input" in l: filename = tools.charactersBetween(l, "{", "}") starts.append(filename + ".tex") if len(starts) == 0: return None return Dependency(starts = starts, targets = target, runInStartFolder = False, printOutput = False)
def check(f, lines): if f.fileType != "py": return None dependencies = [] starts = [] target = f.fname for l in lines: if "import" in l: start = None if "from" in l: start = tools.charactersBetween(l, " ", " ") else: start = l[l.index(" ")+1:] starts = start.split(",") starts = [start.strip() + ".py" for start in starts] print(starts) # start = start.replace(".", "/") # Python uses . to denote submodules which are folders # start = start.replace("\n", "") # start = start + ".py" if len(starts) == 0: return None return Dependency(starts = starts, targets = target, command = "python3", runCommandOnStartFile = False)
def testCharactersBetweenStartIndex(): s = "----A-randomstring-" assert(tools.charactersBetween(s, "-", "-", s.index("A")) == "randomstring")
def testCharactersBetweenOnTheSameCharacterTwice(): assert(tools.charactersBetween("-randomstring-", "-", "-") == "randomstring")
def testCharactersBetweenReturnsNoneIfEndStringNotFound(): assert(tools.charactersBetween("Xabcdef", "X", "Y") == None)
def testCharactersBetweenReturnsNoneIfStartStringNotFound(): assert(tools.charactersBetween("abcdefY", "X", "Y") == None)
def testCharactersBetweenAppearancesOfEndStringBeforeStartString(): assert(tools.charactersBetween("YYYYYYXrandomstringY", "X", "Y") == "randomstring")
def getStatementTarget(statement): # for statements like "import java.util.Vector;" or "package main" # return "java.util.Vector" or "main" respectively. return tools.charactersBetween(statement, " ", ";").strip()