]> git.pld-linux.org Git - projects/pld-builder.new.git/blame - PLD_Builder/util.py
Fix iterators assumptions that are no longer valid in python3
[projects/pld-builder.new.git] / PLD_Builder / util.py
CommitLineData
dfff8bd5
MM
1# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
b03a96bc
MM
3import re
4import sys
c8782384
MM
5import os
6import log
bdc3292c
MM
7import string
8
8f84e84d
AM
9def uuid_python():
10 return str(uuid_random())
11
2037736d
AM
12def uuid_external():
13 f = os.popen("uuidgen 2>&1")
14 u = string.strip(f.read())
15 f.close()
16 if len(u) != 36:
939af6d7 17 raise Exception, "uuid: fatal, cannot generate uuid: %s" % u
2037736d
AM
18 return u
19
20# uuid module available in python >= 2.5
21try:
8f84e84d 22 from uuid import uuid4 as uuid_random
2037736d
AM
23except ImportError:
24 uuid = uuid_external
8f84e84d
AM
25else:
26 uuid = uuid_python
2037736d 27
b03a96bc 28def pkg_name(nvr):
dfff8bd5 29 return re.match(r"(.+)-[^-]+-[^-]+", nvr).group(1)
e6376553 30
b03a96bc 31def msg(m):
dfff8bd5 32 sys.stderr.write(m)
c8782384
MM
33
34def sendfile(src, dst):
dfff8bd5
MM
35 cnt = 0
36 while 1:
37 s = src.read(10000)
38 if s == "": break
39 cnt += len(s)
40 dst.write(s)
41 return cnt
c8782384
MM
42
43def append_to(log, msg):
dfff8bd5
MM
44 f = open(log, "a")
45 f.write("%s\n" % msg)
46 f.close()
c8782384
MM
47
48def clean_tmp(dir):
dfff8bd5
MM
49 # FIXME: use python
50 os.system("rm -f %s/* 2>/dev/null; rmdir %s 2>/dev/null" % (dir, dir))
c8782384 51
a73fab54 52def collect_files(log, basedir = "/home"):
2b9e7381 53 f = open(log, 'r')
a73fab54 54 rx = re.compile(r"^Wrote: (%s.*\.rpm)$" % basedir)
43c984a8 55 proc = re.compile(r"^Processing files:.*$")
dfff8bd5 56 files = []
8b63d7eb 57 for l in reversed(list(f)):
7a454cb5
AM
58 if proc.match(l):
59 break
dfff8bd5
MM
60 m = rx.search(l)
61 if m:
62 files.append(m.group(1))
2b9e7381 63 f.close()
dfff8bd5 64 return files
2b9e7381
AM
65
66def find_last_section(log):
67 f = open(log, 'r')
cfece95e 68 rx1 = re.compile(r"^Executing\(%(\w+)\).*$")
b525672f 69 rx2 = re.compile(r"^Processing (files):.*$")
2b9e7381
AM
70 last_section = None
71 for l in f:
cfece95e
AM
72 m = rx1.search(l)
73 if not m:
74 m = rx2.search(l)
2b9e7381 75 if m:
99247f87 76 last_section = m.group(1)
2b9e7381
AM
77 f.close()
78 return last_section
This page took 1.820315 seconds and 4 git commands to generate.