1
# this is part of langpack-o-matic, by Martin Pitt <martin.pitt@canonical.com>
3
# (C) 2005, 2010 Canonical Ltd.
27
def make_pkg(skeleton, path, lpmacros, extra_tar=None):
28
'''Create a new source package from a skeleton for a specific locale and
29
class and subsitute all macros using the given LangpackMacros object.
31
If the package already exists, then it is updated. The "cls" parameter
32
specifies the desired package class (kde, gnome, or empty string for the
33
"all other stuff" language pack). The source package path is appended to
34
"updated-packages" (if not already present).
36
If a file name extra_tar is given, the file is installed into
39
if os.path.isdir(path):
40
logging.debug('Updating source package %s from skeleton %s', path, skeleton)
41
_update_pkg(skeleton, path, lpmacros)
43
logging.debug('Creating source package %s from skeleton %s', path, skeleton)
44
_create_pkg(skeleton, path, lpmacros)
46
# add package to updated-packages
47
if not os.path.exists('updated-packages') or \
48
path not in [l.strip() for l in flines('updated-packages')]:
49
with open('updated-packages', 'a') as f:
52
# Refresh upgrade notes
53
notedir = os.path.join(path, 'debian', 'upgrade-notes')
54
if os.path.isdir(notedir) and not lpmacros['CLASS']:
55
for f in os.listdir('upgrade-notes'):
56
# ignore .arch-ids and other stuff
59
# copy file, substitute macros
60
content = fcontents(os.path.join('upgrade-notes', f))
61
content = lpmacros.subst_string(content)
62
f = open(os.path.join(notedir, f), 'w')
66
# Install extra tarball
68
target = os.path.join(path, 'data', 'extra.tar')
69
if extra_tar.endswith('.gz'):
70
tardata = gzip.open(extra_tar).read()
72
tardata = fcontents(extra_tar)
78
def _create_pkg(skel, dest, lpmacros):
79
# copy skel files, omitting hidden files
80
assert os.path.isdir(skel)
81
for path, dirs, files in os.walk(skel):
82
if os.path.basename(path)[0] == '.':
84
destdir = os.path.join(dest, os.path.sep.join(path.split(os.path.sep)[1:]))
89
# copy file, substitute macros
90
content = fcontents(os.path.join(path, f))
91
content = lpmacros.subst_string(content)
92
f = open(os.path.join(destdir, f), 'w')
97
def _update_pkg(skel, dest, lpmacros):
98
assert os.path.isdir(skel)
99
# copy control files (but changelog) again, in case they have changed
100
srcdir = os.path.join(skel, 'debian')
101
destdir = os.path.join(dest, 'debian')
103
# clean up old data to avoid file conflicts from files which moved to a
105
if 'custom' not in skel:
106
shutil.rmtree(os.path.join(dest, 'data'))
108
for f in os.listdir(srcdir):
109
if f[0] == '.' or f == 'changelog':
112
# copy file, substitute macros
113
src = os.path.join(srcdir, f)
114
if os.path.isfile(src):
115
content = fcontents(src)
116
content = lpmacros.subst_string(content)
117
f = open(os.path.join(destdir, f), 'w')
121
# call dch to update changelog
124
result = os.spawnlpe(os.P_WAIT, 'dch', 'dch', '--force-distribution',
125
'--force-bad-version', '-v',
126
'1:%s+%s' % (lpmacros['RELEASEVERSION'], lpmacros['TIMESTAMP']),
127
'--urgency=low', '-p', '-D', lpmacros['RELEASE'],
128
'Automatic update to latest translation data.',
129
{'DEBEMAIL': lpmacros['UPLOADER']})
133
raise Exception('dch failed')
136
def get_pkg_version(path):
137
'''Return the version of a package.'''
139
ch = open(os.path.join(path, 'debian', 'changelog'))
142
return l[l.index('(') + 1:l.index(')')].strip()
145
if __name__ == '__main__':
150
class _T(unittest.TestCase):
152
self.workdir = tempfile.mkdtemp()
153
self.macros = macros.LangpackMacros('ubuntu', 'de_CH', 'gnome', 'trusty', '20100528')
154
self.pkg = os.path.join(self.workdir, 'mypkg')
156
os.unlink('updated-packages')
161
shutil.rmtree(self.workdir)
163
os.unlink('updated-packages')
167
def test_create(self):
168
'''create new package'''
170
make_pkg('skel-base', self.pkg, self.macros)
172
self.assertEqual(fcontents('updated-packages').strip(), self.pkg)
173
self.assertTrue(os.path.isfile(os.path.join(self.pkg, 'COPYING')))
174
self.assertTrue(os.path.isfile(os.path.join(self.pkg, 'debian', 'rules')))
177
changelog = flines(os.path.join(self.pkg, 'debian', 'changelog'))
178
self.assertTrue(changelog[0].startswith('language-pack-gnome-de-base (1:14.04+20100528) trusty'), changelog[0])
179
self.assertTrue('Initial Release' in changelog[2])
182
control = fcontents(os.path.join(self.pkg, 'debian', 'control'))
183
self.assertTrue(control.startswith('Source: language-pack-gnome-de-base'))
184
self.assertTrue('Package: language-pack-gnome-de-base' in control)
185
self.assertTrue(re.search('^Description:.*GNOME.*German', control, re.M))
187
def test_update(self):
188
'''update existing package'''
190
make_pkg('skel-update', self.pkg, self.macros)
191
self.macros = macros.LangpackMacros('ubuntu', 'de_CH', 'gnome', 'trusty', '20100529')
192
make_pkg('skel-update', self.pkg, self.macros)
193
self.assertEqual(fcontents('updated-packages').strip(), self.pkg)
195
self.assertTrue(os.path.isfile(os.path.join(self.pkg, 'COPYING')))
196
self.assertTrue(os.path.isfile(os.path.join(self.pkg, 'debian', 'rules')))
199
changelog = flines(os.path.join(self.pkg, 'debian', 'changelog'))
200
self.assertTrue(changelog[0].startswith('language-pack-gnome-de (1:14.04+20100529) trusty'), changelog[0])
201
self.assertTrue('update' in changelog[2])
202
# old changelog entries still present
203
self.assertTrue(changelog[6].startswith('language-pack-gnome-de (1:14.04+20100528) trusty'))
206
control = fcontents(os.path.join(self.pkg, 'debian', 'control'))
207
self.assertTrue(control.startswith('Source: language-pack-gnome-de'))
208
self.assertTrue('Package: language-pack-gnome-de' in control)
209
self.assertTrue(re.search('^Description:.*GNOME.*German', control, re.M))
211
def test_extra_tarball(self):
212
'''package with extra tarball'''
214
make_pkg('skel-base', self.pkg, self.macros, 'extra-files/kde-de.tar')
216
fcontents(os.path.join(self.pkg, 'data', 'extra.tar')),
217
fcontents('extra-files/kde-de.tar'))