Repository navigation
Expand file tree
/
Copy pathcommon.py
More file actions
66 lines (54 loc) · 2.01 KB
/
Copy pathcommon.py
File metadata and controls
66 lines (54 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import re
from subprocess import Popen, PIPE
from htmlentitydefs import name2codepoint
chroot_path = "/var/chroot/squeeze-i386"
home_in_chroot = os.path.join(chroot_path,"home/mark")
build_path_in_chroot = os.path.join(home_in_chroot,"fiji-build")
owner_and_group = "mark.mark"
def get_version_from_changelog(changelog_path):
p = Popen(["dpkg-parsechangelog","-l"+changelog_path],stdout=PIPE)
changelog = p.communicate()[0]
if p.returncode != 0:
raise Exception, "Failed to parse debian/changelog"
version_match = re.search("(?ims)Version: (\S+)",changelog)
if not version_match:
raise Exception, "Failed to find the Version field"
version_from_changelog = version_match.group(1)
if not re.match('^\d{14}$',version_from_changelog):
print >> sys.stderr, "Error: The version number is not of the form YYYYMMDDHHMMSS"
sys.exit(6)
return version_from_changelog
# These next two useful functions are from:
# http://snippets.dzone.com/posts/show/4569
def substitute_entity(match):
ent = match.group(2)
if match.group(1) == "#":
return unichr(int(ent))
else:
cp = name2codepoint.get(ent)
if cp:
return unichr(cp)
else:
return match.group()
def decode_htmlentities(string):
entity_re = re.compile("&(#?)(\d{1,5}|\w{1,8});")
return entity_re.subn(substitute_entity, string)[0]
def trim_line(s,max_length):
rs = s.rstrip()
if len(rs) <= max_length:
return rs
else:
substitution = " [...]"
return rs[0:(max_length-len(substitution))].rstrip() + substitution
def classpath_definitions_from(filename):
result = {}
with open(filename) as f:
for line in f:
matches = re.findall('CLASSPATH\((.*?)\)=([\w\.\:/\-\$]+)',line)
for m in matches:
target_filename = m[0]
result.setdefault(target_filename,[])
for j in m[1].split(':'):
result[target_filename].append(j)
return result