fix possible path and vdb location issues
authorMarius Mauch <genone@gentoo.org>
Tue, 24 Jan 2006 15:20:58 +0000 (15:20 -0000)
committerMarius Mauch <genone@gentoo.org>
Tue, 24 Jan 2006 15:20:58 +0000 (15:20 -0000)
svn path=/main/trunk/; revision=2581

bin/emaint

index 803b5a72604d7c08940f7440a9566eeb0f202938..4ea4e73b8489a15112f7cdda1c97ec14ae9d1e2c 100755 (executable)
@@ -55,10 +55,10 @@ class VdbKeyHandler(object):
                self.keys = ["HOMEPAGE", "SRC_URI", "KEYWORDS", "DESCRIPTION"]
                
                for p in self.list:
-                       mydir = "/var/db/pkg/"+p
+                       mydir = os.path.join(os.sep, portage.settings["ROOT"], portage_const.VDB_PATH, p)+os.sep
                        ismissing = True
                        for k in self.keys:
-                               if os.path.exists(mydir+"/"+k):
+                               if os.path.exists(mydir+k):
                                        ismissing = False
                                        break
                        if ismissing:
@@ -72,32 +72,33 @@ class VdbKeyHandler(object):
                errors = []
        
                for p in self.missing:
-                       mydir = "/var/db/pkg/"+p
-                       if not os.access(mydir+"/environment.bz2", os.R_OK):
-                               errors.append("Can't access %s" % (mydir+"/environment.bz2"))
+                       mydir = os.path.join(os.sep, portage.settings["ROOT"], portage_const.VDB_PATH, p)+os.sep
+                       if not os.access(mydir+"environment.bz2", os.R_OK):
+                               errors.append("Can't access %s" % (mydir+"environment.bz2"))
                        elif not os.access(mydir, os.W_OK):
                                errors.append("Can't create files in %s" % mydir)
                        else:
-                               env = os.popen("bzip2 -dcq "+mydir+"/environment.bz2", "r")
+                               env = os.popen("bzip2 -dcq "+mydir+"environment.bz2", "r")
                                envlines = env.read().split("\n")
                                env.close()
                                for k in self.keys:
-                                       s = [l for l in envlines if l.strip("\"\'").startswith(k+"=")]
+                                       s = [l for l in envlines if l.startswith(k+"=")]
                                        if len(s) > 1:
-                                               errors.append("multiple matches for %s found in %s/environment.bz2" % (k, mydir))
+                                               errors.append("multiple matches for %s found in %senvironment.bz2" % (k, mydir))
                                        elif len(s) == 0:
                                                s = ""
                                        else:
                                                s = s[0].split("=",1)[1]
                                                s = s.lstrip("$").strip("\'\"")
                                                s = re.sub("(\\\\[nrt])+", " ", s)
-                                               s = re.sub("[\n\r\t]+"," ",s)
-                                               s = re.sub(" +"," ",s)
-                                               s = s.strip()
+                                               s = " ".join(s.split()).strip()
                                                if s != "":
-                                                       keyfile = open(mydir+"/"+k, "w")
-                                                       keyfile.write(s+"\n")
-                                                       keyfile.close()
+                                                       try:
+                                                               keyfile = open(mydir+os.sep+k, "w")
+                                                               keyfile.write(s+"\n")
+                                                               keyfile.close()
+                                                       except (IOError, OSError), e:
+                                                               errors.append("Could not write %s, reason was: %s" % (mydir+k, e))
                
                return errors