extras-buildsys/builder CONFIG.py,1.5,1.6 builder.py,1.13,1.14

Daniel Williams (dcbw) fedora-extras-commits at redhat.com
Wed Jul 13 19:36:08 UTC 2005


Author: dcbw

Update of /cvs/fedora/extras-buildsys/builder
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv16444/builder

Modified Files:
	CONFIG.py builder.py 
Log Message:
2005-07-13  Dan Williams <dcbw at redhat.com>

    * builder/builder.py
      builder/CONFIG.py
      etc/plague-builder.config
      etc/plague-builder.init
        - Move arches and hostname into the CONFIG.py file, since
            its already instance-specific.  Change the initscripts
            to reference the config file, which gets passed
            to the builder on the command line now.




Index: CONFIG.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/builder/CONFIG.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CONFIG.py	6 Jul 2005 21:20:49 -0000	1.5
+++ CONFIG.py	13 Jul 2005 19:36:06 -0000	1.6
@@ -22,6 +22,8 @@
 
 config_opts['fileserver_port'] = 8889
 config_opts['xmlrpc_port'] = 8888
+config_opts['hostname'] = 'localhost'
+config_opts['arches'] = ['i386', 'i486', 'i586', 'i686']
 
 BUILDER_DIR = "/etc/plague/builder"
 


Index: builder.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/builder/builder.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- builder.py	12 Jul 2005 20:12:30 -0000	1.13
+++ builder.py	13 Jul 2005 19:36:06 -0000	1.14
@@ -38,17 +38,9 @@
 from optparse import OptionParser
 
 
-# Load in the config
-execfile("/etc/plague/builder/CONFIG.py")
-
 use_lighttpd = False
 
-g_our_hostname = None
 certs = {}
-certs['key_and_cert'] = config_opts['builder_key_and_cert']
-certs['ca_cert'] = config_opts['ca_cert']
-certs['peer_ca_cert'] = config_opts['ca_cert']
-
 
 def get_url_for_file(file_path):
     """ Return a URL pointing to a particular file in our work dir """
@@ -62,7 +54,7 @@
         method = "https://"
     else:
         method = "http://"
-    full_url = method + g_our_hostname + ":" + port + "/" + file_part
+    full_url = method + config_opts['hostname'] + ":" + port + "/" + file_part
     return urllib.quote(full_url)
 
 
@@ -469,16 +461,16 @@
     return bcp
 
 
-def log(string):
-    if config_opts['debug']:
-        print string
-
 class XMLRPCBuilderServer:
     def __init__(self, localarches):
         self.ids = {} # unique id => awclass instance
         self.localarches = localarches
         self.cur_job = 0
 
+    def log(string):
+        if config_opts['debug']:
+            print string
+
     def process(self):
         # Give jobs some time to update their status and do their thing
         jobid = 0
@@ -490,7 +482,7 @@
 
     def start(self, target, arch, srpm_url):
         if self.cur_job != 0:
-            log("Tried to build '%s' when already buiding something" % srpm_url)
+            self.log("Tried to build '%s' when already buiding something" % srpm_url)
             return 0
 
         cur_time = time.time()
@@ -505,10 +497,10 @@
             self.ids[uniqid] = job
             job.start()
             filename = os.path.basename(srpm_url)
-            log("%s: started %s on %s arch %s at time %d" % (uniqid, filename,
+            self.log("%s: started %s on %s arch %s at time %d" % (uniqid, filename,
                         target, arch, cur_time))
         else:
-            log("%s: Failed request for %s on %s UNSUPPORTED arch %s at time %d" %
+            self.log("%s: Failed request for %s on %s UNSUPPORTED arch %s at time %d" %
                         (uniqid, srpm_url, target, arch, cur_time))
             uniqid = 0
         self.cur_job = uniqid
@@ -609,7 +601,7 @@
         if a != avail_arches[len(avail_arches)-1]:
             archlist = archlist + ", "
 
-    usage = "Usage: %s  [-p <pidfile>] [-l <logfile>] [-d] -a arch1 [-a arch2] <hostname>" % sys.argv[0]
+    usage = "Usage: %s  [-p <pidfile>] [-l <logfile>] [-d] -c <configfile>" % sys.argv[0]
     parser = OptionParser(usage=usage)
     parser.add_option("-p", "--pidfile", default=None,
         help='file to write the PID to')
@@ -617,22 +609,32 @@
         help="location of file to write log output to")
     parser.add_option("-d", "--daemon", default=False, action="store_true",
         help="daemonize (i.e., detach from the terminal)")
-    parser.add_option("-a", "--arch", default=[], action='append', dest='archs',
-        help="archs this machine can build Available arches: [ %s ]" % archlist)
+    parser.add_option("-c", "--configfile", default=None,
+        help="location of the builder config file")
     (opts, args) = parser.parse_args()
 
-    if len(args) == 0 or len(opts.archs) == 0:
-        print "Must specify hostname and at least one build arch."
+    if not opts.configfile:
+        print "Must specify the config file."
         sys.exit(1)
-    
-    for arch in opts.archs:
+
+    if not os.path.exists(opts.configfile):
+        print "Could not find the config file %s" % opts.configfile
+        sys.exit(1)
+
+    if not os.access(opts.configfile, os.R_OK):
+        print "Could not read the config file %s" % opts.configfile
+        sys.exit(1)
+
+    # Load in the config
+    execfile(opts.configfile)
+    certs['key_and_cert'] = config_opts['builder_key_and_cert']
+    certs['ca_cert'] = config_opts['ca_cert']
+    certs['peer_ca_cert'] = config_opts['ca_cert']
+
+    for arch in config_opts['arches']:
         if arch not in archlist:
-            print "Arch must be one of [ %s ]" % archlist
+            print "Arch '%s' must be one of [ %s ]" % (arch, archlist)
             sys.exit(1)
-            
-    host = args[0]
-    g_our_hostname = host
-    localarches = opts.archs
 
     if opts.daemon:
         ret=daemonize.createDaemon()
@@ -644,9 +646,9 @@
         open(opts.pidfile, 'w').write('%d\n' % os.getpid())
 
     if opts.logfile:
-        log=open(opts.logfile, 'a')
-        sys.stdout=log
-        sys.stderr=log
+        logf=open(opts.logfile, 'a')
+        sys.stdout=logf
+        sys.stderr=logf
 
     work_dir = config_opts['builder_work_dir']
     if not os.path.exists(work_dir) or not os.access(work_dir, os.R_OK):
@@ -662,12 +664,12 @@
             key_and_cert = config_opts['builder_key_and_cert']
         else:
             key_and_cert = None
-        http_server = lighttpdManager.lighttpdManager(http_cnf_file, g_our_hostname, port, work_dir, True, key_and_cert)
+        http_server = lighttpdManager.lighttpdManager(http_cnf_file, config_opts['hostname'], port, work_dir, True, key_and_cert)
     else:
         if config_opts['ssl_buildserver']:
-            http_server = HTTPServer.PlgHTTPServerManager((g_our_hostname, port), work_dir, certs)
+            http_server = HTTPServer.PlgHTTPServerManager((config_opts['hostname'], port), work_dir, certs)
         else:
-            http_server = HTTPServer.PlgHTTPServerManager((g_our_hostname, port), work_dir, None)
+            http_server = HTTPServer.PlgHTTPServerManager((config_opts['hostname'], port), work_dir, None)
     http_server.start()
 
     # Stop running as root
@@ -676,19 +678,19 @@
         time.sleep(1)
         os._exit(1)
 
-    print "Binding to address '%s' with arches: [%s]" % (g_our_hostname, string.join(localarches))
+    print "Binding to address '%s' with arches: [%s]" % (config_opts['hostname'], string.join(config_opts['arches']))
     xmlrpc_port = config_opts['xmlrpc_port']
     try:
         if config_opts['ssl_buildserver']:
-            xmlserver = AuthedXMLRPCServer.AuthedSSLXMLRPCServer((g_our_hostname, xmlrpc_port), None, certs)
+            xmlserver = AuthedXMLRPCServer.AuthedSSLXMLRPCServer((config_opts['hostname'], xmlrpc_port), None, certs)
         else:
-            xmlserver = AuthedXMLRPCServer.AuthedXMLRPCServer((g_our_hostname, xmlrpc_port), None)
+            xmlserver = AuthedXMLRPCServer.AuthedXMLRPCServer((config_opts['hostname'], xmlrpc_port), None)
     except socket.error, e:
         if e[0] == 98:
-            print "Error: couldn't bind to address '%s:%s'.  Is the builder already running?" % (g_our_hostname, xmlrpc_port)
+            print "Error: couldn't bind to address '%s:%s'.  Is the builder already running?" % (config_opts['hostname'], xmlrpc_port)
             os._exit(1)
 
-    bcs = XMLRPCBuilderServer(localarches)
+    bcs = XMLRPCBuilderServer(config_opts['arches'])
     xmlserver.register_instance(bcs)
 
     last_time = time.time()
@@ -706,5 +708,8 @@
             last_time = time.time()
 
     http_server.stop()
-    time.sleep(2)
+    try:
+        time.sleep(2)
+    except KeyboardInterrupt, e:
+        pass
     os._exit(0)




More information about the fedora-extras-commits mailing list