Ticket #313: harmless2.patch

File harmless2.patch, 9.5 kB (added by albertHofkamp, 6 months ago)

several small changes, see ticket for details

  • buildbot-0.7.7/buildbot/locks.py

    old new  
    1010    debuglog = lambda m: None 
    1111 
    1212class BaseLock: 
     13    """ 
     14    Class handling claiming and releasing of L{self}, and keeping track of 
     15    current and waiting owners. 
     16 
     17    @note: Ideally, we'd like to maintain FIFO order. The place to do that 
     18           would be the L{isAvailable()} function. However, this function is 
     19           called by builds/steps both for the first time, and after waking 
     20           them up by L{self} from the L{self.waiting} queue. There is 
     21           currently no way of distinguishing between them. 
     22    """ 
    1323    description = "<BaseLock>" 
    1424 
    1525    def __init__(self, name, maxCount=1): 
     
    2232        return self.description 
    2333 
    2434    def isAvailable(self): 
     35        """ Return a boolean whether the lock is available for claiming """ 
    2536        debuglog("%s isAvailable: self.owners=%r" % (self, self.owners)) 
    2637        return len(self.owners) < self.maxCount 
    2738 
    2839    def claim(self, owner): 
     40        """ Claim the lock (lock must be available) """ 
    2941        debuglog("%s claim(%s)" % (self, owner)) 
    3042        assert owner is not None 
    3143        assert len(self.owners) < self.maxCount, "ask for isAvailable() first" 
     
    3345        debuglog(" %s is claimed" % (self,)) 
    3446 
    3547    def release(self, owner): 
     48        """ Release the lock """ 
    3649        debuglog("%s release(%s)" % (self, owner)) 
    3750        assert owner in self.owners 
    3851        self.owners.remove(owner) 
     
    90103        return self.locks[slavename] 
    91104 
    92105 
     106class BaseLockId(util.ComparableMixin): 
     107    """ Abstract base class for LockId classes. 
     108 
     109    Derived classes should add 
     110    - Comparison with the L{util.ComparableMixin} via the L{compare_attrs} 
     111      class variable. 
     112    - Link to the actual lock class should be added with the L{lockClass} 
     113      class variable. 
     114    """ 
     115 
    93116# master.cfg should only reference the following MasterLock and SlaveLock 
    94117# classes. They are identifiers that will be turned into real Locks later, 
    95118# via the BotMaster.getLockByID method. 
    96119 
    97 class MasterLock(util.ComparableMixin): 
     120class MasterLock(BaseLockId): 
    98121    """I am a semaphore that limits the number of simultaneous actions. 
    99122 
    100123    Builds and BuildSteps can declare that they wish to claim me as they run. 
     
    113136        self.name = name 
    114137        self.maxCount = maxCount 
    115138 
    116 class SlaveLock(util.ComparableMixin): 
     139class SlaveLock(BaseLockId): 
    117140    """I am a semaphore that limits simultaneous actions on each buildslave. 
    118141 
    119142    Builds and BuildSteps can declare that they wish to claim me as they run. 
  • buildbot-0.7.7/buildbot/master.py

    old new  
    2626from buildbot.changes.changes import Change, ChangeMaster 
    2727from buildbot.sourcestamp import SourceStamp 
    2828from buildbot.buildslave import BuildSlave 
    29 from buildbot import interfaces 
     29from buildbot import interfaces, locks 
    3030 
    3131######################################## 
    3232 
     
    209209        @param lockid: a locks.MasterLock or locks.SlaveLock instance 
    210210        @return: a locks.RealMasterLock or locks.RealSlaveLock instance 
    211211        """ 
     212        assert isinstance(lockid, (locks.MasterLock, locks.SlaveLock)) 
    212213        if not lockid in self.locks: 
    213214            self.locks[lockid] = lockid.lockClass(lockid) 
    214215        # if the master.cfg file has changed maxCount= on the lock, the next 
     
    629630 
    630631        # assert that all locks used by the Builds and their Steps are 
    631632        # uniquely named. 
    632         locks = {} 
     633        lock_dict = {} 
    633634        for b in builders: 
    634635            for l in b.get('locks', []): 
    635                 if locks.has_key(l.name): 
    636                     if locks[l.name] is not l: 
     636                if lock_dict.has_key(l.name): 
     637                    if lock_dict[l.name] is not l: 
    637638                        raise ValueError("Two different locks (%s and %s) " 
    638639                                         "share the name %s" 
    639                                          % (l, locks[l.name], l.name)) 
     640                                         % (l, lock_dict[l.name], l.name)) 
    640641                else: 
    641                     locks[l.name] = l 
     642                    lock_dict[l.name] = l 
    642643            # TODO: this will break with any BuildFactory that doesn't use a 
    643644            # .steps list, but I think the verification step is more 
    644645            # important. 
    645646            for s in b['factory'].steps: 
    646647                for l in s[1].get('locks', []): 
    647                     if locks.has_key(l.name): 
    648                         if locks[l.name] is not l: 
     648                    if lock_dict.has_key(l.name): 
     649                        if lock_dict[l.name] is not l: 
    649650                            raise ValueError("Two different locks (%s and %s)" 
    650651                                             " share the name %s" 
    651                                              % (l, locks[l.name], l.name)) 
     652                                             % (l, lock_dict[l.name], l.name)) 
    652653                    else: 
    653                         locks[l.name] = l 
     654                        lock_dict[l.name] = l 
    654655 
    655656        # slavePortnum supposed to be a strports specification 
    656657        if type(slavePortnum) is int: 
  • buildbot-0.7.7/buildbot/util.py

    old new  
    6060        return hash(tuple(alist)) 
    6161 
    6262    def __cmp__(self, them): 
    63         if cmp(type(self), type(them)): 
    64             return cmp(type(self), type(them)) 
    65         if cmp(self.__class__, them.__class__): 
    66             return cmp(self.__class__, them.__class__) 
     63        result = cmp(type(self), type(them)) 
     64        if result: 
     65            return result 
     66 
     67        result = cmp(self.__class__, them.__class__) 
     68        if result: 
     69            return result 
     70 
    6771        assert self.compare_attrs == them.compare_attrs 
    6872        self_list= [getattr(self, name, _None) for name in self.compare_attrs] 
    6973        them_list= [getattr(them, name, _None) for name in self.compare_attrs] 
  • buildbot-0.7.7/docs/buildbot.texinfo

    old new  
    54435443simultaneous builds as there are machines. 
    54445444 
    54455445Each @code{Lock} is created with a unique name. Each lock gets a count 
    5446 of how many owners it may have: how many processes can claim it at ths 
     5446of how many owners it may have: how many processes can claim it at the 
    54475447same time. This limit defaults to one, and is controllable through the 
    54485448@code{maxCount} argument. On @code{SlaveLock}s you can set the owner 
    54495449count on a per-slave basis by providing a dictionary (that maps from 
     
    54935493f.addStep(source.SVN(svnurl="http://example.org/svn/Trunk")) 
    54945494f.addStep(shell.ShellCommand(command="make all")) 
    54955495f.addStep(shell.ShellCommand(command="make test", locks=[db_lock])) 
    5496 b1 = @{'name': 'full1', 'slavename': 'bot-1', builddir='f1', 'factory': f@} 
    5497 b2 = @{'name': 'full2', 'slavename': 'bot-2', builddir='f2', 'factory': f@} 
    5498 b3 = @{'name': 'full3', 'slavename': 'bot-3', builddir='f3', 'factory': f@} 
     5496b1 = @{'name': 'full1', 'slavename': 'bot-1', 'builddir': 'f1', 'factory': f@} 
     5497b2 = @{'name': 'full2', 'slavename': 'bot-2', 'builddir': 'f2', 'factory': f@} 
     5498b3 = @{'name': 'full3', 'slavename': 'bot-3', 'builddir': 'f3', 'factory': f@} 
    54995499c['builders'] = [b1, b2, b3] 
    55005500@end example 
    55015501 
     
    55225522f22 = factory.Trial(source, trialpython=["python2.2"]) 
    55235523f23 = factory.Trial(source, trialpython=["python2.3"]) 
    55245524f24 = factory.Trial(source, trialpython=["python2.4"]) 
    5525 b1 = @{'name': 'p22', 'slavename': 'bot-1', builddir='p22', 'factory': f22
    5526       'locks': [slow_lock] @} 
    5527 b2 = @{'name': 'p23', 'slavename': 'bot-1', builddir='p23', 'factory': f23
    5528       'locks': [slow_lock] @} 
    5529 b3 = @{'name': 'p24', 'slavename': 'bot-1', builddir='p24', 'factory': f24
    5530       'locks': [slow_lock] @} 
     5525b1 = @{'name': 'p22', 'slavename': 'bot-1', 'builddir': 'p22'
     5526      'factory': f22, 'locks': [slow_lock] @} 
     5527b2 = @{'name': 'p23', 'slavename': 'bot-1', 'builddir': 'p23'
     5528      'factory': f23, 'locks': [slow_lock] @} 
     5529b3 = @{'name': 'p24', 'slavename': 'bot-1', 'builddir': 'p24'
     5530      'factory': f24, 'locks': [slow_lock] @} 
    55315531c['builders'] = [b1, b2, b3] 
    55325532@end example 
    55335533 
     
    55555555f.addStep(shell.ShellCommand(command="make test", locks=[cpu_lock])) 
    55565556f.addStep(shell.ShellCommand(command="make db-test", locks=[db_lock, cpu_lock])) 
    55575557 
    5558 b1 = @{'name': 'full1', 'slavename': 'bot-slow', builddir='full1', 
    5559       'factory': f@} 
    5560 b2 = @{'name': 'full2', 'slavename': 'bot-slow', builddir='full2', 
    5561       'factory': f@} 
    5562 b3 = @{'name': 'full3', 'slavename': 'bot-fast', builddir='full3', 
    5563       'factory': f@} 
    5564 b4 = @{'name': 'full4', 'slavename': 'bot-fast', builddir='full4', 
     5558b1 = @{'name': 'full1', 'slavename': 'bot-slow', 'builddir': 'full1', 
     5559      'factory': f@} 
     5560b2 = @{'name': 'full2', 'slavename': 'bot-slow', 'builddir': 'full2', 
     5561      'factory': f@} 
     5562b3 = @{'name': 'full3', 'slavename': 'bot-fast', 'builddir': 'full3', 
     5563      'factory': f@} 
     5564b4 = @{'name': 'full4', 'slavename': 'bot-fast', 'builddir': 'full4', 
    55655565      'factory': f@} 
    55665566c['builders'] = [b1, b2, b3, b4] 
    55675567@end example 
     
    65296529 
    65306530@example 
    65316531from buildbot.status import html 
    6532 w = html.Waterfall(http_port=8080) 
     6532w = html.WebStatus(http_port=8080) 
    65336533c['status'].append(w) 
    65346534@end example 
    65356535