Esempio n. 1
0
def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())

    parser.add_option('-o',
                      '--overwrite',
                      action='store_true',
                      help="Overwrite the destination files. "
                      "If this is not set, an error is generated if "
                      "the destination file exists.")

    parser.add_option(
        '-i',
        '--insert-package-inits',
        action='store_true',
        help=
        "Automatically create missing __init__.py in intervening directories.")

    opts, args = parser.parse_args()

    if len(args) != 1:
        parser.error("You must specify the destination root.")
    dest, = args

    if not opts.overwrite and exists(dest):
        logging.error("Cannot overwrite '%s'." % dest)
        sys.exit(1)

    depends = list(read_depends(sys.stdin))

    for droot, drel in flatten_depends(depends):
        srcfn = join(droot, drel)
        if isdir(srcfn):
            drel = join(drel, '__init__.py')
            srcfn = join(droot, drel)
        dstfn = join(dest, drel)

        if not opts.overwrite and exists(dstfn):
            logging.error("Cannot overwrite '%s'." % dstfn)
            sys.exit(1)

        destdir = dirname(dstfn)
        if not exists(destdir):
            os.makedirs(destdir)

        print_('Copying: %s' % srcfn)
        if not exists(srcfn):
            logging.error("Could not copy file '%s'." % srcfn)
            continue
        shutil.copyfile(srcfn, dstfn)

    if opts.insert_package_inits:
        for root, dirs, files in os.walk(dest):
            if root == dest:
                continue  # Not needed at the very root.
            initfn = join(root, '__init__.py')
            if not exists(initfn):
                print_('Creating: %s' % initfn)
                f = open(initfn, 'w')
                f.close()
Esempio n. 2
0
def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())
    opts, renames = parser.parse_args()

    if len(renames) % 2:
        parser.error("An odd number of renames was specified.")

    renames = [(re.compile(regexp), target)
               for regexp, target in iterpairs(renames)]

    depends = read_depends(sys.stdin)

    clusfiles = defaultdict(set)
    for (froot, f), (troot, t) in depends:
        for rename, target in renames:
            if rename.match(f):
                f = target
                break
        cfrom = (froot, f)
        for rename, target in renames:
            if t and rename.match(t):
                t = target
                break
        cto = (troot, t)

        # Skip self-dependencies that may occur.
        if cfrom == cto:
            cto = (None, None)

        clusfiles[cfrom].add(cto)

    output_depends(clusfiles)
Esempio n. 3
0
def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())

    parser.add_option('-f', '--from-file', action='store',
                      help="Read cluster list from the given filename.")

    opts, clusters = parser.parse_args()

    if opts.from_file:
        clusters.extend(read_clusters(opts.from_file))

    depends = read_depends(sys.stdin)

    clusfiles = defaultdict(set)
    for (froot, f), (troot, t) in depends:
        cfrom = apply_cluster(clusters, froot, f)
        cto = apply_cluster(clusters, troot, t)

        # Skip self-dependencies that may occur.
        if cfrom == cto:
            cto = (None, None)

        clusfiles[cfrom].add(cto)

    output_depends(clusfiles)
Esempio n. 4
0
def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())

    parser.add_option('-f',
                      '--from-file',
                      action='store',
                      help="Read cluster list from the given filename.")

    opts, clusters = parser.parse_args()

    if opts.from_file:
        clusters.extend(read_clusters(opts.from_file))

    depends = read_depends(sys.stdin)

    clusfiles = defaultdict(set)
    for (froot, f), (troot, t) in depends:
        cfrom = apply_cluster(clusters, froot, f)
        cto = apply_cluster(clusters, troot, t)

        # Skip self-dependencies that may occur.
        if cfrom == cto:
            cto = (None, None)

        clusfiles[cfrom].add(cto)

    output_depends(clusfiles)
Esempio n. 5
0
def main():
    parser = optparse.OptionParser(__doc__.strip())
    opts, args = parser.parse_args()

    depends = read_depends(sys.stdin)
    for droot, drel in flatten_depends(depends):
        print(join(droot, drel))
Esempio n. 6
0
def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())
    opts, renames = parser.parse_args()

    if len(renames) % 2:
        parser.error("An odd number of renames was specified.")

    renames = [(re.compile(regexp), target)
               for regexp, target in iterpairs(renames)]

    depends = read_depends(sys.stdin)

    clusfiles = defaultdict(set)
    for (froot, f), (troot, t) in depends:
        for rename, target in renames:
            if rename.match(f):
                f = target
                break
        cfrom = (froot, f)
        for rename, target in renames:
            if t and rename.match(t):
                t = target
                break
        cto = (troot, t)

        # Skip self-dependencies that may occur.
        if cfrom == cto:
            cto = (None, None)

        clusfiles[cfrom].add(cto)

    output_depends(clusfiles)
Esempio n. 7
0
def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())
    opts, args = parser.parse_args()

    depends = read_depends(sys.stdin)
    for droot, drel in flatten_depends(depends):
        print_(join(droot, drel))
Esempio n. 8
0
def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())

    parser.add_option('-o', '--overwrite', action='store_true',
                      help="Overwrite the destination files. "
                      "If this is not set, an error is generated if "
                      "the destination file exists.")

    parser.add_option('-i', '--insert-package-inits', action='store_true',
                      help="Automatically create missing __init__.py in intervening directories.")

    opts, args = parser.parse_args()

    if len(args) != 1:
        parser.error("You must specify the destination root.")
    dest, = args

    if not opts.overwrite and exists(dest):
        logging.error("Cannot overwrite '%s'." % dest)
        sys.exit(1)

    depends = list(read_depends(sys.stdin))
    
    for droot, drel in flatten_depends(depends):
        srcfn = join(droot, drel)
        if isdir(srcfn):
            drel = join(drel, '__init__.py')
            srcfn = join(droot, drel)
        dstfn = join(dest, drel)

        if not opts.overwrite and exists(dstfn):
            logging.error("Cannot overwrite '%s'." % dstfn)
            sys.exit(1)

        destdir = dirname(dstfn)
        if not exists(destdir):
            os.makedirs(destdir)
            
        print 'Copying: %s' % srcfn
        if not exists(srcfn):
            logging.error("Could not copy file '%s'." % srcfn)
            continue
        shutil.copyfile(srcfn, dstfn)

    if opts.insert_package_inits:
        for root, dirs, files in os.walk(dest):
            if root == dest:
                continue  # Not needed at the very root.
            initfn = join(root, '__init__.py')
            if not exists(initfn):
                print 'Creating: %s' % initfn
                f = open(initfn, 'w')
                f.close()
Esempio n. 9
0
def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())

    parser.add_option('-f', '--full-pathnames', '--full', action='store_true',
                      help="Output the full pathnames, not just the relative.")

    parser.add_option('-p', '--pythonify-filenames', '--remove-extensions',
                      action='store_true',
                      help="Remove filename extensions in the graph and "
                      "replace slashes with dots.")

    parser.add_option('-r', '--redundant', action='store_false', default=True,
                      help="Do not eliminate redundant dependencies.")

    parser.add_option('--fontsize', action='store', type='int',
                      default=10,
                      help="The size of the font to use for nodes.")
    
    parser.add_option('--rankdir', action='store',
                      default='LR',
                      help="The direction of the graph layout (dot only). LR or TB.")
    
    parser.add_option('--size', action='store',
                      default='8,10',
                      help="Size.")
    
    parser.add_option('--shape', action='store',
                      default='ellipse',
                      help="Node shape. [ellipse,box,..]")
    
    parser.add_option('--ratio', action='store',
                      default='fill',
                      help="See http://www.graphviz.org/doc/info/attrs.html#d:ratio.")

    global opts
    opts, args = parser.parse_args()

    if not args:
        args = ['-']
    for fn in args:
        if fn == '-':
            f = sys.stdin
        else:
            f = open(fn)
        depends = read_depends(f)
        if opts.redundant:
            depends = eliminate_redundant_depends(depends)
        graph(depends, sys.stdout.write, opts.fontsize, opts.rankdir, 
              opts.size, opts.ratio, opts.shape)
Esempio n. 10
0
def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())

    parser.add_option('-f',
                      '--full-pathnames',
                      '--full',
                      action='store_true',
                      help="Output the full pathnames, not just the relative.")

    parser.add_option('-p',
                      '--pythonify-filenames',
                      '--remove-extensions',
                      action='store_true',
                      help="Remove filename extensions in the graph and "
                      "replace slashes with dots.")

    parser.add_option('-r',
                      '--redundant',
                      action='store_false',
                      default=True,
                      help="Do not eliminate redundant dependencies.")

    parser.add_option('--fontsize',
                      action='store',
                      type='int',
                      default=10,
                      help="The size of the font to use for nodes.")

    parser.add_option('--dpi',
                      action='store',
                      type='int',
                      default=-1,
                      help="Resolution to use for graph.")

    global opts
    opts, args = parser.parse_args()

    if not args:
        args = ['-']
    for fn in args:
        if fn == '-':
            f = sys.stdin
        else:
            f = open(fn)
        depends = read_depends(f)
        if opts.redundant:
            depends = eliminate_redundant_depends(depends)
        graph(depends, sys.stdout.write, opts.fontsize, opts.dpi)
Esempio n. 11
0
def main():
    import optparse

    parser = optparse.OptionParser(__doc__.strip())

    parser.add_option(
        "-f",
        "--full-pathnames",
        "--full",
        action="store_true",
        help="Output the full pathnames, not just the relative.",
    )

    parser.add_option(
        "-p",
        "--pythonify-filenames",
        "--remove-extensions",
        action="store_true",
        help="Remove filename extensions in the graph and " "replace slashes with dots.",
    )

    parser.add_option(
        "-r", "--redundant", action="store_false", default=True, help="Do not eliminate redundant dependencies."
    )

    parser.add_option(
        "--fontsize", action="store", type="int", default=10, help="The size of the font to use for nodes."
    )

    global opts
    opts, args = parser.parse_args()

    if not args:
        args = ["-"]
    for fn in args:
        if fn == "-":
            f = sys.stdin
        else:
            f = open(fn)
        depends = read_depends(f)
        if opts.redundant:
            depends = eliminate_redundant_depends(depends)
        graph(depends, sys.stdout.write, opts.fontsize)
Esempio n. 12
0
def main():
    import optparse
    parser = optparse.OptionParser()

    parser.add_option('-f',
                      '--from-file',
                      action='store',
                      help="Read cluster list from the given filename.")

    opts, renames = parser.parse_args()

    if opts.from_file:
        renames.extend(read_clusters(opts.from_file))

    if len(renames) % 2:
        parser.error("An odd number of renames was specified.")

    renames = [(re.compile(regexp), target)
               for regexp, target in iterpairs(renames)]

    depends = read_depends(sys.stdin)

    clusfiles = defaultdict(set)
    for (froot, f), (troot, t) in depends:
        for rename, target in renames:
            if rename.match(f):
                f = target
                break
        cfrom = (froot, f)
        for rename, target in renames:
            if t and rename.match(t):
                t = target
                break
        cto = (troot, t)

        # Skip self-dependencies that may occur.
        if cfrom == cto:
            cto = (None, None)

        clusfiles[cfrom].add(cto)

    output_depends(clusfiles)
Esempio n. 13
0
File: graph.py Progetto: SCV/cgat
def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())

    parser.add_option('-f', '--full-pathnames', '--full', action='store_true',
                      help="Output the full pathnames, not just the relative.")

    parser.add_option('-p', '--pythonify-filenames', '--remove-extensions',
                      action='store_true',
                      help="Remove filename extensions in the graph and "
                      "replace slashes with dots.")

    parser.add_option('-r', '--redundant', action='store_false', default=True,
                      help="Do not eliminate redundant dependencies.")

    parser.add_option('--fontsize', action='store', type='int',
                      default=10,
                      help="The size of the font to use for nodes.")

    global opts
    opts, args = parser.parse_args()

    if not args:
        args = ['-']

    color_map = {}

    for fn in args:
        if fn == '-':
            f = sys.stdin
        else:
            f = open(fn)
        depends = read_depends(f)
        if opts.redundant:
            depends = eliminate_redundant_depends(depends)
        graph(depends, sys.stdout.write, opts.fontsize, color_map)
Esempio n. 14
0
#!/usr/bin/python
import sys
from snakefood.depends import read_depends

## def read_depends(f):
##     "Generator for the dependencies read from the given file object."
##     for line in f:
##         try:
##             yield eval(line)
##         except Exception:
##             logging.warning("Invalid line: '%s'" % line)

depends = read_depends(sys.stdin)

for d in depends:

    if d[0][0].startswith("/home/nbecker/idma-cdma") and (
        d[1][0] == None or d[1][0].startswith("/home/nbecker/idma-cdma")
    ):
        print d
Esempio n. 15
0
#!/usr/bin/python
import sys
from snakefood.depends import read_depends

## def read_depends(f):
##     "Generator for the dependencies read from the given file object."
##     for line in f:
##         try:
##             yield eval(line)
##         except Exception:
##             logging.warning("Invalid line: '%s'" % line)

depends = read_depends(sys.stdin)

for d in depends:

    if (d[0][0].startswith ('/home/nbecker/idma-cdma') and \
        (d[1][0] == None or \
         d[1][0].startswith ('/home/nbecker/idma-cdma'))):
        print(d)