Example #1
0
def main(filepath, *a, **kw):
    filelist = txlparser.get_file_list(filepath)

    interactive = True
    if os.path.isdir(filepath):
        interactive = False
        kw['unparse'] = True

    def write(msg):
        if not interactive:
            io.output(msg)

    failures = 0
    for fp in filelist:
        success = True
        try:
            process_file(fp, *a, **kw)
        except:
            success = False
            if interactive:
                raise

        lab = "SUCCEEDED"
        if not success:
            failures += 1
            lab = "FAILED"
        localname = io.relpath(fp, relative_to=filepath)
        localname = localname == "." and filepath or localname
        write("%-9.9s  %s\n" % (lab.upper(), localname))
    write("Processed %s files, %s failed\n" % (len(filelist), failures))

    exitcode = failures > 0 and 1 or 0
    return exitcode
Example #2
0
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
Example #3
0
def get_graph_filepaths(graph, relative_to):
    ns = graph.rootnode.collect_nodes(lambda n: n)
    f = lambda n: io.relpath(os.path.join(graph.abspath, n.path, n.filename),
                             relative_to)
    filepaths = map(f, ns)
    filepaths = map(normalize_filepath, filepaths)
    return filepaths
Example #4
0
 def get_basepath(cls, basepath, relative_to=None):
     mypath = __file__
     distpath = os.path.dirname(os.path.abspath(mypath))
     basepath = os.path.normpath(os.path.join(distpath, basepath))
     if relative_to:
         basepath = io.relpath(basepath, relative_to)
     return basepath
Example #5
0
 def rebase_path(path):
     oldcwd = os.getcwd()
     try:
         os.chdir(graph.abspath)
         path = os.path.abspath(path)
     finally:
         os.chdir(oldcwd)
     path = io.relpath(path, relative_to=use_abspath)
     return path
Example #6
0
def inject(filepath, skiplist=None):
    filelist = txlparser.get_file_list(filepath)
    count = len(filelist)
    for (i, fp) in enumerate(filelist):
        localname = io.relpath(fp, relative_to=filepath)
        localname = localname == "." and filepath or localname
        if localname in skiplist:
            io.output("Skip file (%s/%s) %s\n" % (i+1, count, localname))
        else:
            io.output("Inject into (%s/%s) %s\n" % (i+1, count, localname))
            inject_into_file(fp, localname)
Example #7
0
    def parse_test(cls, filepath, unparse=False):
        filelist = get_file_list(filepath)

        failures = 0
        for fp in filelist:
            success, lab, out, err = cls.exec_gracefully(fp)
            if not success:
                failures += 1
            elif unparse:
                s = out[-1] == "\n" and out or out + "\n"
                open(fp, "w").write(s)
            localname = io.relpath(fp, relative_to=filepath)
            localname = localname == "." and filepath or localname
            io.output("%-9.9s  %s\n" % (lab.upper(), localname))
        io.output("Processed %s files, %s failed\n" % (len(filelist), failures))

        exitcode = failures > 0 and 1 or 0
        return exitcode
Example #8
0
    def get_stdlibpath(cls, src_first=False, libonly=False, relative_to=None):
        containers = ('lib', 'src')
        if src_first:
            containers = ('src', 'lib')
        if libonly:
            containers = ('lib',)

        stdlibpath = []
        for cont in containers:
            basepath = cls.get_basepath(cls.basepath_dcc_rel)
            cont = os.path.join(basepath, cont)
            stdlibpath.append(cont)
            for root, dirs, files in os.walk(cont):
                for d in dirs:
                    # skip debug dir, has dcus with debug info
                    if not (re.match('(?i)debug', d) or
                            re.search('(?i)debug', root)):
                        stdlibpath.append(os.path.join(root, d))
        if relative_to:
            for (i, path) in enumerate(stdlibpath):
                stdlibpath[i] = io.relpath(path, relative_to)
        return stdlibpath
Example #9
0
def do_prune(projectroot_path, fileindex):
    fps = io.ifind(projectroot_path, '*')
    fps = sorted(fps, key=lambda fp:fp.lower())
    fps = map(lambda fp: io.relpath(fp, relative_to=projectroot_path), fps)

    # filter out .git/*
    fps = filter(lambda fp: not re.match('(?i)\.git', fp), fps)

    filelist = filter(lambda fp: os.path.isfile(fp), fps)
    dirlist = filter(lambda fp: os.path.isdir(fp), fps)

    for fp in filelist:
        if not fileindex.has(fp):
            print('DELETE: %s' % fp)
            os.unlink(fp)
#        else:
#            print('KEEP  : %s' % fp)

    for fp in dirlist:
        try:
            os.removedirs(fp)
            print('RMDIR : %s' % fp)
        except:
            pass
Example #10
0
 def style_edge(self, start, end):
     dot_s = ''
     if start.path != end.path:
         rel = io.relpath(end.path, start.path)
         dot_s = ' [label="%s"]' % rel
     return dot_s
Example #11
0
 def set_path(node):
     node.path = io.relpath(os.path.join(dg.abspath, node.path),
                            relative_to=os.getcwd())
     return True
Example #12
0
#!/usr/bin/env python
#
# Copyright: Martin Matusiak <*****@*****.**>
# Licensed under the GNU Public License, version 3.

if __name__ == "__main__":
    import __path__

import os
import sys

from delpy import io


if __name__ == "__main__":
    try:
        (frm, to) = sys.argv[1:3]
    except IndexError:
        print("Usage:  %s <from_path> <to_path>" % sys.argv[0])
    print(io.relpath(to, relative_to=frm))