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 sendfile(src, dst):
44 def append_to(log, msg):
51 os.system("rm -f %s/* 2>/dev/null; rmdir %s 2>/dev/null" % (dir, dir))
53 def collect_files(log, basedir = "/home"):
55 rx = re.compile(r"^Wrote: (%s.*\.rpm)$" % basedir)
56 proc = re.compile(r"^Processing files:.*$")
58 for l in reversed(list(f)):
63 files.append(m.group(1))
67 def find_last_section(log):
69 rx1 = re.compile(r"^Executing\(%(\w+)\).*$")
70 rx2 = re.compile(r"^Processing (files):.*$")
77 last_section = m.group(1)
81 def cmp_to_key(mycmp):
82 'Convert a cmp= function into a key= function'
84 def __init__(self, obj, *args):
86 def __lt__(self, other):
87 return mycmp(self.obj, other.obj) < 0
88 def __gt__(self, other):
89 return mycmp(self.obj, other.obj) > 0
90 def __eq__(self, other):
91 return mycmp(self.obj, other.obj) == 0
92 def __le__(self, other):
93 return mycmp(self.obj, other.obj) <= 0
94 def __ge__(self, other):
95 return mycmp(self.obj, other.obj) >= 0
96 def __ne__(self, other):
97 return mycmp(self.obj, other.obj) != 0
103 elif type(s) is str or (sys.version_info[0] < 3 and type(s) is unicode):
104 return codecs.encode(s, 'utf-8')
106 raise TypeError("Expected bytes or string, but got %s." % type(s))
110 return codecs.decode(s, 'utf-8')
111 elif type(s) is str or (sys.version_info[0] < 3 and type(s) is unicode):
114 raise TypeError("Expected bytes or string, but got %s." % type(s))