Ticket #87: custombuildproperties.diff

File custombuildproperties.diff, 9.1 kB (added by rochg, 1 year ago)

Original custom build properties patch from Paul Gain

  • buildbot/status/html.py

    old new  
    538538                           "<input type='text' name='branch' />") 
    539539                + make_row("Revision to build:", 
    540540                           "<input type='text' name='revision' />") 
     541                + self.make_user_defined_rows() 
     542 
    541543                + """ 
    542544                <input type='submit' value='Force Build' /> 
    543545                </form> 
     
    560562 
    561563        return data 
    562564 
     565    # Providing the users custom properties are set in the master.cfg file 
     566    # this method will generate custom widgets (text fields, radio buttons and 
     567    # check boxes) for the slave build page. The method returns a html string 
     568    # representing the widgets. This string is added to the body of the slave 
     569    # build page. 
     570    def make_user_defined_rows(self): 
     571        userDefRows = name = type = label = value = "" 
     572        customBuildProperties = self.status.getCustomBuildProperties()    
     573        for properties in customBuildProperties: 
     574            name = properties['propertyName'] 
     575            type = properties['propertyType'] 
     576            label = properties['propertyLabel']                
     577            if type == 'radio':                
     578                value = properties['groupValue'] 
     579                field = "<input type=" + "\'" + type + "\'" + "name=" + "\'" + \ 
     580                                name + "\'" + "value=" + "\'" + value + "\'" + " />" 
     581            else: 
     582                field = "<input type=" + "\'" + type + "\'" +  \ 
     583                                "name=" + "\'" + name + "\'" + " />" 
     584 
     585            userDefRows += make_row(label, field) 
     586            name = type = label = value = "" 
     587 
     588        return userDefRows 
     589 
    563590    def force(self, request): 
    564591        name = request.args.get("username", ["<unknown>"])[0] 
    565592        reason = request.args.get("comments", ["<no reason specified>"])[0] 
    566593        branch = request.args.get("branch", [""])[0] 
    567594        revision = request.args.get("revision", [""])[0] 
    568595 
     596        # Custom properties. 
     597        custom_props = {}           
     598        forceBuildProperties = self.status.getCustomBuildProperties()    
     599        for dict in forceBuildProperties: 
     600            for key, value in dict.iteritems():              
     601               if key == 'propertyName': 
     602                   custom_props[value] = request.args.get(value, [""])[0] 
     603 
    569604        r = "The web-page 'force build' button was pressed by '%s': %s\n" \ 
    570605            % (name, reason) 
    571606        log.msg("web forcebuild of builder '%s', branch='%s', revision='%s'" 
     
    593628        # button, use their name instead of None, so they'll be informed of 
    594629        # the results. 
    595630        s = SourceStamp(branch=branch, revision=revision) 
    596         req = BuildRequest(r, s, self.builder.getName()) 
     631        req = BuildRequest(r, s, custom_props, self.builder.getName()) 
    597632        try: 
    598633            self.control.requestBuildSoon(req) 
    599634        except interfaces.NoSlaveError: 
  • buildbot/status/builder.py

    old new  
    17771777        return self.botmaster.parent.projectURL 
    17781778    def getBuildbotURL(self): 
    17791779        return self.botmaster.parent.buildbotURL 
     1780    def getCustomBuildProperties(self): 
     1781     return self.botmaster.parent.customBuildProperties 
    17801782 
    17811783    def getURLForThing(self, thing): 
    17821784        prefix = self.getBuildbotURL() 
  • buildbot/process/base.py

    old new  
    3939                  provide this, but for forced builds the user requesting the 
    4040                  build will provide a string. 
    4141 
     42    @type custom_props: dictionary. 
     43    @ivar custom_props: custom user properties. 
     44 
    4245    @ivar status: the IBuildStatus object which tracks our status 
    4346 
    4447    @ivar submittedAt: a timestamp (seconds since epoch) when this request 
     
    4952    source = None 
    5053    builder = None 
    5154    startCount = 0 # how many times we have tried to start this build 
     55    custom_props = {} 
    5256 
    5357    if implements: 
    5458        implements(interfaces.IBuildRequestControl) 
    5559    else: 
    5660        __implements__ = interfaces.IBuildRequestControl, 
    5761 
    58     def __init__(self, reason, source, builderName=None): 
     62    def __init__(self, reason, source, custom_props, builderName=None): 
    5963        # TODO: remove the =None on builderName, it is there so I don't have 
    6064        # to change a lot of tests that create BuildRequest objects 
    6165        assert interfaces.ISourceStamp(source, None) 
    6266        self.reason = reason 
    6367        self.source = source 
     68        self.custom_props = custom_props 
    6469        self.start_watchers = [] 
    6570        self.finish_watchers = [] 
    6671        self.status = BuildRequestStatus(source, builderName) 
     
    8792        self.finish_watchers.append(d) 
    8893        return d 
    8994 
     95    def customProps(self): 
     96     return self.custom_props; 
     97 
    9098    # these are called by the Builder 
    9199 
    92100    def requestSubmitted(self, builder): 
     
    175183        self.source = requests[0].mergeWith(requests[1:]) 
    176184        self.reason = requests[0].mergeReasons(requests[1:]) 
    177185 
     186        # Set custom properties. 
     187        self.custom_properties = requests[0].customProps() 
     188 
    178189        #self.abandoned = False 
    179190 
    180191        self.progress = None 
     
    269280        self.setProperty("buildnumber", self.build_status.number) 
    270281        self.setProperty("branch", self.source.branch) 
    271282        self.setProperty("revision", self.source.revision) 
     283        cp = self.custom_properties 
     284        for key,userProp in cp.iteritems(): 
     285         self.setProperty(key,userProp) 
    272286 
    273287    def setupSlaveBuilder(self, slavebuilder): 
    274288        self.slavebuilder = slavebuilder 
  • buildbot/master.py

    old new  
    543543    projectURL = None 
    544544    buildbotURL = None 
    545545    change_svc = None 
     546    customBuildProperties = None 
    546547 
    547548    def __init__(self, basedir, configFileName="master.cfg"): 
    548549        service.MultiService.__init__(self) 
     
    694695 
    695696        known_keys = "bots sources schedulers builders slavePortnum " + \ 
    696697                     "debugPassword manhole " + \ 
    697                      "status projectName projectURL buildbotURL" 
     698                     "status projectName projectURL buildbotURL " + \ 
     699                     "customBuildProperties" 
    698700        known_keys = known_keys.split() 
    699701        for k in config.keys(): 
    700702            if k not in known_keys: 
     
    715717            projectName = config.get('projectName') 
    716718            projectURL = config.get('projectURL') 
    717719            buildbotURL = config.get('buildbotURL') 
     720            customBuildProperties = config.get('customBuildProperties') 
    718721 
    719722        except KeyError, e: 
    720723            log.msg("config dictionary is missing a required parameter") 
     
    818821        self.projectName = projectName 
    819822        self.projectURL = projectURL 
    820823        self.buildbotURL = buildbotURL 
     824        self.customBuildProperties = customBuildProperties 
    821825 
    822826        # self.bots: Disconnect any that were attached and removed from the 
    823827        # list. Update self.checker with the new list of passwords, 
  • buildbot/scripts/sample.cfg

    old new  
    173173# without some help. 
    174174 
    175175c['buildbotURL'] = "http://localhost:8010/" 
     176 
     177###### CUSTOM BUILD PROPERTIES FOR THE SLAVE BUILD PAGE. 
     178 
     179""" 
     180textField = {'propertyName' : 'text_field', 
     181             'propertyType' : 'text', 
     182             'propertyLabel': 'Text Label', 
     183             } 
     184 
     185checkBox = {'propertyName' : 'check_box', 
     186            'propertyType' : 'checkbox', 
     187            'propertyLabel': 'Check Box', 
     188            } 
     189 
     190radio1 = {'propertyName' : 'radio_group', 
     191          'propertyType' : 'radio', 
     192          'propertyLabel': 'Male', 
     193          'groupValue'   : 'm', 
     194          } 
     195 
     196radio2 = {'propertyName' : 'radio_group', 
     197          'propertyType' : 'radio', 
     198          'propertyLabel': 'Female', 
     199          'groupValue'   : 'f', 
     200          } 
     201 
     202c['customBuildProperties'] = [textField, checkBox, radio1, radio2] 
     203"""