Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 669 | ||||||||
Proposed branch: | lp:~mterry/quickly/extras | ||||||||
Merge into: | lp:quickly | ||||||||
Diff against target: |
357 lines (+186/-132) 4 files modified
data/templates/ubuntu-application/internal/packaging.py (+86/-55) data/templates/ubuntu-application/test/extras.sh (+99/-0) data/templates/ubuntu-application/test/metadata.sh (+0/-76) data/templates/ubuntu-application/test/package.sh (+1/-1) |
||||||||
To merge this branch: | bzr merge lp:~mterry/quickly/extras | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Didier Roche-Tolomelli | Approve | ||
Review via email: mp+107104@code.launchpad.net |
Commit message
Description of the change
quickly package --extras is super broken right now.
It doesn't install the desktop or executable files in the right place.
The desktop file doesn't point to the right executable or icon.
The code looks in the wrong place for data files.
It doesn't know to look at or compile its own schemas.
To post a comment you must log in.
lp:~mterry/quickly/extras
updated
- 678. By Michael Terry
-
conditionally execute some of the commands in debian/rules to support cli apps too
Revision history for this message
Michael Terry (mterry) wrote : | # |
Added the following before merging:
# TODO: Vastly simplify this function. This was implemented post-12.04 to
# make it easier to get an SRU for these fixes. But the only things here
# that can't be done in-code (either wrapper code or setup.py) is compiling
# the schemas and moving the desktop file.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'data/templates/ubuntu-application/internal/packaging.py' |
2 | --- data/templates/ubuntu-application/internal/packaging.py 2012-03-05 20:11:36 +0000 |
3 | +++ data/templates/ubuntu-application/internal/packaging.py 2012-05-25 19:09:17 +0000 |
4 | @@ -158,62 +158,93 @@ |
5 | return(_continue_if_errors(err_output, warn_output, proc.returncode, |
6 | ask_on_warn_or_error)) |
7 | |
8 | -def update_metadata(): |
9 | - # See https://wiki.ubuntu.com/PostReleaseApps/Metadata for details |
10 | - |
11 | - metadata = [] |
12 | +def update_rules(): |
13 | project_name = configurationhandler.project_config['project'] |
14 | |
15 | - # Grab name and category from desktop file |
16 | - with open('%s.desktop.in' % project_name, 'r') as f: |
17 | - desktop = f.read() |
18 | - |
19 | - match = re.search('\n_?Name=(.*)\n', desktop) |
20 | - if match is not None: |
21 | - metadata.append('XB-AppName: %s' % match.group(1)) |
22 | - |
23 | - match = re.search('\nCategories=(.*)\n', desktop) |
24 | - if match is not None: |
25 | - metadata.append('XB-Category: %s' % match.group(1)) |
26 | - |
27 | - # Grab distribution for screenshot URLs from debian/changelog |
28 | - changelog = subprocess.Popen(['dpkg-parsechangelog'], stdout=subprocess.PIPE).communicate()[0] |
29 | - match = re.search('\nDistribution: (.*)\n', changelog) |
30 | - if match is not None: |
31 | - distribution = match.group(1) |
32 | - first_letter = project_name[0] |
33 | - urlbase = 'https://software-center.ubuntu.com/screenshots/%s' % first_letter |
34 | - metadata.append('XB-Screenshot-Url: %s/%s-%s.png' % (urlbase, project_name, distribution)) |
35 | - metadata.append('XB-Thumbnail-Url: %s/%s-%s.thumb.png' % (urlbase, project_name, distribution)) |
36 | - |
37 | - # Now ship the icon as part of the debian packaging |
38 | - icon_name = 'data/media/%s.svg' % project_name |
39 | - if not os.path.exists(icon_name): |
40 | - # Support pre-11.03.1 icon names |
41 | - icon_name = 'data/media/logo.svg' |
42 | - if not os.path.exists(icon_name): |
43 | - icon_name = None |
44 | - if icon_name: |
45 | - contents = '' |
46 | - with open('debian/rules', 'r') as f: |
47 | - contents = f.read() |
48 | - if contents and re.search('dpkg-distaddfile %s.svg' % project_name, contents) is None: |
49 | - contents += """ |
50 | -override_dh_install:: |
51 | - dh_install |
52 | - cp %(icon_name)s ../%(project_name)s.svg |
53 | - dpkg-distaddfile %(project_name)s.svg raw-meta-data -""" % { |
54 | - 'project_name': project_name, 'icon_name': icon_name} |
55 | - templatetools.set_file_contents('debian/rules', contents) |
56 | - |
57 | - metadata.append('XB-Icon: %s.svg' % project_name) |
58 | - |
59 | - # Prepend the start-match line, because update_file_content replaces it |
60 | - metadata.insert(0, 'XB-Python-Version: ${python:Versions}') |
61 | - templatetools.update_file_content('debian/control', |
62 | - 'XB-Python-Version: ${python:Versions}', |
63 | - 'Depends: ${misc:Depends},', |
64 | - '\n'.join(metadata) + '\n') |
65 | + install_rules = """ |
66 | +override_dh_install: |
67 | + dh_install""" |
68 | + |
69 | + opt_root = "/opt/extras.ubuntu.com/" + project_name |
70 | + |
71 | + # Move script to bin/ folder. |
72 | + # There are some complications here. As of this writing, current versions |
73 | + # of python-mkdebian do not correctly install our executable script in a |
74 | + # bin/ subdirectory. Instead, they either install it in the opt-project |
75 | + # root or in the opt-project python library folder (depending on whether |
76 | + # the project name is the same as its python name). So if we find that to |
77 | + # be the case, we move the script accordingly. |
78 | + bin_path = "%(opt_root)s/bin/%(project_name)s" % { |
79 | + 'opt_root': opt_root, 'project_name': project_name} |
80 | + bad_bin_debpath = "debian/%(project_name)s%(opt_root)s/%(project_name)s" % { |
81 | + 'opt_root': opt_root, 'project_name': project_name} |
82 | + python_name = templatetools.python_name(project_name) |
83 | + if project_name == python_name: |
84 | + bad_bin_debpath += "/" + project_name |
85 | + install_rules += """ |
86 | + mkdir -p debian/%(project_name)s%(opt_root)s/bin |
87 | + if [ -x %(bad_bin_debpath)s ]; then mv %(bad_bin_debpath)s debian/%(project_name)s%(opt_root)s/bin; fi""" % { |
88 | + 'project_name': project_name, 'opt_root': opt_root, 'bad_bin_debpath': bad_bin_debpath} |
89 | + |
90 | + # Move desktop file and update it to point to our /opt locations. |
91 | + # The file starts, as expected, under /opt. But the ARB wants and allows |
92 | + # us to install it in /usr, so we do. |
93 | + old_desktop_debdir = "debian/%(project_name)s%(opt_root)s/share/applications" % { |
94 | + 'project_name': project_name, 'opt_root': opt_root} |
95 | + new_desktop_debdir = "debian/%(project_name)s/usr/share/applications" % {'project_name': project_name} |
96 | + new_desktop_debpath = new_desktop_debdir + "/extras-" + project_name + ".desktop" |
97 | + install_rules += """ |
98 | + if [ -f %(old_desktop_debdir)s/%(project_name)s.desktop ]; then \\ |
99 | + mkdir -p %(new_desktop_debdir)s; \\ |
100 | + mv %(old_desktop_debdir)s/%(project_name)s.desktop %(new_desktop_debpath)s; \\ |
101 | + rmdir --ignore-fail-on-non-empty %(old_desktop_debdir)s; \\ |
102 | + sed -i 's|Exec=.*|Exec=%(bin_path)s|' %(new_desktop_debpath)s; \\ |
103 | + sed -i 's|Icon=/usr/|Icon=%(opt_root)s/|' %(new_desktop_debpath)s; \\ |
104 | + fi""" % { |
105 | + 'bin_path': bin_path, 'old_desktop_debdir': old_desktop_debdir, |
106 | + 'new_desktop_debdir': new_desktop_debdir, 'project_name': project_name, |
107 | + 'opt_root': opt_root, 'new_desktop_debpath': new_desktop_debpath} |
108 | + |
109 | + # Set gettext's bindtextdomain to point to /opt and use the locale |
110 | + # module (gettext's C API) instead of the gettext module (gettext's Python |
111 | + # API), so that translations are loaded from /opt |
112 | + localedir = os.path.join(opt_root, 'share/locale') |
113 | + install_rules += """ |
114 | + grep -RlZ 'import gettext' debian/%(project_name)s/* | xargs -0 -r sed -i 's|\(import\) gettext$$|\\1 locale|' |
115 | + grep -RlZ 'from gettext import gettext as _' debian/%(project_name)s/* | xargs -0 -r sed -i 's|from gettext \(import gettext as _\)|from locale \\1|' |
116 | + grep -RlZ "gettext.textdomain('%(project_name)s')" debian/%(project_name)s/* | xargs -0 -r sed -i "s|gettext\(\.textdomain('%(project_name)s')\)|locale\.bindtextdomain('%(project_name)s', '%(localedir)s')\\nlocale\\1|" """ % { |
117 | + 'project_name': project_name, 'localedir': localedir} |
118 | + |
119 | + # We install a python_nameconfig.py file that contains a pointer to the |
120 | + # data directory. But that will be determined by setup.py, so it will be |
121 | + # wrong (python-mkdebian's --prefix command only affects where it moves |
122 | + # files during build, but not what it passes to setup.py) |
123 | + config_debpath = "debian/%(project_name)s%(opt_root)s/%(python_name)s*/%(python_name)sconfig.py" % { |
124 | + 'project_name': project_name, 'opt_root': opt_root, 'python_name': python_name} |
125 | + install_rules += """ |
126 | + sed -i "s|__%(python_name)s_data_directory__ =.*|__%(python_name)s_data_directory__ = '%(opt_root)s/share/%(project_name)s/'|" %(config_debpath)s""" % { |
127 | + 'opt_root': opt_root, 'project_name': project_name, |
128 | + 'python_name': python_name, 'config_debpath': config_debpath} |
129 | + |
130 | + # Adjust XDG_DATA_DIRS so we can find schemas and help files |
131 | + install_rules += """ |
132 | + sed -i 's| sys.path.insert(0, opt_path)|\\0\\n os.putenv("XDG_DATA_DIRS", "%%s:%%s" %% ("%(opt_root)s/share/", os.getenv("XDG_DATA_DIRS", "")))|' debian/%(project_name)s%(bin_path)s""" % { |
133 | + 'opt_root': opt_root, 'project_name': project_name, 'bin_path': bin_path} |
134 | + |
135 | + # Compile the glib schema, since it is in a weird place that normal glib |
136 | + # triggers won't catch during package install. |
137 | + schema_debdir = "debian/%(project_name)s%(opt_root)s/share/glib-2.0/schemas" % { |
138 | + 'opt_root': opt_root, 'project_name': project_name} |
139 | + install_rules += """ |
140 | + if [ -d %(schema_debdir)s ]; then glib-compile-schemas %(schema_debdir)s; fi""" % { |
141 | + 'schema_debdir': schema_debdir} |
142 | + |
143 | + # Set rules back to include our changes |
144 | + rules = '' |
145 | + with open('debian/rules', 'r') as f: |
146 | + rules = f.read() |
147 | + rules += install_rules |
148 | + templatetools.set_file_contents('debian/rules', rules) |
149 | |
150 | def get_python_mkdebian_version(): |
151 | proc = subprocess.Popen(["python-mkdebian", "--version"], stdout=subprocess.PIPE) |
152 | @@ -275,7 +306,7 @@ |
153 | return(return_code) |
154 | |
155 | if installopt: |
156 | - update_metadata() |
157 | + update_rules() |
158 | |
159 | print _("Ubuntu packaging created in debian/") |
160 | |
161 | |
162 | === added file 'data/templates/ubuntu-application/test/extras.sh' |
163 | --- data/templates/ubuntu-application/test/extras.sh 1970-01-01 00:00:00 +0000 |
164 | +++ data/templates/ubuntu-application/test/extras.sh 2012-05-25 19:09:17 +0000 |
165 | @@ -0,0 +1,99 @@ |
166 | +#!/bin/sh |
167 | + |
168 | +cd /tmp |
169 | + |
170 | +rm -rf test-project* |
171 | + |
172 | +quickly create ubuntu-application test-project |
173 | +# Creating bzr repository and committing |
174 | +# Congrats, your new project is setup! cd /tmp/test-project/ to start hacking. |
175 | +# Creating project directory test-project |
176 | + |
177 | +cd test-project |
178 | + |
179 | +(echo "Copyright (C) 2010 Oliver Twist <twist@example.com>" > AUTHORS) |
180 | + |
181 | +quickly license GPL-3 |
182 | + |
183 | +quickly package --extras | sed 's/^\.\+//' |
184 | +# Ubuntu packaging created in debian/ |
185 | +# Ubuntu package has been successfully created in ../test-project_0.1_all.deb |
186 | + |
187 | +ls ../test-project_0.1.dsc ../test-project_0.1.tar.gz ../test-project_0.1_all.deb |
188 | +# ../test-project_0.1_all.deb |
189 | +# ../test-project_0.1.dsc |
190 | +# ../test-project_0.1.tar.gz |
191 | + |
192 | +## Now we want to verify that we installed things in the right place |
193 | + |
194 | +mkdir unpacked |
195 | + |
196 | +cd unpacked |
197 | + |
198 | +ar p ../../test-project_0.1_all.deb data.tar.gz | tar xz |
199 | + |
200 | +ls -F . |
201 | +# opt/ |
202 | +# usr/ |
203 | + |
204 | +ls -F ./opt |
205 | +# extras.ubuntu.com/ |
206 | + |
207 | +ls -F ./opt/extras.ubuntu.com |
208 | +# test-project/ |
209 | + |
210 | +ls -F ./opt/extras.ubuntu.com/test-project |
211 | +# bin/ |
212 | +# share/ |
213 | +# test_project/ |
214 | +# test_project-0.1.egg-info |
215 | +# test_project_lib/ |
216 | + |
217 | +ls -F ./opt/extras.ubuntu.com/test-project/bin |
218 | +# test-project* |
219 | + |
220 | +ls -F ./opt/extras.ubuntu.com/test-project/share |
221 | +# glib-2.0/ |
222 | +# gnome/ |
223 | +# test-project/ |
224 | + |
225 | +ls -F ./opt/extras.ubuntu.com/test-project/share/glib-2.0 |
226 | +# schemas/ |
227 | + |
228 | +ls -F ./opt/extras.ubuntu.com/test-project/share/glib-2.0/schemas |
229 | +# gschemas.compiled |
230 | +# net.launchpad.test-project.gschema.xml |
231 | + |
232 | +ls -F ./usr |
233 | +# share/ |
234 | + |
235 | +ls -F ./usr/share |
236 | +# applications/ |
237 | +# doc/ |
238 | +# python/ |
239 | + |
240 | +ls -F ./usr/share/applications |
241 | +# extras-test-project.desktop |
242 | + |
243 | +## Now confirm the contents of some of these files |
244 | + |
245 | +cat ./usr/share/applications/extras-test-project.desktop |
246 | +# [Desktop Entry] |
247 | +# Name=Test Project |
248 | +# Comment=TestProject application |
249 | +# Categories=GNOME;Utility; |
250 | +# Exec=/opt/extras.ubuntu.com/test-project/bin/test-project |
251 | +# Icon=/opt/extras.ubuntu.com/test-project/share/test-project/media/test-project.svg |
252 | +# Terminal=false |
253 | +# Type=Application |
254 | + |
255 | +grep -Rh "__test_project_data_directory__ = " ./opt/extras.ubuntu.com/test-project |
256 | +# __test_project_data_directory__ = '/opt/extras.ubuntu.com/test-project/share/test-project/' |
257 | + |
258 | +grep -Rh "locale.bindtextdomain" ./opt/extras.ubuntu.com/test-project/bin/test-project |
259 | +# locale.bindtextdomain('test-project', '/opt/extras.ubuntu.com/test-project/share/locale') |
260 | + |
261 | +grep -Rh "^import gettext" ./opt/extras.ubuntu.com/test-project |
262 | + |
263 | +grep -Rh "XDG_DATA_DIRS" ./opt/extras.ubuntu.com/test-project/bin/test-project |
264 | +# os.putenv("XDG_DATA_DIRS", "%s:%s" % ("/opt/extras.ubuntu.com/test-project/share/", os.getenv("XDG_DATA_DIRS", ""))) |
265 | |
266 | === removed file 'data/templates/ubuntu-application/test/metadata.sh' |
267 | --- data/templates/ubuntu-application/test/metadata.sh 2012-03-14 23:48:37 +0000 |
268 | +++ data/templates/ubuntu-application/test/metadata.sh 1970-01-01 00:00:00 +0000 |
269 | @@ -1,76 +0,0 @@ |
270 | -#!/bin/sh |
271 | - |
272 | -cd /tmp |
273 | - |
274 | -rm -rf test-project |
275 | - |
276 | -quickly create ubuntu-application test-project |
277 | -# Creating bzr repository and committing |
278 | -# Congrats, your new project is setup! cd /tmp/test-project/ to start hacking. |
279 | -# Creating project directory test-project |
280 | - |
281 | -cd test-project |
282 | - |
283 | -quickly package --extras | sed 's/^\.\+//' |
284 | -# Ubuntu packaging created in debian/ |
285 | -# Ubuntu package has been successfully created in ../test-project_0.1_all.deb |
286 | - |
287 | -grep -C1 "^XB-" debian/control | sed "s/project-$(lsb_release -c | cut -f2)*\./project-RELEASE./" |
288 | -# Architecture: all |
289 | -# XB-Python-Version: ${python:Versions} |
290 | -# XB-AppName: Test Project |
291 | -# XB-Category: GNOME;Utility; |
292 | -# XB-Screenshot-Url: https://software-center.ubuntu.com/screenshots/t/test-project-RELEASE.png |
293 | -# XB-Thumbnail-Url: https://software-center.ubuntu.com/screenshots/t/test-project-RELEASE.thumb.png |
294 | -# XB-Icon: test-project.svg |
295 | -# Depends: ${misc:Depends}, |
296 | - |
297 | -cat debian/rules |
298 | -# #!/usr/bin/make -f |
299 | -# %: |
300 | -# ifneq ($(shell dh -l | grep -xF translations),) |
301 | -# dh $@ --with python2,translations |
302 | -# else |
303 | -# dh $@ --with python2 |
304 | -# endif |
305 | -# |
306 | -# override_dh_auto_install: |
307 | -# dh_auto_install -- --install-scripts=/opt/extras.ubuntu.com/test-project --install-data=/opt/extras.ubuntu.com/test-project --install-lib=/opt/extras.ubuntu.com/test-project |
308 | -# |
309 | -# override_dh_python2: |
310 | -# dh_python2 /opt/extras.ubuntu.com/test-project |
311 | -# |
312 | -# |
313 | -# override_dh_install:: |
314 | -# dh_install |
315 | -# cp data/media/test-project.svg ../test-project.svg |
316 | -# dpkg-distaddfile test-project.svg raw-meta-data - |
317 | - |
318 | -## Older versions of quickly had logo.svg instead of project_name.svg, so test those too |
319 | - |
320 | -mv data/media/test-project.svg data/media/logo.svg |
321 | - |
322 | -quickly package --extras | sed 's/^\.\+//' |
323 | -# Ubuntu packaging created in debian/ |
324 | -# Ubuntu package has been successfully created in ../test-project_0.1_all.deb |
325 | - |
326 | -grep XB-Icon debian/control |
327 | -# XB-Icon: test-project.svg |
328 | - |
329 | -tail -n 4 debian/rules |
330 | -# override_dh_install:: |
331 | -# dh_install |
332 | -# cp data/media/logo.svg ../test-project.svg |
333 | -# dpkg-distaddfile test-project.svg raw-meta-data - |
334 | - |
335 | -## Finally, make sure we gracefully handle no icon at all |
336 | - |
337 | -rm data/media/logo.svg |
338 | - |
339 | -quickly package --extras | sed 's/^\.\+//' |
340 | -# Ubuntu packaging created in debian/ |
341 | -# Ubuntu package has been successfully created in ../test-project_0.1_all.deb |
342 | - |
343 | -grep XB-Icon debian/control |
344 | - |
345 | -grep dpkg-distaddfile debian/rules |
346 | |
347 | === modified file 'data/templates/ubuntu-application/test/package.sh' |
348 | --- data/templates/ubuntu-application/test/package.sh 2012-05-21 20:24:47 +0000 |
349 | +++ data/templates/ubuntu-application/test/package.sh 2012-05-25 19:09:17 +0000 |
350 | @@ -49,7 +49,7 @@ |
351 | # debian/control:Maintainer: UNKNOWN <UNKNOWN> |
352 | # debian/control:Description: UNKNOWN |
353 | # debian/control: UNKNOWN |
354 | -# debian/copyright:Maintainer: UNKNOWN <UNKNOWN> |
355 | +# debian/copyright:Upstream-Contact: UNKNOWN <UNKNOWN> |
356 | # debian/copyright:Source: UNKNOWN |
357 | # debian/copyright:License: UNKNOWN |
358 |
Now that you answered some of my questions (if you add the TODO: tag), I'm happy approving it!
Some more comments: fail-on- non-empty %(old_desktop_ debdir) s; \\
rmdir --ignore-
I love it I love it I love it! Nice way to not remove everything if people add some more customization. Elegant and lovely ;)
Also, let's hope people won't use ngettext or one of its UTF8 import rule, otherwise, we are screwed :)
But overall again, nice work in an non intrusive way :)