Rename catalyst.spec to catalyst.util
authoragaffney <agaffney@kagome.(none)>
Sat, 6 Sep 2008 18:09:06 +0000 (13:09 -0500)
committeragaffney <agaffney@kagome.(none)>
Sat, 6 Sep 2008 18:09:06 +0000 (13:09 -0500)
Move spec_dump() into spec class
Modify catalyst to use new spec class

ChangeLog
catalyst
modules/catalyst/util.py [moved from modules/catalyst/spec.py with 95% similarity]
modules/catalyst_support.py

index bf5590bdffcb9cc2a64f66a7766a526a03c7960f..271dc913506d11bf3e1f0a590b1255719e5bc08c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,12 @@
 # Copyright 2002-2008 Gentoo Foundation; Distributed under the GPL v2
 # $Id: $
 
+  06 Sep 2008; Andrew Gaffney <agaffney@gentoo.org> catalyst,
+  -modules/catalyst/spec.py, +modules/catalyst/util.py,
+  modules/catalyst_support.py:
+  Rename catalyst.spec to catalyst.util Move spec_dump() into spec class
+  Modify catalyst to use new spec class
+
   06 Sep 2008; Andrew Gaffney <agaffney@gentoo.org> catalyst,
   +modules/catalyst/__init__.py:
   Add __init__.py file and import line
index baf29e462b6baf58b265b2df54d70ee23de70379..9ea67459c6b7e62e6341b48064d398001f60a510 100755 (executable)
--- a/catalyst
+++ b/catalyst
@@ -9,7 +9,7 @@ import pdb
 
 sys.path.append("./modules")
 
-from catalyst.spec import spec
+import catalyst
 
 __maintainer__="Chris Gianelloni <wolf31o2@gentoo.org>"
 __version__="2.0.6"
@@ -191,14 +191,6 @@ def import_modules():
 
        return targetmap
 
-def do_spec(myspecfile):
-       try:
-               addlargs=read_spec(myspecfile)
-       except:
-               sys.exit(1)
-               
-       return addlargs
-
 def do_cli(cmdline):
        try:
                return arg_parse(cmdline)
@@ -389,7 +381,8 @@ if __name__ == "__main__":
        addlargs={}
        
        if myspecfile:
-               addlargs.update(do_spec(myspecfile))
+               spec = catalyst.util.spec(myspecfile)
+               addlargs.update(spec.get_values())
        
        if mycmdline:
                addlargs.update(do_cli(mycmdline))
similarity index 95%
rename from modules/catalyst/spec.py
rename to modules/catalyst/util.py
index ba726bf038853588e96ddbd632a6c7fcae5d3b91..c637aea3ba48c4d5942546bb12d0cc5e286b9fb6 100644 (file)
@@ -14,6 +14,11 @@ class spec:
        def get_values(self):
                return self.values
 
+       def dump(self):
+               dump = ""
+               for x in self.values.keys():
+                       dump += x + ": " + repr(self.values[x]) + "\n"
+
        def load(self, filename):
                self.filename = filename
                try:
index d8e1ac3927461170be0e73dd87b7a75441e580a3..b402beed7312b82ae04f0d89d39c6b61bd1cfb4e 100644 (file)
@@ -593,68 +593,6 @@ defined are not preserved. In other words, "foo", "bar", "oni" ordering is prese
 "item2" "item3" ordering is not, as the item strings are stored in a dictionary (hash).
 """
 
-def parse_spec(mylines):
-       myspec = {}
-       cur_array = []
-       trailing_comment=re.compile("#.*$")
-       white_space=re.compile("\s+")
-       while len(mylines):
-               myline = mylines.pop(0).strip()
-
-               # Force the line to be clean 
-               # Remove Comments ( anything following # )
-               myline = trailing_comment.sub("", myline)
-
-               # Skip any blank lines
-               if not myline: continue
-
-               # Look for colon
-               msearch = myline.find(':')
-               
-               # If semicolon found assume its a new key
-               # This may cause problems if : are used for key values but works for now
-               if msearch != -1:
-                       # Split on the first semicolon creating two strings in the array mobjs
-                       mobjs = myline.split(':', 1)
-                       mobjs[1] = mobjs[1].strip()
-
-                       # Check that this key doesn't exist already in the spec
-                       if myspec.has_key(mobjs[0]):
-                               raise Exception("You have a duplicate key (" + mobjs[0] + ") in your spec. Please fix it")
-
-                       # Start a new array using the first element of mobjs
-                       cur_array = [mobjs[0]]
-                       if mobjs[1]:
-                               # split on white space creating additional array elements
-                               subarray = white_space.split(mobjs[1])
-                               if subarray:
-                                       if len(subarray)==1:
-                                               # Store as a string if only one element is found.
-                                               # this is to keep with original catalyst behavior 
-                                               # eventually this may go away if catalyst just works
-                                               # with arrays.
-                                               cur_array.append(subarray[0])
-                                       else:
-                                               cur_array += subarray
-               
-               # Else add on to the last key we were working on
-               else:
-                       mobjs = white_space.split(myline)
-                       cur_array += mobjs
-               
-               # XXX: Do we really still need this "single value is a string" behavior?
-               if len(cur_array) == 2:
-                       myspec[cur_array[0]] = cur_array[1]
-               else:
-                       myspec[cur_array[0]] = cur_array[1:]
-       
-       for x in myspec.keys():
-               # Delete empty key pairs
-               if not myspec[x]:
-                       print "\n\tWARNING: No value set for key " + x + "...deleting"
-                       del myspec[x]
-       return myspec
-
 def parse_makeconf(mylines):
        mymakeconf={}
        pos=0
@@ -677,15 +615,6 @@ def parse_makeconf(mylines):
                            mymakeconf[mobj.group(1)]=clean_string
        return mymakeconf
 
-def read_spec(myspecfile):
-       try:
-               myf=open(myspecfile,"r")
-       except:
-               raise CatalystError, "Could not open spec file "+myspecfile
-       mylines=myf.readlines()
-       myf.close()
-       return parse_spec(mylines)
-
 def read_makeconf(mymakeconffile):
        if os.path.exists(mymakeconffile):
                try:
@@ -764,10 +693,6 @@ def addl_arg_parse(myspec,addlargs,requiredspec,validspec):
                if not myspec.has_key(x):
                        raise CatalystError, "Required argument \""+x+"\" not specified."
        
-def spec_dump(myspec):
-       for x in myspec.keys():
-               print x+": "+repr(myspec[x])
-
 def touch(myfile):
        try:
                myf=open(myfile,"w")