def main(self):
        """
        A replacable main function.  If you wish to use the data loader features of this
        class, you'll need to edit the code at the bottom of this file.
        
        This one is basically connects to the database and then attempts to fire up the
        pairing process.
        
        GNOME doesn't use hierarchical project descriptions, so this should not be nearly
        as big of a deal that we force the parent to be none.
        """
        options, args = self.parser.parse_args()
        
        self.log.setLevel(getattr(logging, options.loglevel.upper()))

        # connect to the database
        self.log.debug("connecting to database: %s - debug=%s", options.uri, options.debug)
        connect(options.uri, debug=options.debug, autocommit=False)
    
        try:
            self.community = Community.select(Community.q.name==options.community)[0] # pylint: disable-msg=E1101
        except IndexError:
            self.log.error("Unable to find community \"%s\"", options.community)
            sys.exit()
        
        self.unknowncorp = Corporation.select(Corporation.q.name=="unknown")[0] # pylint: disable-msg=E1101
        
        projects = MasterProject.select(AND(MasterProject.q.communityID==self.community.id, # pylint: disable-msg=E1101
                                            MasterProject.q.parentID==None)) # pylint: disable-msg=E1101
        for project in projects:
            self.link_project(project)
def get_community(community_name):
    """
    Finds the community with the given name, creating it if necessary
    
    @param community_name: the name of the community to example (eg "eclipse", "gnome")
    @return: an SQLObject Community entity
    @rtype: dbojects.Community
    """
    comm = Community.select(Community.q.name == community_name)
    if comm.count():
        COMMUNITY_CACHE[community_name] = comm[0]
        return comm[0]
    else:
        COMMUNITY_CACHE[community_name] = Community(name=community_name)
        return COMMUNITY_CACHE[community_name]
    def get_community(self, community_name):
        """
        Finds the community with the given name, creating it if necessary

        @param community_name: the name of the community to example (eg "eclipse", "gnome")
        @return: an SQLObject Community entity
        @rtype: dbojects.Community
        """
        comm = Community.select(Community.q.name == community_name) #pylint: disable-msg=E1101
        if comm.count():
            self.community_cache[community_name] = comm[0]
            return comm[0]
        else:
            self.community_cache[community_name] = Community(name=community_name)
            return self.community_cache[community_name]
    def main(self):
        """
        Generic main handler for the network maker.
        
        Connects to the database, gets the involvments, calls the network maker,
        save the network.  Awesome.
        """
        options, args = self.parser.parse_args()
        
        # these options can be specified via the command line or through the defaults
        self.outputdir = options.outputdir
        self.communityname = options.community
        
        self.log.setLevel(getattr(logging, options.loglevel.upper()))

        # connect to the database
        self.log.debug("connecting to database: %s - debug=%s", options.uri, options.debug)
        connect(options.uri, debug=options.debug, autocommit=False)

        community = Community.select(Community.q.name==self.communityname)[0] #pylint: disable-msg=E1101

        # get the set of projects if we have filter options
        projectset = self.get_project_set(community, options.mincommits, options.mindevelopers, options.mincorps) # pylint: disable-msg=E1101

        if projectset:
            print len(projectset)
            involvement = ProjectInvolvement.select(AND(ProjectInvolvement.q.projectID == MasterProject.q.id, #pylint: disable-msg=E1101
                                                        MasterProject.q.communityID == community.id, # pylint: disable-msg=E1101
                                                        IN(MasterProject.q.id, projectset)), # pylint: disable-msg=E1101
                                                        distinct=True)
        else:
            involvement = ProjectInvolvement.select(AND(ProjectInvolvement.q.projectID == MasterProject.q.id, #pylint: disable-msg=E1101
                                                        MasterProject.q.communityID == community.id), # pylint: disable-msg=E1101
                                                        distinct=True)
        self.log.info("ProjectInvolvement count: %d", involvement.count())
        ctr = 0
        if involvement.count() > 0:
            for devinv in involvement:
                ctr = ctr + 1
                self.add_involvement(devinv)
                if ctr%100 == 0:
                    self.log.info("processing involvement %d", ctr)
        else:
            self.log.error("No developer involvement found, exiting")
            sys.exit()

        # multiply out the corporate involvement
        self.multiply_corporate_participation()
        
        # create the output directory   
        if not os.path.isdir(self.outputdir):
            os.makedirs(self.outputdir)
            
        outputnetwork = ETs.ElementTreeSerializer().toString(self.network)        
        outfile = open(self.outputdir + os.sep + "%s.dynetml" % (self.communityname), "w")
        outfile.write(outputnetwork)
        outfile.close()
        
        # now, dump all of the networks, yowza
        self.save_nodenames()
        for network in self.graphs.itervalues():
            self.save_graph(network)