code cleanup
[catalyst.git] / catalyst
index 5211427ddfacf399aefa4da40bdd7282ee1a07e1..070d8a99c9b125f8f3a6a5e0bb89743164c04dc2 100755 (executable)
--- a/catalyst
+++ b/catalyst
@@ -1,19 +1,19 @@
 #!/usr/bin/python
 # Copyright 1999-2004 Gentoo Technologies, Inc.
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/catalyst,v 1.42 2004/07/11 21:25:22 zhen Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/catalyst,v 1.49 2004/10/06 16:00:09 zhen Exp $
 
 # Maintained in full by John Davis <zhen@gentoo.org>
 
 import os,sys,imp,string,getopt
 
 __maintainer__="John Davis <zhen@gentoo.org>"
-__version__="1.0.9"
+__version__="1.1.0"
 
 conf_values={}
 
 def usage():
-       print "Usage catalyst [options] [-C variable=value...]"
+       print "Usage catalyst [options] [-C variable=value...] [ -s identifier]"
        print " -h --help               print this help message"
        print " -v --version            display version information"
        print " -d --debug              enable debugging"
@@ -21,6 +21,18 @@ def usage():
        print " -C --cli                catalyst commandline (MUST BE LAST OPTION)"
        print " -f --file               read specfile"
        print " -V --verbose            verbose output"
+       print " -s --snapshot           generate a Portage snapshot"
+       print
+       print "Usage examples:"
+       print
+       print "Using the commandline option (-C, --cli) to build a Portage snapshot:"
+       print "catalyst -C target=snapshot version_stamp=my_date"
+       print
+       print "Using the snapshot option (-s, --snapshot) to build a Portage snapshot:"
+       print "catalyst -s 2004.3"
+       print
+       print "Using the specfile option (-f, --file) to build a stage target:"
+       print "catalyst -f stage1-specfile.spec"
 
 def version():
        print "Gentoo Catalyst, version "+__version__
@@ -172,8 +184,8 @@ if __name__ == "__main__":
 
        # parse out the command line arguments
        try:
-               opts,args = getopt.getopt(sys.argv[1:], "hvdc:C:f:V", ["help", "version", "debug",\
-                       "config=", "cli=", "file=", "verbose"])
+               opts,args = getopt.getopt(sys.argv[1:], "hvdc:C:f:Vs:", ["help", "version", "debug",\
+                       "config=", "cli=", "file=", "verbose","snapshot="])
        
        except getopt.GetoptError:
                usage()
@@ -185,21 +197,47 @@ if __name__ == "__main__":
        myconfig=""
        myspecfile=""
        mycmdline=[]
+       myopts=[]
+
+       # check preconditions
+       if len(opts) == 0:
+               print "!!! catalyst: please specify one of either -f or -C\n"
+               usage()
+               sys.exit(2)
+       
+       # check to see if -f and -C are used together
+       for i in opts:
+               myopts.append(i[0])
+               
+       if ('-f' in myopts or '--file' in myopts) and ('-C' in myopts or '--cli' in myopts):
+               print "!!! catalyst: please specify one of either -f or -C\n"
+               usage()
+               sys.exit(2)
 
        for o, a in opts:
                if o in ("-h", "--help"):
                        usage()
-                       sys.exit(2)
+                       sys.exit(1)
                
                if o in ("-v", "--version"):
                        print "Catalyst version "+__version__
-                       sys.exit(2)
+                       sys.exit(1)
 
                if o in ("-d", "--debug"):
-                       debug=True
+                       if len(sys.argv) < 3:
+                               print "!!! catalyst: please specify one of either -f or -C\n"
+                               usage()
+                               sys.exit(2)
+                       else:
+                               conf_values["DEBUG"]="1"
 
                if o in ("-c", "--config"):
-                       myconfig=a
+                       if len(sys.argv) < 3:
+                               print "!!! catalyst: please specify one of either -f or -C\n"
+                               usage()
+                               sys.exit(2)
+                       else:
+                               myconfig=a
 
                if o in ("-C", "--cli"):
                        x=sys.argv.index(o)+1
@@ -211,7 +249,21 @@ if __name__ == "__main__":
                        myspecfile=a
                        
                if o in ("-V", "--verbose"):
-                       verbose=True
+                       if len(sys.argv) < 3:
+                               print "!!! catalyst: please specify one of either -f or -C\n"
+                               usage()
+                               sys.exit(2)
+                       else:
+                               conf_values["VERBOSE"]="1"
+
+               if o in ("-s", "--snapshot"):
+                       if len(sys.argv) < 3:
+                               print "!!! catalyst: missing snapshot identifier\n"
+                               usage()
+                               sys.exit(2)
+                       else:
+                               mycmdline.append("target=snapshot")
+                               mycmdline.append("version_stamp="+a)
        
        # import configuration file and import our main module using those settings
        parse_config(myconfig)
@@ -226,9 +278,10 @@ if __name__ == "__main__":
        
        if mycmdline:
                addlargs=do_cli(mycmdline)
-
+       
        # everything is setup, so the build is a go
        try:
                build_target(addlargs, targetmap)
        except:
                print "!!! catalyst: could not complete build"
+               sys.exit(2)