]> 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 00816ac48f904a72a184d16ecb2aefd70a9ce679..05cf076753ee6ec6ce8ccc4804bbf4f6b01c256c 100644 (file)
@@ -6,9 +6,28 @@ import os
 import log
 import string
 
+def uuid_python():
+    return str(uuid_random())
+
+def uuid_external():
+    f = os.popen("uuidgen 2>&1")
+    u = f.read().strip()
+    f.close()
+    if len(u) != 36:
+        raise Exception("uuid: fatal, cannot generate uuid: %s" % u)
+    return u
+
+# uuid module available in python >= 2.5
+try:
+    from uuid import uuid4 as uuid_random
+except ImportError:
+    uuid = uuid_external
+else:
+    uuid = uuid_python
+
 def pkg_name(nvr):
     return re.match(r"(.+)-[^-]+-[^-]+", nvr).group(1)
-    
+
 def msg(m):
     sys.stderr.write(m)
 
@@ -30,20 +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 uuid():
-    f = os.popen("uuidgen 2>&1")
-    u = string.strip(f.read())
-    f.close()
-    if len(u) != 36:
-        raise "uuid: fatal, cannot generate uuid: %s" % u
-    return u
-
-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.106056 seconds and 4 git commands to generate.