1. John Chandler
  2. qadpid


qadpid / go_qadpid.py

#!/usr/bin/env python
qadpid - takes a PHP project directory structure and generates a DOT representation of the dependencies

Copyright 2011 John Chandler
This software is distributed under the terms of the GNU General Public License version 3
import os
import sys
from optparse import OptionParser

from qadpid.hierarchy import PHPHierarchyCreator
from qadpid.parser    import PHPFileParser
from qadpid.writer    import DOTWriter

def source_directory( source_dir ):
    """ Generator returning the next location to look at """
    dir_walker = os.walk( source_dir )

    while True:
        yield dir_walker.next()

if __name__ == "__main__":    
    parser = OptionParser( "usage: %prog [options] dir" )
    parser.add_option( "-o", "--output", dest="output_filename", help="write DOT output to FILE", metavar="FILE")

    options, args = parser.parse_args()

    if len(args) != 1:
        parser.error( "no directory specified!" )

    # set output
    if options.output_filename:
        output_file = open(options. output_filename, "w" )
        output_file = sys.stdout

    # set things up
    parser  = PHPFileParser()
    creator = PHPHierarchyCreator( parser=parser )

    # walk source directory structure
    for location in source_directory( args[0] ):
        current_directory = location[0]

        #print "walking %s" % str(current_directory)
        creator.add( location )

    # write file
    writer = DOTWriter( creator.hierarchy )
    writer.write( output_file )