1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
11 return str(uuid_random())
14 f = os.popen("uuidgen 2>&1")
18 raise Exception("uuid: fatal, cannot generate uuid: %s" % u)
21 # uuid module available in python >= 2.5
23 from uuid import uuid4 as uuid_random
30 return re.match(r"(.+)-[^-]+-[^-]+", nvr).group(1)
35 def append_to(log, msg):
42 os.system("rm -f %s/* 2>/dev/null; rmdir %s 2>/dev/null" % (dir, dir))
44 def collect_files(log, basedir = "/home"):
46 rx = re.compile(r"^Wrote: (%s.*\.rpm)$" % basedir)
47 proc = re.compile(r"^Processing files:.*$")
49 for l in reversed(list(f)):
54 files.append(m.group(1))
58 def find_last_section(log):
60 rx1 = re.compile(r"^Executing\(%(\w+)\).*$")
61 rx2 = re.compile(r"^Processing (files):.*$")
68 last_section = m.group(1)
72 def cmp_to_key(mycmp):
73 'Convert a cmp= function into a key= function'
75 def __init__(self, obj, *args):
77 def __lt__(self, other):
78 return mycmp(self.obj, other.obj) < 0
79 def __gt__(self, other):
80 return mycmp(self.obj, other.obj) > 0
81 def __eq__(self, other):
82 return mycmp(self.obj, other.obj) == 0
83 def __le__(self, other):
84 return mycmp(self.obj, other.obj) <= 0
85 def __ge__(self, other):
86 return mycmp(self.obj, other.obj) >= 0
87 def __ne__(self, other):
88 return mycmp(self.obj, other.obj) != 0
94 elif type(s) is str or (sys.version_info[0] < 3 and type(s) is unicode):
95 return codecs.encode(s, 'utf-8')
97 raise TypeError("Expected bytes or string, but got %s." % type(s))
101 return codecs.decode(s, 'utf-8')
102 elif type(s) is str or (sys.version_info[0] < 3 and type(s) is unicode):
105 raise TypeError("Expected bytes or string, but got %s." % type(s))
108 return (a > b) - (a < b)