Fix bug 65284. More flexible spec parsing. Should handle cases where no spaces...
authorEric Edgar <rocket@gentoo.org>
Thu, 5 May 2005 21:16:06 +0000 (21:16 +0000)
committerEric Edgar <rocket@gentoo.org>
Thu, 5 May 2005 21:16:06 +0000 (21:16 +0000)
git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/catalyst/trunk@651 d1e1f19c-881f-0410-ab34-b69fee027534

ChangeLog
catalyst
modules/catalyst_support.py

index ec8e67037d8c0ffe930627b63764101c9e0c4f15..60e5ae27d6c7de34f7cbfed57ded7cde7f13edea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 # Copyright 2002-2005 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.256 2005/05/03 15:57:37 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.257 2005/05/05 21:16:06 rocket Exp $
+
+  05 May 2005; Eric Edgar <rocket@gentoo.org> catalyst,
+  modules/catalyst_support.py:
+  Fix bug 65284. More flexible spec parsing. Should handle cases where no
+  spaces are after :. Better handling of comments ( ie preprocessed and
+  stripped off ). Unset empty keys.
 
   03 May 2005; Eric Edgar <rocket@gentoo.org> catalyst,
   targets/support/kill-chroot-pids.sh:
index feb86bec13a655175a9ad0c43af556328e594c39..8c49dd01a42267ef30105a8453e42141e6438919 100755 (executable)
--- a/catalyst
+++ b/catalyst
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # Copyright 1999-2004 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/catalyst,v 1.79 2005/05/03 15:57:37 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/catalyst,v 1.80 2005/05/05 21:16:06 rocket Exp $
 
 # Maintained in full by:
 # Eric Edgar <rocket@gentoo.org>
@@ -349,6 +349,9 @@ if __name__ == "__main__":
        except KeyboardInterrupt:
                print "\nCatalyst build aborted due to user interrupt ( Ctrl-C )"
                sys.exit(2)
+       except KeyError:
+               print "\nproblem with command line or spec file ( Key Error )"
+               sys.exit(2)
        except:
                print "Catalyst aborting ...."
                sys.exit(2)
index a710ce76553a48e37122c9713954ed8421352a0e..3d741ca91f82ddde3d3a6e6e10f6e71e122ed7a6 100644 (file)
@@ -1,6 +1,6 @@
 # Copyright 1999-2004 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/modules/catalyst_support.py,v 1.45 2005/04/27 21:04:02 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/modules/catalyst_support.py,v 1.46 2005/05/05 21:16:06 rocket Exp $
 
 import sys,string,os,types,re,signal,traceback,md5,time
 # a function to turn a string of non-printable characters into a string of
@@ -200,54 +200,72 @@ defined are not preserved. In other words, "foo", "bar", "oni" ordering is prese
 def parse_spec(mylines):
        myspec={}
        pos=0
+       colon_optional_spaces=re.compile(":")
+       trailing_comment=re.compile("#.*\n")
+       newline=re.compile("\n")
+       leading_white_space=re.compile("\s+")
        while pos<len(mylines):
+               # Force the line to be clean 
+               # Remove Comments ( anything following # )
+               mylines[pos]=trailing_comment.sub("",mylines[pos])
+               
+               # Remove newline character \n
+               mylines[pos]=newline.sub("",mylines[pos])
+
+               # Remove leading white space
+               mylines[pos]=leading_white_space.sub("",mylines[pos])
+               
+               # Skip any blank lines
                if len(mylines[pos])<=1:
-                       #skip blanks
                        pos += 1
                        continue
-               if mylines[pos][0] in ["#"," ","\t"]:
-                       #skip indented lines, comments
-                       pos += 1
-                       continue
-               else:
-                       myline=mylines[pos].split()
+               msearch=colon_optional_spaces.search(mylines[pos])
                
-                       if (len(myline)==0) or (myline[0][-1] != ":"):
-                               msg("Skipping invalid spec line "+repr(pos+1))
-                       #strip colon:
-                       myline[0]=myline[0][:-1]
-                       if len(myline)==2:
-                               #foo: bar  --> foo:"bar"
-                               myspec[myline[0]]=myline[1]
-                               pos += 1
-                       elif len(myline)>2:
-                               #foo: bar oni --> foo: [ "bar", "oni" ]
-                               myspec[myline[0]]=myline[1:]
-                               pos += 1
-                       else:
-                               #foo:
-                               # bar
-                               # oni meep
-                               # --> foo: [ "bar", "oni", "meep" ]
-                               accum=[]
-                               pos += 1
-                               while (pos<len(mylines)):
-                                       if len(mylines[pos])<=1:
-                                               #skip blanks
-                                               pos += 1
-                                               continue
-                                       if mylines[pos][0] == "#":
-                                               #skip comments
-                                               pos += 1
-                                               continue
-                                       if mylines[pos][0] in [" ","\t"]:
-                                               #indented line, add to accumulator
-                                               accum.extend(mylines[pos].split())
-                                               pos += 1
+               # If semicolon found assume its a new key
+               # This may cause problems if : are used for key values but works for now
+               if msearch:
+                       # Split on the first semicolon creating two strings in the array mobjs
+                       mobjs = colon_optional_spaces.split(mylines[pos],1)
+                       # Start a new array using the first element of mobjs
+                       newarray=[mobjs[0]]
+                       if mobjs[1]:
+                               # split on white space creating additional array elements
+                               subarray=mobjs[1].split()
+                               if len(subarray)>0:
+                                       
+                                       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.
+                                               newarray.append(subarray[0])
                                        else:
-                                               #we've hit the next item, break out
-                                               break
-                               myspec[myline[0]]=accum
+                                               newarray.append(mobjs[1].split())
+               
+               # Else add on to the last key we were working on
+               else:
+                       myline=mylines[pos].split()
+                       newarray.append(myline)
+                       
+               pos += 1
+               if len(newarray)==2:
+                       myspec[newarray[0]]=newarray[1]
+               else: 
+                       myspec[newarray[0]]=newarray[1:]
+
+       for x in myspec.keys():
+               # Convert myspec[x] to an array of strings
+               newarray=[]
+               if type(myspec[x])!=types.StringType:
+                       for y in myspec[x]:
+                               newarray.append(y[0])
+                       myspec[x]=newarray
+               # Delete empty key pairs
+               if len(myspec[x])==0:
+                       print "\n\tWARNING: No value set for key: "+x
+                       print "\tdeleting key: "+x+"\n"
+                       del myspec[x]
+       
        return myspec
 
 def parse_makeconf(mylines):