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_project_set(self, community, mincommits, mindevelopers, mincorps):
     """
     Queries the database to filter through the projects and only fetch the data for
     the projects that meet criteria.  Useful for GNOME
     
     @param community: the community to filter
     @param mincommits: the minimum number of commits for the project
     @param mindevelopers: the minimum number of developers for the project
     @param mincorps: the minimum number of corporations
     """
     if not(mincommits) and not(mindevelopers) and not(mincorps):
         return None
     # create a default set of projects that includes all master projects
     defaultset = Set([x.id for x in MasterProject.select(MasterProject.q.communityID == community.id)]) # pylint: disable-msg=E1101
     
     # now, if we have a commits filter, lets get that
     if mincommits:
         query = """SELECT master_project.master_project_id, count(*) FROM master_project, project, cvs_commit 
                     WHERE master_project.master_project_id = project.master_project_id
                           AND project.project_id = cvs_commit.project_id
                           AND master_project.community_id=%s
                  GROUP BY master_project.master_project_id""" % (community.id)
         commitset = Set([x[0] for x in raw_query(query) if x[1] >= mincommits])
     else:
         commitset = defaultset
     
     # filter by minimum number of developers, we use cvs commits here
     if mindevelopers:
         query = """SELECT master_project.master_project_id, count(distinct cvs_commit.user_id) FROM master_project, project, cvs_commit
                     WHERE master_project.master_project_id = project.master_project_id
                           AND project.project_id = cvs_commit.project_id
                           AND master_project.community_id=%s
                  GROUP BY master_project.master_project_id""" % (community.id)
         print query
         developerset = Set([x[0] for x in raw_query(query) if x[1] >= mindevelopers])
     else:
         developerset = defaultset
     
     # filter by the minimum number of corporations
     if mincorps:
         query = """SELECT project_id, count(distinct corporation_id) FROM user_corporation_project, master_project
                     WHERE user_corporation_project.project_id = master_project.master_project_id
                           AND master_project.community_id=%s
                  GROUP BY user_corporation_project.project_id""" % (community.id)
         print query
         corpset = Set([x[0] for x in raw_query(query) if x[1] >= mincorps])
          
     else:
         corpset = defaultset
         
     retset = commitset.intersection(developerset).intersection(corpset)
     self.log.info("Filtering Down: original=%d, commits=%d, developers=%d, corporations=%d, final=%d", len(defaultset),
                   len(commitset), len(developerset), len(corpset), len(retset))
     return retset
def get_master_project(community, project):
    """
    Gets a master project for a particular community
    
    @param community: a dbobjects.Community 
    @param project: the name of the community
    """
    if not MASTER_PROJECT_CACHE.has_key(community.id):
        MASTER_PROJECT_CACHE[community.id] = {}
    if MASTER_PROJECT_CACHE[community.id].has_key(project):
        return MASTER_PROJECT_CACHE[community.id][project]
    mproject = MasterProject.select(AND(MasterProject.q.name == project,
                                        MasterProject.q.communityID == community.id))
    if mproject.count():
        MASTER_PROJECT_CACHE[community.id][project] = mproject[0]
    else:
        MASTER_PROJECT_CACHE[community.id][project] = MasterProject(name=project, community=community)
    return MASTER_PROJECT_CACHE[community.id][project]
 def get_master_project(self, community, project):
     """
     Gets a master project for a particular community
     
     @param community: a dbobjects.Community 
     @param project: the name of the community
     """
     if not self.master_project_cache.has_key(community.id):
         self.master_project_cache[community.id] = {}
     if self.master_project_cache[community.id].has_key(project):
         return self.master_project_cache[community.id][project]
     mproject = MasterProject.select(AND(MasterProject.q.name == project,              #pylint: disable-msg=E1101
                                         MasterProject.q.communityID == community.id)) #pylint: disable-msg=E1101
     if mproject.count():
         self.master_project_cache[community.id][project] = mproject[0]
     else:
         self.master_project_cache[community.id][project] = MasterProject(name=project, community=community)
     return self.master_project_cache[community.id][project]