extras-buildsys/builder builder.py,1.11,1.12

Seth Vidal (skvidal) fedora-extras-commits at redhat.com
Sun Jul 10 07:17:16 UTC 2005


Author: skvidal

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

Modified Files:
	builder.py 
Log Message:

- modify builder.py to use optparse for getting cli options
  default behavior now uses -a for adding architectures and checks the archs
  vs the archlist for this host.
- modify the spec file to clean up %description for base package
- modify init script and init script config file for new cli syntax for
  builder



Index: builder.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/builder/builder.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- builder.py	10 Jul 2005 04:48:38 -0000	1.11
+++ builder.py	10 Jul 2005 07:17:14 -0000	1.12
@@ -35,6 +35,7 @@
 from plague import lighttpdManager
 from plague import HTTPServer
 from plague import daemonize
+from optparse import OptionParser
 
 
 # Load in the config
@@ -600,63 +601,50 @@
     state={'opts': True, 'host': None, 'archs': [],
       'daemon': False, 'pidfile': None, 'logfile': None}
 
-    for i in sys.argv[1:]:
-        if state['logfile']=='':
-            state['logfile']=i
-            continue
-        if state['pidfile']=='':
-            state['pidfile']=i
-            continue
-        if i.startswith('-'):
-            if state['opts']:
-                if i=='-d':
-                    state['daemon']=True
-                elif i=='-p':
-                    state['pidfile']=''
-                elif i=='-l':
-                    state['logfile']=''
-                elif i=='--':
-                    state['opts']=False
-                continue
-    if not state['host']:
-        state['host']=i
-    else:
-        state['archs'].append(i)
+    archlist = ""
+    avail_arches = builder_dict.keys()
+    avail_arches.sort()
+    for a in avail_arches:
+        archlist = archlist + a
+        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]
+    parser = OptionParser(usage=usage)
+    parser.add_option("-p", "--pidfile", default=None,
+        help='file to write the PID to')
+    parser.add_option("-l", "--logfile", default=None,
+        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)
+    (opts, args) = parser.parse_args()
 
-    if not state['host'] or not state['archs'] or (state['pidfile']=='') or (state['logfile']==''):
-        print "Usage:\n"
-        print "   %s <hostname> <archlist> [-p <pidfile>] [-l <logfile>] [-d]\n" % sys.argv[0]
-        print "   <hostname> - hostname or IP address of this machine"
-        print "   <archlist> - space-separated list of arches this machine can build"
-        print "   <pidfile> - file to write the PID to"
-        print "   <logfile> - file to write messages to instead of stdout"
-        print "   -d - daemonize (i.e., detach from the terminal)"
-
-        # pretty-print the available archlist
-        archlist = ""
-        avail_arches = builder_dict.keys()
-        avail_arches.sort()
-        for a in avail_arches:
-            archlist = archlist + a
-            if a != avail_arches[len(avail_arches)-1]:
-                archlist = archlist + ", "
-        print "                Available arches: [ %s ]\n" % archlist
+    if len(args) == 0 or len(opts.archs) == 0:
+        print "Must specify hostname and at least one build arch."
         sys.exit(1)
+    
+    for arch in opts.archs:
+        if arch not in archlist:
+            print "Arch must be one of [ %s ]" % archlist
+            sys.exit(1)
+            
+    host = args[0]
+    g_our_hostname = host
+    localarches = opts.archs
 
-    g_our_hostname = state['host']
-    localarches = state['archs']
-
-    if state['daemon']:
+    if opts.daemon:
         ret=daemonize.createDaemon()
         if ret:
             print "Daemonizing failed!"
             sys.exit(2)
 
-    if state['pidfile']:
-        open(state['pidfile'], 'w').write('%d\n' % os.getpid())
+    if opts.pidfile:
+        open(opts.pidfile, 'w').write('%d\n' % os.getpid())
 
-    if state['logfile']:
-        log=open(state['logfile'], 'a')
+    if opts.logfile:
+        log=open(opts.logfile, 'a')
         sys.stdout=log
         sys.stderr=log
 




More information about the fedora-extras-commits mailing list