]> git.pld-linux.org Git - projects/pld-builder.new.git/blobdiff - PLD_Builder/util.py
- more python 3.x fixes
[projects/pld-builder.new.git] / PLD_Builder / util.py
index b79921fbffc2650ab854004a40e78877940680b7..05cf076753ee6ec6ce8ccc4804bbf4f6b01c256c 100644 (file)
@@ -7,19 +7,19 @@ import log
 import string
 
 def uuid_python():
-    return uuid.uuid4()
+    return str(uuid_random())
 
 def uuid_external():
     f = os.popen("uuidgen 2>&1")
-    u = string.strip(f.read())
+    u = f.read().strip()
     f.close()
     if len(u) != 36:
-        raise "uuid: fatal, cannot generate uuid: %s" % u
+        raise Exception("uuid: fatal, cannot generate uuid: %s" % u)
     return u
 
 # uuid module available in python >= 2.5
 try:
-    import uuid
+    from uuid import uuid4 as uuid_random
 except ImportError:
     uuid = uuid_external
 else:
@@ -27,7 +27,7 @@ else:
 
 def pkg_name(nvr):
     return re.match(r"(.+)-[^-]+-[^-]+", nvr).group(1)
-    
+
 def msg(m):
     sys.stderr.write(m)
 
@@ -49,12 +49,49 @@ def clean_tmp(dir):
     # FIXME: use python
     os.system("rm -f %s/* 2>/dev/null; rmdir %s 2>/dev/null" % (dir, dir))
 
-def collect_files(log):
-    f = open(log)
-    rx = re.compile(r"^Wrote: (/home.*\.rpm)$")
+def collect_files(log, basedir = "/home"):
+    f = open(log, 'r')
+    rx = re.compile(r"^Wrote: (%s.*\.rpm)$" % basedir)
+    proc = re.compile(r"^Processing files:.*$")
     files = []
-    for l in f.xreadlines():
+    for l in reversed(list(f)):
+        if proc.match(l):
+            break
         m = rx.search(l)
         if m:
             files.append(m.group(1))
+    f.close()
     return files
+
+def find_last_section(log):
+    f = open(log, 'r')
+    rx1 = re.compile(r"^Executing\(%(\w+)\).*$")
+    rx2 = re.compile(r"^Processing (files):.*$")
+    last_section = None
+    for l in f:
+        m = rx1.search(l)
+        if not m:
+            m = rx2.search(l)
+        if m:
+            last_section = m.group(1)
+    f.close()
+    return last_section
+
+def cmp_to_key(mycmp):
+    'Convert a cmp= function into a key= function'
+    class K:
+        def __init__(self, obj, *args):
+            self.obj = obj
+        def __lt__(self, other):
+            return mycmp(self.obj, other.obj) < 0
+        def __gt__(self, other):
+            return mycmp(self.obj, other.obj) > 0
+        def __eq__(self, other):
+            return mycmp(self.obj, other.obj) == 0
+        def __le__(self, other):
+            return mycmp(self.obj, other.obj) <= 0
+        def __ge__(self, other):
+            return mycmp(self.obj, other.obj) >= 0
+        def __ne__(self, other):
+            return mycmp(self.obj, other.obj) != 0
+    return K
This page took 0.123007 seconds and 4 git commands to generate.