예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #4
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()