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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
# this is part of langpack-o-matic, by Martin Pitt <martin.pitt@canonical.com>
# (C) 2005, 2010 Canonical Ltd.
import os.path, os, gzip, subprocess
import macros
def make_pkg(skeleton, path, lpmacros, extra_tar = None):
'''Create a new source package from a skeleton for a specific locale and
class and subsitute all macros using the given LangpackMacros object.
If the package already exists, then it is updated. The "cls" parameter
specifies the desired package class (kde, gnome, or empty string for the
"all other stuff" language pack). The source package path is appended to
"updated-packages" (if not already present).
If a file name extra_tar is given, the file is installed into
data/extra.tar.
'''
if os.path.isdir(path):
print "Updating source package %s from skeleton %s" % (path, skeleton)
_update_pkg(skeleton, path, lpmacros)
else:
print "Creating source package %s from skeleton %s" % (path, skeleton)
_create_pkg(skeleton, path, lpmacros)
# add package to updated-packages
if not os.path.exists('updated-packages') or path not in [l.strip() for l
in open('updated-packages')]:
print >> open('updated-packages', 'a'), path
# Refresh upgrade notes
notedir = os.path.join(path, 'debian', 'upgrade-notes')
if os.path.isdir(notedir) and not lpmacros['CLASS']:
for f in os.listdir('upgrade-notes'):
# ignore .arch-ids and other stuff
if f[0] == '.':
continue
# copy file, substitute macros
content = open(os.path.join('upgrade-notes',f)).read()
content = lpmacros.subst_string(content)
open(os.path.join(notedir,f), 'w').write(content)
# Install extra tarball
if extra_tar:
target = os.path.join(path, 'data', 'extra.tar')
if extra_tar.endswith('.gz'):
tardata = gzip.open(extra_tar).read()
else:
tardata = open(extra_tar).read()
open(target, 'w').write(tardata)
# add extra recommends; this is a quick hack for LP#352036 until LP #123020
# gets fixed properly
package = path.split('/')[-1]
try:
extra_recommends = macros._file_map('maps/extra-recommends-' +
lpmacros['RELEASEVERSION'], package, ':')
print 'Adding extra recommends:', extra_recommends
subprocess.call(['sed', '-i', '/^Depends:/ aRecommends: ' +
extra_recommends, os.path.join(path, 'debian', 'control')])
except (IOError, KeyError):
pass
# Chinese package split (zh => zh-hans / zh-hant) needs a Conflicts: and a Replaces: entry
if lpmacros['RELEASEVERSION'] == '9.10' or lpmacros['RELEASEVERSION'] == '10.04':
try:
conflicts = macros._file_map('maps/conflicts-%s' % lpmacros['RELEASEVERSION'], package, ':')
print 'Adding Conflicts and Replaces:', conflicts
subprocess.call(['sed', '-i', '/^Conflicts:/ a, ' +
conflicts, os.path.join(path, 'debian', 'control')])
subprocess.call(['sed', '-i', '/^Replaces:/ a, ' +
conflicts, os.path.join(path, 'debian', 'control')])
except (IOError, KeyError):
pass
def _create_pkg(skel, dest, lpmacros):
# copy skel files, omitting hidden files
for path, dirs, files in os.walk(skel):
if os.path.basename(path)[0] == '.':
continue
destdir = os.path.join(dest, os.path.sep.join(path.split(os.path.sep)[1:]))
os.makedirs(destdir)
for f in files:
if f[0] == '.':
continue
# copy file, substitute macros
content = open(os.path.join(path,f)).read()
content = lpmacros.subst_string(content)
open(os.path.join(destdir,f), 'w').write(content)
def _update_pkg(skel, dest, lpmacros):
# copy control files (but changelog) again, in case they have changed
srcdir = os.path.join(skel, 'debian')
destdir = os.path.join(dest, 'debian')
for f in os.listdir(srcdir):
if f[0] == '.' or f == 'changelog':
continue
# copy file, substitute macros
src = os.path.join(srcdir,f)
if os.path.isfile(src):
content = open(src).read()
content = lpmacros.subst_string(content)
open(os.path.join(destdir,f), 'w').write(content)
# call dch to update changelog
cwd = os.getcwd()
os.chdir(dest)
result = os.spawnlpe(os.P_WAIT, 'dch', 'dch', '--force-distribution', '-v',
'1:%s+%s' % (lpmacros['RELEASEVERSION'], lpmacros['TIMESTAMP']),
'-p', '-D', lpmacros['RELEASE'],
'Automatic update to latest translation data.',
{'DEBEMAIL': lpmacros['UPLOADER']})
os.chdir(cwd)
if result != 0:
raise Exception, 'dch failed'
def get_pkg_version(path):
'''Return the version of a package.'''
l = open(os.path.join(path, 'debian', 'changelog')).readline()
return l[l.index('(')+1:l.index(')')].strip()
if __name__ == '__main__':
import tempfile, unittest, shutil, re
class _T(unittest.TestCase):
def setUp(self):
self.workdir = tempfile.mkdtemp()
self.macros = macros.LangpackMacros('de_CH', 'gnome', 'lucid',
'20100528')
self.pkg = os.path.join(self.workdir, 'mypkg')
try:
os.unlink('updated-packages')
except OSError:
pass
def tearDown(self):
shutil.rmtree(self.workdir)
try:
os.unlink('updated-packages')
except OSError:
pass
def test_create(self):
'''create new package'''
make_pkg('skel-input', self.pkg, self.macros)
self.assertEqual(open('updated-packages').read().strip(), self.pkg)
self.assert_(os.path.isfile(os.path.join(self.pkg, 'COPYING')))
self.assert_(os.path.isfile(os.path.join(self.pkg, 'debian', 'rules')))
# check changelog
changelog = open(os.path.join(self.pkg, 'debian',
'changelog')).read().splitlines()
self.assert_(changelog[0].startswith('language-support-input-gnome-de (1:10.04+20100528) lucid'))
self.assert_('Initial Release' in changelog[2])
# check control file
control = open(os.path.join(self.pkg, 'debian', 'control')).read()
self.assert_(control.startswith('Source: language-support-input-gnome-de'))
self.assert_('Package: language-support-input-gnome-de' in control)
self.assert_(re.search('^Description:.*GNOME German', control, re.M))
def test_update(self):
'''update existing package'''
make_pkg('skel-input', self.pkg, self.macros)
self.macros = macros.LangpackMacros('de_CH', 'gnome', 'lucid',
'20100529')
make_pkg('skel-input', self.pkg, self.macros)
self.assertEqual(open('updated-packages').read().strip(), self.pkg)
self.assert_(os.path.isfile(os.path.join(self.pkg, 'COPYING')))
self.assert_(os.path.isfile(os.path.join(self.pkg, 'debian', 'rules')))
# check changelog
changelog = open(os.path.join(self.pkg, 'debian',
'changelog')).read().splitlines()
self.assert_(changelog[0].startswith('language-support-input-gnome-de (1:10.04+20100529) lucid'))
self.assert_('update' in changelog[2])
# old changelog entries still present
self.assert_(changelog[6].startswith('language-support-input-gnome-de (1:10.04+20100528) lucid'))
# check control file
control = open(os.path.join(self.pkg, 'debian', 'control')).read()
self.assert_(control.startswith('Source: language-support-input-gnome-de'))
self.assert_('Package: language-support-input-gnome-de' in control)
self.assert_(re.search('^Description:.*GNOME German', control, re.M))
def test_extra_tarball(self):
'''package with extra tarball'''
make_pkg('skel-base', self.pkg, self.macros, 'extra-files/kde-de.tar')
self.assertEqual(open(os.path.join(self.pkg, 'data',
'extra.tar')).read(), open('extra-files/kde-de.tar').read())
unittest.main()
|