Add a new parse_use_local_desc() function.
authorZac Medico <zmedico@gentoo.org>
Sun, 2 Jul 2006 06:24:36 +0000 (06:24 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 2 Jul 2006 06:24:36 +0000 (06:24 -0000)
svn path=/main/trunk/; revision=3748

bin/repoman

index ebd3882a56cc29e2d1f0126489e6b6cef31027b1..59fbb2713fb9f03a6b34b2c7551baf00c4b6a414 100755 (executable)
@@ -523,20 +523,34 @@ if "--pretend" in myoptions:
 elif quiet < 1:
        print green("\nRepoMan scours the neighborhood...")
 
+def parse_use_local_desc(mylines, usedict=None):
+       """returns a dict of the form {cpv:set(flags)}"""
+       if usedict is None:
+               usedict = {}
+       lineno = 0
+       for l in mylines:
+               lineno += 1
+               if not l or l.startswith("#"):
+                       continue
+               mysplit = l.split(None, 1)
+               if not mysplit:
+                       continue
+               mysplit = mysplit[0].split(":")
+               if len(mysplit) != 2:
+                       raise ParseError("line %d: Malformed input: '%s'" % \
+                               (lineno, l.rstrip("\n")))
+               usedict.setdefault(mysplit[0], set())
+               usedict[mysplit[0]].add(mysplit[1])
+       return usedict
+
 # retreive local USE list
 luselist={}
 try:
-       mylist=portage.grabfile(portdir+"/profiles/use.local.desc")
-       for mypos in range(0,len(mylist)):
-               mysplit=mylist[mypos].split()[0]
-               myuse=string.split(mysplit,":")
-               if len(myuse)==2:
-                       if not luselist.has_key(myuse[0]):
-                               luselist[myuse[0]] = []
-                       luselist[myuse[0]].append(myuse[1])
-except SystemExit, e:
-       raise  # Need to propogate this
-except:
+       f = open(os.path.join(portdir, "profiles", "use.local.desc"))
+       parse_use_local_desc(f, luselist)
+       f.close()
+except (IOError, OSError, ParseError), e:
+       print >> sys.stderr, str(e)
        err("Couldn't read from use.local.desc")
 
 # setup a uselist from portage