2012-12-04 22 views
1

對一些解釋進行編輯:buildbot是一個可以通過web界面控制的python中的持續集成系統。在此Web界面中,您有一個「瀑布」頁面,您可以在其中選擇特定的構建器並使用「強制構建」按鈕觸發構建。奇怪的b​​uildbot python行爲

網址:http://trac.buildbot.net/

背景:我們助洗劑是連續的簇(檢查每隔幾分鐘,如果發生了變化,如果是,重建)或夜間(建每天晚上)。我們的系統到目前爲止只有一個特定企業建設者項目。這是通過強制每個項目都必須在一個恆定的URL下找到像

https://myrepositioryurl/{$projectname}. 

然後,當一個項目需要您需要選擇一個項目XYZ企業構建和buildbot假定項目需要檢查出完成在

https://myrepositioryurl/{$projectname}. 

這是非常嚴格的,我想重新配置項目可以在不同的URL下的buildbot。在由「buildbot start master」啓動的構建器的設置過程中,我們項目的配置文件被讀取並存儲在ConfigParser對象中。在下面的源代碼中,它是clzoptions var und我想要使用的URL應該是

https://mytesturl/XYZ. 

對於項目XYZ。 我現在在測試項目的「svnBaseURL」條目下添加了我的不同URL。現在我遇到了一些我在創建構建器的python類中不太明白的東西。首先來源:

import os 
import logging 

from xcodebuild import xcodebuild 
from projects import Projects 

from buildbot.config import BuilderConfig 
from buildbot.process.factory import BuildFactory 
from buildbot.steps.source import SVN 
from buildbot.steps.shell import ShellCommand, WithProperties 
from buildbot.process.properties import Property 


class builders(object): 
    clzoptions = Projects().options 


    def __init__(self): 
     aProject = Projects() 
     self.options = aProject.options 


    def enterprise_checkout_url(self, curProjectName): 
     return curProjectName 

    def create_enterprise_builder(self): 
     factory = BuildFactory() 
     factory.addStep(ShellCommand(name='svn checkout', 
            haltOnFailure=True, 
            description='svn checkout', 
            descriptionDone='svn checkout done', 
            command=['svn', 'checkout', '--username', 'admin', self.enterprise_checkout_url(WithProperties('%(project)s')), '.'])) 



     builderConfig = BuilderConfig(name="foobuilder", 
             category="OnDemand", 
             slavenames=[ "buildslave01" ], 
             factory=factory) 
     return builderConfig 



    def get_all_builders(self): 
     builders = [] 

     builders.append(self.create_enterprise_builder()) 

     return builders 

我把它融化到了核心問題,裏面還有更多的建設者。關鍵功能是self.enterprise_checkout_url(WithProperties('%(project)s'))。

如果我呼籲在瀑布項目名稱「XYZ」是建設者,我得到的結果

svn checkout --username admin XYZ . 

的ShellCommand。雖然這是無意義的,因爲它不是一個URL,我看到 參數curProjectName的計算結果爲「XYZ」。 到目前爲止,對嗎?現在,讓我們改變功能...

def enterprise_checkout_url(self, curProjectName): 
    return builders.clzoptions.get("XYZ", "svnBaseURL")) 

,並得到

svn checkout --username admin https://mytesturl/XYZ . 

這幾乎是我需要的東西,

https://mytesturl/XYZ 

是正確的道路。但關鍵是不變的,我需要它是可變的。但至少我知道字典存在並且具有XYZ的正確條目。

現在的問題,我根本不明白。

讓我們現在就來試試

def enterprise_checkout_url(self, curProjectName): 
     return builders.clzoptions.get(curProjectName, "svnBaseURL")) 

和哎呀,他不建

ConfigParser.NoSectionError: No section: <buildbot.process.properties.WithProperties instance at 0x1073739e0> 

好,編譯階段curProjectName內不得設置,怎麼樣:

def enterprise_checkout_url(self, curProjectName): 
    projects = builders.clzoptions.sections() 
    for project in projects: 
     if project == curProjectName: 
     return builders.clzoptions.get(project, "svnBaseURL") 

編譯。 我得到我所有的項目,測試如果curProjectName是正確的,然後返回我的svnBaseURL與應該等於curProjectName的項目鍵。 但我得到:

<type 'exceptions.TypeError'>: 'NoneType' object is not iterable 

輪到你了。我試圖在curProjectName上使用str(),repr(),eval(),但無濟於事。我無法訪問現有字典和curProjectName。

+0

你好。你說什麼樣的指導你「稱呼建設者」? – eyquem

+0

所有構建命令都由瀑布顯示中的Web UI啓動。我輸入項目名稱,然後按「強制構建」。 –

+0

什麼是瀑布? – eyquem

回答

1

這對你有幫助嗎?

class builders(object): 

    builders = [] 
    print 'id of buiders just created ==',id(builders) 

    def __init__(self,x): 
     self.the = x 

    def enterprise_checkout_url(self, curProjectName): 
     return curProjectName 

    def create_enterprise_builder(self,yy): 
     builderConfig = dict(descriptionDone='-SVN-', 
          command=yy) 
     return builderConfig 

    def get_all_builders(self): 
     print 'id of builders inside get_all_builders ==',id(builders) 
     print 'id of builders.builders inside get_all_builders ==',id(builders.builders) 

     builders.builders.append(self.create_enterprise_builder((self.the))) 

     return builders.builders 

print 'id of class builders ==',id(builders) 
print '\n################################\n' 

b = builders('BOF') 
print b.get_all_builders() 

print '\n=================================\n' 

b2 = builders('MOTO') 
print b2.get_all_builders() 

結果

id of buiders just created == 18709040 
id of class builders == 13819408 

################################ 

id of builders inside get_all_builders == 13819408 
id of builders.builders inside get_all_builders == 18709040 
[{'descriptionDone': '-SVN-', 'command': 'BOF'}] 

================================= 

id of builders inside get_all_builders == 13819408 
id of builders.builders inside get_all_builders == 18709040 
[{'descriptionDone': '-SVN-', 'command': 'BOF'}, {'descriptionDone': '-SVN-', 'command': 'MOTO'}] 

編輯

療法是我的代碼有問題。
如果指令print b2.get_all_builders()被執行兩次,結果是

id of buiders just created == 18709040 
id of class builders == 13819408 

################################ 

id of builders inside get_all_builders == 13819408 
id of builders.builders inside get_all_builders == 18709040 
[{'descriptionDone': '-SVN-', 'command': 'BOF'}] 

================================= 

id of builders inside get_all_builders == 13819408 
id of builders.builders inside get_all_builders == 18709040 
[{'descriptionDone': '-SVN-', 'command': 'BOF'}, {'descriptionDone': '-SVN-', 'command': 'MOTO'}] 

id of builders inside get_all_builders == 13819408 
id of builders.builders inside get_all_builders == 18709040 
[{'descriptionDone': '-SVN-', 'command': 'BOF'}, {'descriptionDone': '-SVN-', 'command': 'MOTO'}, {'descriptionDone': '-SVN-', 'command': 'MOTO'}] 

其中一個字典的出現兩次。

由於我不太清楚你的問題,我不確定你想要什麼,我不知道如何改正它