boa-constructor /

import HTMLCyclops

import types, sys, string
from os import path

""" This module runs Tim Peter's Cyclops cycle finder on a module given as
    a command line parameter. It was subclassed to provide browsable HTML.

    Please comment out lines to avoid running certain sub reports.
    See comments in the code further down.


def mod_refs(x):
    return x.__dict__.values()

def mod_tag(x, i):
    return "." + x.__dict__.keys()[i]

def func_refs(x):
    return x.func_globals, x.func_defaults

def func_tag(x, i):
    return (".func_globals", ".func_defaults")[i]

def instance_filter(cycle):
    for obj, index in cycle:
        if type(obj) is types.InstanceType:
            return 1
    return 0

def run():
    mod_name = path.splitext(sys.argv[1])[0]
    print 'MOD_NAME', mod_name
    # remove command line option
    del sys.argv[1]
    f = open(mod_name+'.cycles', 'w')
        z = HTMLCyclops.CycleFinderHTML()
        mod = __import__(mod_name)

        # Comment out any of the following lines to not add a chaser or filter
        z.chase_type(types.ModuleType, mod_refs, mod_tag)
        z.chase_type(types.FunctionType, func_refs, func_tag)

        # Execute the module and trace the first round of cycles
            import traceback

            tp, vl, tb = sys.exc_info()
            err = '<font color="#FF4444"><h3>Error:</h3></font>'+\
              string.join(traceback.format_exception(tp, vl, tb), '<br>')


        # Comment out any of the following lines to not show a certain section
        # of the report.
        z.show_stats(z.stats_list())        # Statistics
        z.show_cycles()               # All cycles
        z.show_cycleobjs()            # Objects involved in cycles
        z.show_sccs()                 # Cycle objects partitioned into maximal SCCs
        z.show_arcs()                 # Arc types involved in cycles
        z.iterate_til_steady_state(show_objs=0) # Repeatedly purge until there are no more dead roots

        # Write out the report

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.