from depend import Depend class DependReport: def report(self, tree, indentlevel=0): text = "%s%s directly included lines(%d), all included lines(%d)\n" % (" "*indentlevel, tree.name(), tree.lines(), tree.totalLines()) for child in tree.children(): text += self.report(child, indentlevel+1) return text def reportStats(self, stats): report = "" files = stats.files() files.sort(key=lambda k:k.compiledLines()) for file in files: report += "%s lines in file(%d), all included lines(%d), places included from(%d)\n" % (file.file(), file.fileLines(), file.compiledLines(), file.includedFrom()) return report if __name__ == "__main__": import sys file = sys.argv[1] lines = open(file).readlines() depend = Depend() tree = depend.getTree(lines) reporter = DependReport() print reporter.report(tree)
logger.info("adding depend %s on %s" % (self, on_layer)) # # Handle the depend any bullshit # if any_frame or depend_type == DependType.LayerOnAny: if isinstance(self, (LayerPreProcess, )): depend_type = DependType.LayerOnLayer else: depend_type = DependType.FrameByFrame any_frame = False for pre in self.get_preprocess_layers(): pre.depend_on(on_layer, DependType.LayerOnLayer, any_frame=True) depend = Depend(self, on_layer, depend_type, propigate, any_frame) self.__depends.append(depend) # Setup pre-process dependencies for my_preprocess in self.get_preprocess_layers(): for on_preprocess in on_layer.get_preprocess_layers(): # Depend on the layer's pre-process my_preprocess.depend_on(on_preprocess, DependType.LayerOnLayer) # # Handle depend propigation. # # Propigation occurs when a layer A depends on layer B, and # layer C depends on layer D, but Layer A also depends on Layer # C, which means layer D must now also depend on layer B. #
from depend import Depend from depend import DependReport if __name__ == "__main__": import sys file = sys.argv[1] lines = open(file).readlines() depend = Depend() depend.feed(lines) reporter = DependReport() print reporter.report(depend.getTree())
class TestAcceptance(unittest.TestCase): def setUp(self): self.depend = Depend() def feed(self, precomp): lines = precomp.splitlines() self.depend.feed(lines) def getStats(self, precomp): self.feed(precomp) return self.depend.getStats() def getTree(self, precomp): self.feed(precomp) return self.depend.getTree() def testNoNothing(self): tree = self.getTree("") assert (tree is None) def testNoNothingStats(self): stats = self.getStats("") self.assertEqual(len(stats.files()), 0) def testNoLineInfo(self): tree = self.getTree("/*nothing to see here*/") assert (tree is None) def testFirstNode(self): precomp = '''#line 1 "test.cpp"''' tree = self.getTree(precomp) self.assertEqual(tree.name(), "test.cpp") def testWonkyLine(self): precomp = ''' #line 1 "test.cpp"''' tree = self.getTree(precomp) self.assertEqual(tree.name(), "test.cpp") def testFirstNodeWithAnnoyingName(self): precomp = '''#line 1 "C:\\blahblah\\overhere\\overthere\\test.cpp"''' tree = self.getTree(precomp) self.assertEqual(tree.name(), "test.cpp") def testFirstNodeWithLines(self): tree = self.getTree(precompWithLines) self.assertEqual(tree.name(), "test.cpp") self.assertEqual(tree.lines(), 6) def testTwoRootLevelFiles(self): self.feed(precompWithLinesTemplate % "a.cpp") self.feed(precompWithLinesTemplate % "b.cpp") trees = self.depend.getTrees() self.assertEqual(len(trees), 2) self.assertEqual(trees[0].name(), "a.cpp") self.assertEqual(trees[0].lines(), 6) self.assertEqual(trees[0].totalLines(), 6) self.assertEqual(trees[1].name(), "b.cpp") self.assertEqual(trees[1].lines(), 6) self.assertEqual(trees[1].totalLines(), 6) def testOneInclude(self): tree = self.getTree(precompOneInclude) self.assertEqual(tree.name(), "test.cpp") self.assertEqual(tree.lines(), 5) self.assertEqual(len(tree.children()), 1) self.assertEqual(tree.children()[0].name(), "test.h") self.assertEqual(tree.children()[0].lines(), 1) self.assertEqual(len(tree.children()[0].children()), 0) def testNestedInclude(self): tree = self.getTree(precompNestedInclude) self.assertEqual(tree.name(), "test.cpp") self.assertEqual(tree.lines(), 5) self.assertEqual(len(tree.children()), 1) self.assertEqual(tree.children()[0].name(), "test2.h") self.assertEqual(tree.children()[0].lines(), 1) self.assertEqual(len(tree.children()[0].children()), 1) self.assertEqual(tree.children()[0].children()[0].name(), "test.h") def testNestedIncludeSameNames(self): tree = self.getTree(precompNestedIncludeSameName) self.assertEqual(tree.name(), "test.cpp") self.assertEqual(tree.lines(), 5) self.assertEqual(len(tree.children()), 1) self.assertEqual(tree.children()[0].name(), "test.h") self.assertEqual(tree.children()[0].lines(), 1) self.assertEqual(len(tree.children()[0].children()), 1) self.assertEqual(tree.children()[0].children()[0].name(), "test.h") def testTwoIncludes(self): tree = self.getTree(precompTwoIncludes) self.assertEqual(tree.name(), "test.cpp") self.assertEqual(tree.lines(), 5) self.assertEqual(len(tree.children()), 2) self.assertEqual(tree.children()[0].name(), "testa.h") self.assertEqual(tree.children()[1].name(), "testb.h") def testTotalLines(self): tree = self.getTree(precompWithLines) self.assertEqual(tree.totalLines(), 6) def testTotalLinesWithNestedChildren(self): tree = self.getTree(precompNestedInclude) self.assertEqual(tree.totalLines(), 7) def testTotalLinesWithChildren(self): tree = self.getTree(precompTwoIncludes) self.assertEqual(tree.totalLines(), 7) def testTwoGnuCppIncludes(self): tree = self.getTree(precompGnuCpp) self.assertEqual(tree.name(), "test.cpp") self.assertEqual(tree.lines(), 4) self.assertEqual(len(tree.children()), 2) self.assertEqual(tree.children()[0].name(), "testa.h") self.assertEqual(tree.children()[1].name(), "testb.h")
def setUp(self): self.depend = Depend()
from depend import Depend from depend import DependReport if __name__ == "__main__": import sys files = sys.argv[1:] depend = Depend() for file in files: lines = open(file).readlines() depend.feed(lines) reporter = DependReport() print reporter.reportStats(depend.getStats())
class TestAcceptance(unittest.TestCase): def setUp(self): self.depend = Depend() def feed(self, precomp): lines = precomp.splitlines() self.depend.feed(lines) def getStats(self, precomp): self.feed(precomp) return self.depend.getStats() def getTree(self, precomp): self.feed(precomp) return self.depend.getTree() def testNoNothing(self): tree = self.getTree("") assert tree is None def testNoNothingStats(self): stats = self.getStats("") self.assertEqual(len(stats.files()), 0) def testNoLineInfo(self): tree = self.getTree("/*nothing to see here*/") assert tree is None def testFirstNode(self): precomp = '''#line 1 "test.cpp"''' tree = self.getTree(precomp) self.assertEqual(tree.name(), "test.cpp") def testWonkyLine(self): precomp = ''' #line 1 "test.cpp"''' tree = self.getTree(precomp) self.assertEqual(tree.name(), "test.cpp") def testFirstNodeWithAnnoyingName(self): precomp = '''#line 1 "C:\\blahblah\\overhere\\overthere\\test.cpp"''' tree = self.getTree(precomp) self.assertEqual(tree.name(), "test.cpp") def testFirstNodeWithLines(self): tree = self.getTree(precompWithLines) self.assertEqual(tree.name(), "test.cpp") self.assertEqual(tree.lines(), 6) def testTwoRootLevelFiles(self): self.feed(precompWithLinesTemplate % "a.cpp") self.feed(precompWithLinesTemplate % "b.cpp") trees = self.depend.getTrees() self.assertEqual(len(trees), 2) self.assertEqual(trees[0].name(), "a.cpp") self.assertEqual(trees[0].lines(), 6) self.assertEqual(trees[0].totalLines(), 6) self.assertEqual(trees[1].name(), "b.cpp") self.assertEqual(trees[1].lines(), 6) self.assertEqual(trees[1].totalLines(), 6) def testOneInclude(self): tree = self.getTree(precompOneInclude) self.assertEqual(tree.name(), "test.cpp") self.assertEqual(tree.lines(), 5) self.assertEqual(len(tree.children()), 1) self.assertEqual(tree.children()[0].name(), "test.h") self.assertEqual(tree.children()[0].lines(), 1) self.assertEqual(len(tree.children()[0].children()), 0) def testNestedInclude(self): tree = self.getTree(precompNestedInclude) self.assertEqual(tree.name(), "test.cpp") self.assertEqual(tree.lines(), 5) self.assertEqual(len(tree.children()), 1) self.assertEqual(tree.children()[0].name(), "test2.h") self.assertEqual(tree.children()[0].lines(), 1) self.assertEqual(len(tree.children()[0].children()), 1) self.assertEqual(tree.children()[0].children()[0].name(), "test.h") def testNestedIncludeSameNames(self): tree = self.getTree(precompNestedIncludeSameName) self.assertEqual(tree.name(), "test.cpp") self.assertEqual(tree.lines(), 5) self.assertEqual(len(tree.children()), 1) self.assertEqual(tree.children()[0].name(), "test.h") self.assertEqual(tree.children()[0].lines(), 1) self.assertEqual(len(tree.children()[0].children()), 1) self.assertEqual(tree.children()[0].children()[0].name(), "test.h") def testTwoIncludes(self): tree = self.getTree(precompTwoIncludes) self.assertEqual(tree.name(), "test.cpp") self.assertEqual(tree.lines(), 5) self.assertEqual(len(tree.children()), 2) self.assertEqual(tree.children()[0].name(), "testa.h") self.assertEqual(tree.children()[1].name(), "testb.h") def testTotalLines(self): tree = self.getTree(precompWithLines) self.assertEqual(tree.totalLines(), 6) def testTotalLinesWithNestedChildren(self): tree = self.getTree(precompNestedInclude) self.assertEqual(tree.totalLines(), 7) def testTotalLinesWithChildren(self): tree = self.getTree(precompTwoIncludes) self.assertEqual(tree.totalLines(), 7) def testTwoGnuCppIncludes(self): tree = self.getTree(precompGnuCpp) self.assertEqual(tree.name(), "test.cpp") self.assertEqual(tree.lines(), 4) self.assertEqual(len(tree.children()), 2) self.assertEqual(tree.children()[0].name(), "testa.h") self.assertEqual(tree.children()[1].name(), "testb.h")
class TestDepend(MockTestCase): def setUp(self): self.depend = Depend() self.builder = self.mock() self.depend.builder = self.builder def expects(self): return self.builder.expects(once()) def expectEnd(self): self.expects().end() def expectNode(self, file, name): return self.expects().node(eq(file), eq(name)) def expectLine(self): return self.expects().line() def feed(self, text): self.depend.feed([text]) def testOneNode(self): self.expectNode("test.cpp", "test.cpp") self.expectEnd() self.feed('#line 1 "test.cpp"') def testTwoFeeds(self): self.expectNode("a.cpp", "a.cpp") self.expectEnd() self.expectNode("b.cpp", "b.cpp") self.expectEnd() self.feed('#line 1 "a.cpp"') self.feed('#line 1 "b.cpp"') def testWindowsFilenameWithPath(self): self.expectNode("C:\\doodaa\\day\\test.cpp", "test.cpp") self.expectEnd() self.feed('#line 2 "C:\\doodaa\\day\\test.cpp"') def testUnixFilenameWithPath(self): self.expectNode("/home.chris/src/test.cpp", "test.cpp") self.expectEnd() self.feed('#line 2 "/home.chris/src/test.cpp"') def testGnuCppNode(self): self.expectNode("test.cpp", "test.cpp") self.expectEnd() self.feed('# 1 "test.cpp"') def testGnuCppNodeType2(self): self.expectEnd() self.feed('# 1 "<built-in>"') def testGnuCppNodeType3(self): self.expectNode("testa.h", "testa.h") self.expectEnd() self.feed('# 1 "testa.h" 1') def testOneLine(self): self.expectLine() self.expectEnd() self.feed("struct a;") def testEmptyLine(self): self.expectLine() self.expectEnd() self.feed("") def testGetTree(self): self.expects().getTree() self.depend.getTree()
def setUp(self): self.depend = Depend() self.builder = self.mock() self.depend.builder = self.builder
for child in currentNode.children(): flag = 0 if len(child.children()) == 0: flag = 0 else: flag = 1 t.add_node(name=formatNodeText(child), id=child.file(), flag=flag) root=Tk() root.title(os.path.basename(sys.argv[0])) import sys from depend import Depend file = sys.argv[1] lines = open(file).xreadlines() depend = Depend() depend.feed(lines) dependTree = depend.getTree() searchFile = None if len(sys.argv) > 2: searchFile = sys.argv[2] if dependTree is None: print "Error reading dependancy information from %s" % file sys.exit(0) if searchFile is not None: displayIncludeChain(dependTree) # create the control t=Tree.Tree(master=root, root_id=dependTree.file(), root_label=formatNodeText(dependTree),
flag = 0 if len(child.children()) == 0: flag = 0 else: flag = 1 t.add_node(name=formatNodeText(child), id=child.file(), flag=flag) root = Tk() root.title(os.path.basename(sys.argv[0])) import sys from depend import Depend file = sys.argv[1] lines = open(file).xreadlines() depend = Depend() depend.feed(lines) dependTree = depend.getTree() searchFile = None if len(sys.argv) > 2: searchFile = sys.argv[2] if dependTree is None: print "Error reading dependancy information from %s" % file sys.exit(0) if searchFile is not None: displayIncludeChain(dependTree) # create the control t = Tree.Tree(master=root, root_id=dependTree.file(), root_label=formatNodeText(dependTree),