Ejemplo n.º 1
0
def get_user(username, community):
    """
    Gets a user from the database
    @param username: the name of the user
    @param community: a dbobjects.Community element
    """
    if not USER_CACHE.has_key(community.id):
        USER_CACHE[community.id] = {}
    if USER_CACHE[community.id].has_key(username):
        return USER_CACHE[community.id][username]
    user = User.select(AND(User.q.name == username,
                           User.q.communityID == community.id))
    if user.count():
        USER_CACHE[community.id][username] = user[0]
    else:
        USER_CACHE[community.id][username] = User(name=username, community=community)
    return USER_CACHE[community.id][username]
 def get_user(self, username, community):
     """
     Gets a user from the database
     @param username: the name of the user
     @param community: a dbobjects.Community element
     """
     if not self.user_cache.has_key(community.id):
         self.user_cache[community.id] = {}
     if self.user_cache[community.id].has_key(username):
         return self.user_cache[community.id][username]
     user = User.select(AND(User.q.name == username,             #pylint: disable-msg=E1101
                            User.q.communityID == community.id)) #pylint: disable-msg=E1101
     if user.count():
         self.user_cache[community.id][username] = user[0]
     else:
         self.user_cache[community.id][username] = User(name=username, community=community)
     return self.user_cache[community.id][username]
 def link_project_month(self, mproject, projarr, currentdate, nextdate):
     """
     Does the "heavy" lifting for linking individuals to projects over a time period
     
     @param mproject: master project to link to
     @param projarr: the array of child projects
     @param currendate: the date to start looking
     @param nextdate: the date to stop looking
     """
     # get the developers who committed during that period
     people = Person.select(AND(Person.q.id == PersonUser.q.personID, # pylint: disable-msg=E1101
                                PersonUser.q.userID == CVSCommit.q.userID, # pylint: disable-msg=E1101
                                CVSCommit.q.startDate >= currentdate, # pylint: disable-msg=E1101
                                CVSCommit.q.startDate < nextdate, # pylint: disable-msg=E1101
                                IN(CVSCommit.q.projectID, projarr)), distinct=True) # pylint: disable-msg=E1101
     
     count = 0
     numcorp = 0
     numunknown = 0
     # iterate over each of the people
     for person in people:
         user = User.select(AND(User.q.id == PersonUser.q.userID, # pylint: disable-msg=E1101
                                PersonUser.q.personID == person.id))[0] # pylint: disable-msg=E1101
             
         # first get their company.  cache it if possible
         if self.corpmap.has_key(person.id):
             corporation = self.corpmap[person.id]
         else:
             corporations = person.corporations
             if len(corporations) == 0:
                 corporation = self.unknowncorp
             else:
                 corporation = corporations[0]
             self.corpmap[person.id] = corporation
         
         # increment some tracking counters
         if corporation == self.unknowncorp:
             numunknown = numunknown + 1
         else:
             numcorp = numcorp + 1
             
         # now, get their commits, we need the number of commits and the number of lines added/removed
         commits = CVSCommit.select(AND(CVSCommit.q.userID == PersonUser.q.userID, # pylint: disable-msg=E1101
                                     PersonUser.q.personID == person.id, # pylint: disable-msg=E1101
                                     CVSCommit.q.startDate >= currentdate, # pylint: disable-msg=E1101
                                     CVSCommit.q.startDate < nextdate, # pylint: disable-msg=E1101
                                     IN(CVSCommit.q.projectID, projarr)), distinct=True) # pylint: disable-msg=E1101
         commitids = [x.id for x in commits]
         numcommits = len(commitids)
         
         # in some cases, we don't have complete information, we just set those to empty here
         linesadded = FileCommit.select(IN(FileCommit.q.cvsCommitID, commitids)).sum(FileCommit.q.linesAdded) or 0 # pylint: disable-msg=E1101
         linesremoved = FileCommit.select(IN(FileCommit.q.cvsCommitID, commitids)).sum(FileCommit.q.linesRemoved) or 0 # pylint: disable-msg=E1101
         linesdelta = linesadded - linesremoved
         
         # commit the object
         newpi = ProjectInvolvement(user=user, corporation=corporation,
                                    project=mproject, year=currentdate.year,
                                    month=currentdate.month, date=currentdate,
                                    numCommits=numcommits, linesAdded=linesadded,
                                    linesRemoved=linesremoved, linesDelta=linesdelta)
         count = count + 1
     self.log.info("%s-%s Added %d links (%d corp, %d unknown)...", currentdate, nextdate, count, numcorp, numunknown) 
     return count