def get_filelist_from_graph(fileindex, filepath): dg = DelphiGraph.from_file(filepath) df = dg.rootnode if not projectroot_path: projectroot_path = dg.abspath projectroot_path = os.path.realpath(projectroot_path) nodes = df.collect_nodes(DelphiFile.NodePredicates.path_not_in(dg.stdlibpath)) # extract path to project file filepaths = map(lambda n: os.path.join(n.path, n.filename), nodes) # make absolute oldcwd = os.getcwd() io.safechdir(dg.abspath) filepaths = map(lambda fp: os.path.abspath(fp), filepaths) io.safechdir(oldcwd) # make relative to project root filepaths = map(lambda fp: io.relpath(fp, relative_to=projectroot_path), filepaths) for fp in filepaths: fileindex.set(fp) return projectroot_path
def process(index, graphs, trace=False): def output(s): if not trace: io.write(s) order = FileTypes.get_filetypes_by_build_target() for filetype in order: items = index.get(filetype, []) items = util.isort(items) if items: output('%s:\n' % filetype.name) for item in items: line = '- %s\n' % item output(line) if trace: graph_fp = trace_file(item, filetype) graph = DelphiGraph.from_file(graph_fp) graphs[item] = graph filter_index_by_graph(index, graph, excludes=[FileTypes.DelphiProjectGroup, FileTypes.DelphiProject, FileTypes.Program, FileTypes.Library, FileTypes.Package])
def show_diff(filepath1, filepath2): graph1 = DelphiGraph.from_file(filepath1) graph2 = DelphiGraph.from_file(filepath2) color_title = ansicolor.magenta color1 = ansicolor.cyan color2 = ansicolor.yellow keyw_def, fstw_def, sndw_def = 10, 30, 30 diffs = DelphiGraph.diff_graphs(graph1, graph2) exit = 0 if diffs: exit = 1 io.output('Showing diff between:\n') io.output(' - %s\n' % color1(filepath1)) io.output(' - %s\n' % color2(filepath2)) for diff in diffs: io.output(color_title('>>> File: %s\n' % diff.name)) keyw = get_len(diff.keys(), keyw_def) for att, val in diff.iteritems(): fst, snd = val fsts = fmt_obj(fst, fstw_def) snds = fmt_obj(snd, sndw_def) fstw = get_len(fsts, fstw_def) sndw = get_len(snds, sndw_def) if fstw <= fstw_def and sndw <= sndw_def: s = show_sidebyside(att, fsts, snds, (keyw,fstw,sndw), (color1,color2)) else: s = show_oneafterother(att, fsts, snds, (keyw,fstw,sndw), (color1,color2)) io.output(s) return exit
def get_graph(filepath, prefilter=None, maxdepth=None): if not DelphiGraph.filepath_is_graph(filepath): # pre filter projview = False if prefilter: # projview projview = True # trace tracer = DepTracer() filepath = tracer.trace_write(filepath, maxdepth=maxdepth, projview=projview) # load from file dg = DelphiGraph.from_file(filepath) return dg
def build(filepath, use_graph=None, target_dir=None): transform = {} if not DelphiGraph.filepath_is_graph(filepath): fpabs = os.path.abspath(filepath) abspath = os.path.dirname(fpabs) relpath = "." filename = os.path.basename(fpabs) stdlibpath = DelphiCompiler.get_stdlibpath(libonly=True, relative_to=abspath) includepath = ";".join(stdlibpath) if use_graph: dg = DelphiGraph.from_file(use_graph) df = dg.rootnode includepath = prepare_path(dg, use_abspath=abspath) return do_compile(transform, abspath, relpath, filename, includepath, target_dir=target_dir) else: # load from file dg = DelphiGraph.from_file(filepath) df = dg.rootnode targets = df.collect_nodes(lambda n: n.filetype in (FileTypes.Program, FileTypes.Library, FileTypes.Package)) target = targets[0] includepath = prepare_path(dg) try: # XXX seems to be redundant at times, not understood when do_dfm_conversion(transform, dg) exitcode = do_compile( transform, dg.abspath, target.path, target.filename, includepath, target_dir=target_dir ) finally: for (orig, new) in transform.items(): io.rename(new, orig) return exitcode
oldcwd = os.getcwd() try: io.safechdir(path) self.index_clear() df = trace_deps(filename, searchpath, stdlibpath, {}, maxdepth=maxdepth) finally: io.safechdir(oldcwd) return DelphiGraph(df, abspath, searchpath, stdlibpath) def trace_write(self, *args, **kw): noclobber = util.readkw(kw, 'noclobber', None) delphigraph = self.trace(*args, **kw) fp = delphigraph.to_file(noclobber=noclobber) return fp if __name__ == '__main__': file = sys.argv[1] tracer = DepTracer() fp = tracer.trace_write(file) dg = DelphiGraph.from_file(fp) if '-d' in sys.argv: prettyprinter.pp(dg, collapse_duplicates=True) sys.exit() if '-s' in sys.argv: dotgenerator.DotGenerator(dg).show_dot()