Merge lp:~mhall119/quickly-community-templates/add-unity-lens into lp:quickly-community-templates
- add-unity-lens
- Merge into trunk
Proposed by
Michael Hall
Status: | Merged |
---|---|
Merged at revision: | 11 |
Proposed branch: | lp:~mhall119/quickly-community-templates/add-unity-lens |
Merge into: | lp:quickly-community-templates |
Diff against target: |
681 lines (+613/-0) 13 files modified
unity-lens/commandsconfig (+11/-0) unity-lens/create.py (+120/-0) unity-lens/install.py (+72/-0) unity-lens/project_root/AUTHORS (+1/-0) unity-lens/project_root/bin/project_name (+31/-0) unity-lens/project_root/lens_name.lens (+11/-0) unity-lens/project_root/python/__init__.py (+33/-0) unity-lens/project_root/python/python_nameconfig.py (+59/-0) unity-lens/project_root/setup.py (+75/-0) unity-lens/project_root/unity-lens-lens_name.service (+3/-0) unity-lens/project_root/unity-lens-lens_name.svg (+52/-0) unity-lens/run.py (+75/-0) unity-lens/uninstall.py (+70/-0) |
To merge this branch: | bzr merge lp:~mhall119/quickly-community-templates/add-unity-lens |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Planella | Approve | ||
Review via email: mp+109896@code.launchpad.net |
Commit message
Adds the unity-lens template from lp:unity-quickly-templates
Description of the change
Adds the unity-lens template from lp:unity-quickly-templates
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'unity-lens' | |||
2 | === added file 'unity-lens/commandsconfig' | |||
3 | --- unity-lens/commandsconfig 1970-01-01 00:00:00 +0000 | |||
4 | +++ unity-lens/commandsconfig 2012-06-12 18:05:22 +0000 | |||
5 | @@ -0,0 +1,11 @@ | |||
6 | 1 | # define parameters for commands, putting them in a list seperated | ||
7 | 2 | # by ';' | ||
8 | 3 | # if nothing specified, default is to launch command inside a project | ||
9 | 4 | # only and not be followed by a template | ||
10 | 5 | #COMMANDS_LAUNCHED_IN_OR_OUTSIDE_PROJECT = | ||
11 | 6 | COMMANDS_LAUNCHED_OUTSIDE_PROJECT_ONLY = create | ||
12 | 7 | #COMMANDS_FOLLOWED_BY_COMMAND = | ||
13 | 8 | COMMANDS_EXPOSED_IN_BAR = create;edit;install;package;release;save;share;test | ||
14 | 9 | |||
15 | 10 | [ubuntu-application] | ||
16 | 11 | IMPORT=configure;edit;debug;license;package;release;run;save;share;test | ||
17 | 0 | 12 | ||
18 | === added file 'unity-lens/create.py' | |||
19 | --- unity-lens/create.py 1970-01-01 00:00:00 +0000 | |||
20 | +++ unity-lens/create.py 2012-06-12 18:05:22 +0000 | |||
21 | @@ -0,0 +1,120 @@ | |||
22 | 1 | #!/usr/bin/python | ||
23 | 2 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
24 | 3 | # Copyright 2009 Didier Roche | ||
25 | 4 | # | ||
26 | 5 | # This file is part of Quickly ubuntu-application template | ||
27 | 6 | # | ||
28 | 7 | #This program is free software: you can redistribute it and/or modify it | ||
29 | 8 | #under the terms of the GNU General Public License version 3, as published | ||
30 | 9 | #by the Free Software Foundation. | ||
31 | 10 | |||
32 | 11 | #This program is distributed in the hope that it will be useful, but | ||
33 | 12 | #WITHOUT ANY WARRANTY; without even the implied warranties of | ||
34 | 13 | #MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
35 | 14 | #PURPOSE. See the GNU General Public License for more details. | ||
36 | 15 | |||
37 | 16 | #You should have received a copy of the GNU General Public License along | ||
38 | 17 | #with this program. If not, see <http://www.gnu.org/licenses/>. | ||
39 | 18 | |||
40 | 19 | import sys | ||
41 | 20 | import os | ||
42 | 21 | import shutil | ||
43 | 22 | import subprocess | ||
44 | 23 | |||
45 | 24 | from quickly import templatetools | ||
46 | 25 | |||
47 | 26 | import gettext | ||
48 | 27 | from gettext import gettext as _ | ||
49 | 28 | # set domain text | ||
50 | 29 | gettext.textdomain('quickly') | ||
51 | 30 | |||
52 | 31 | |||
53 | 32 | |||
54 | 33 | def usage(): | ||
55 | 34 | templatetools.print_usage(_('quickly create <template> <project-name>')) | ||
56 | 35 | def help(): | ||
57 | 36 | print _("""This will create and run a new Unity Lens, including Python | ||
58 | 37 | code, DBus files, and packaging files to make the project work. After | ||
59 | 38 | creating the project, get started by: | ||
60 | 39 | |||
61 | 40 | 1. Changing your working directory to the new project: | ||
62 | 41 | $ cd path/to/project-name | ||
63 | 42 | |||
64 | 43 | 2. Edit the Python code: | ||
65 | 44 | $ quickly edit | ||
66 | 45 | """) | ||
67 | 46 | templatetools.handle_additional_parameters(sys.argv, help, usage=usage) | ||
68 | 47 | |||
69 | 48 | |||
70 | 49 | path_and_project = sys.argv[1].split('/') | ||
71 | 50 | project_name = path_and_project[-1] | ||
72 | 51 | |||
73 | 52 | # String trailing -lens from project name, we'll add it back in as necessary | ||
74 | 53 | lens_name = project_name | ||
75 | 54 | if lens_name[:6] == 'unity-': | ||
76 | 55 | lens_name = lens_name[6:] | ||
77 | 56 | if lens_name[-5:] == '-lens': | ||
78 | 57 | lens_name = lens_name[:-5] | ||
79 | 58 | elif lens_name[:5] == 'lens-': | ||
80 | 59 | lens_name = lens_name[5:] | ||
81 | 60 | |||
82 | 61 | try: | ||
83 | 62 | project_name = templatetools.quickly_name(project_name) | ||
84 | 63 | except: | ||
85 | 64 | # user friendly message already caught in pre_create | ||
86 | 65 | sys.exit(1) | ||
87 | 66 | |||
88 | 67 | if len(path_and_project) > 1: | ||
89 | 68 | os.chdir(str(os.path.sep).join(path_and_project[0:-1])) | ||
90 | 69 | |||
91 | 70 | os.chdir(project_name) | ||
92 | 71 | |||
93 | 72 | # get origin path | ||
94 | 73 | pathname = templatetools.get_template_path_from_project() | ||
95 | 74 | abs_path_project_root = os.path.join(pathname, 'project_root') | ||
96 | 75 | |||
97 | 76 | python_name = templatetools.python_name(project_name) | ||
98 | 77 | sentence_name, camel_case_name = templatetools.conventional_names(lens_name) | ||
99 | 78 | pythonic_lens_name = templatetools.python_name(lens_name) | ||
100 | 79 | substitutions = (("project_name",project_name), | ||
101 | 80 | ("camel_case_name",camel_case_name), | ||
102 | 81 | ("python_name",python_name), | ||
103 | 82 | ("lens_name",pythonic_lens_name), | ||
104 | 83 | ("sentence_name",sentence_name),) | ||
105 | 84 | |||
106 | 85 | |||
107 | 86 | for root, dirs, files in os.walk(abs_path_project_root): | ||
108 | 87 | try: | ||
109 | 88 | relative_dir = root.split('project_root/')[1] | ||
110 | 89 | except: | ||
111 | 90 | relative_dir = "" | ||
112 | 91 | # python dir should be replace by python_name (project "pythonified" name) | ||
113 | 92 | if relative_dir.startswith('python'): | ||
114 | 93 | relative_dir = relative_dir.replace('python', python_name) | ||
115 | 94 | |||
116 | 95 | for directory in dirs: | ||
117 | 96 | if directory.startswith('python'): | ||
118 | 97 | directory = directory.replace('python', python_name) | ||
119 | 98 | os.mkdir(os.path.join(relative_dir, directory)) | ||
120 | 99 | for filename in files: | ||
121 | 100 | templatetools.file_from_template(root, filename, relative_dir, substitutions) | ||
122 | 101 | |||
123 | 102 | # set the mode to executable for executable file | ||
124 | 103 | exec_file = os.path.join('bin', project_name) | ||
125 | 104 | try: | ||
126 | 105 | os.chmod(exec_file, 0755) | ||
127 | 106 | except: | ||
128 | 107 | pass | ||
129 | 108 | |||
130 | 109 | # add it to revision control | ||
131 | 110 | print _("Creating bzr repository and committing") | ||
132 | 111 | bzr_instance = subprocess.Popen(["bzr", "init"], stdout=subprocess.PIPE) | ||
133 | 112 | bzr_instance.wait() | ||
134 | 113 | bzr_instance = subprocess.Popen(["bzr", "add"], stdout=subprocess.PIPE) | ||
135 | 114 | bzr_instance.wait() | ||
136 | 115 | bzr_instance = subprocess.Popen(["bzr", "commit", "-m", "Initial project creation with Quickly!"], stderr=subprocess.PIPE) | ||
137 | 116 | bzr_instance.wait() | ||
138 | 117 | |||
139 | 118 | print _("Congrats, your new project is setup! cd %s/ to start hacking.") % os.getcwd() | ||
140 | 119 | |||
141 | 120 | sys.exit(0) | ||
142 | 0 | 121 | ||
143 | === added file 'unity-lens/install.py' | |||
144 | --- unity-lens/install.py 1970-01-01 00:00:00 +0000 | |||
145 | +++ unity-lens/install.py 2012-06-12 18:05:22 +0000 | |||
146 | @@ -0,0 +1,72 @@ | |||
147 | 1 | #!/usr/bin/python | ||
148 | 2 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
149 | 3 | # Copyright 2009 Didier Roche | ||
150 | 4 | # | ||
151 | 5 | # This file is part of Quickly ubuntu-application template | ||
152 | 6 | # | ||
153 | 7 | #This program is free software: you can redistribute it and/or modify it | ||
154 | 8 | #under the terms of the GNU General Public License version 3, as published | ||
155 | 9 | #by the Free Software Foundation. | ||
156 | 10 | |||
157 | 11 | #This program is distributed in the hope that it will be useful, but | ||
158 | 12 | #WITHOUT ANY WARRANTY; without even the implied warranties of | ||
159 | 13 | #MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
160 | 14 | #PURPOSE. See the GNU General Public License for more details. | ||
161 | 15 | |||
162 | 16 | #You should have received a copy of the GNU General Public License along | ||
163 | 17 | #with this program. If not, see <http://www.gnu.org/licenses/>. | ||
164 | 18 | |||
165 | 19 | import sys | ||
166 | 20 | import os | ||
167 | 21 | import shutil | ||
168 | 22 | import subprocess | ||
169 | 23 | |||
170 | 24 | from quickly import configurationhandler | ||
171 | 25 | from quickly import templatetools | ||
172 | 26 | |||
173 | 27 | import gettext | ||
174 | 28 | from gettext import gettext as _ | ||
175 | 29 | # set domain text | ||
176 | 30 | gettext.textdomain('quickly') | ||
177 | 31 | |||
178 | 32 | |||
179 | 33 | |||
180 | 34 | def usage(): | ||
181 | 35 | templatetools.print_usage(_('sudo quickly install')) | ||
182 | 36 | def help(): | ||
183 | 37 | print _("""This will install your lens description file into | ||
184 | 38 | /usr/share/unity/leneses/ and restart Unity so that your lens will be available | ||
185 | 39 | for testing""") | ||
186 | 40 | templatetools.handle_additional_parameters(sys.argv, help, usage=usage) | ||
187 | 41 | |||
188 | 42 | if os.getuid() > 0: | ||
189 | 43 | print _("Only root can install lens files") | ||
190 | 44 | sys.exit(1) | ||
191 | 45 | |||
192 | 46 | # if config not already loaded | ||
193 | 47 | if not configurationhandler.project_config: | ||
194 | 48 | configurationhandler.loadConfig() | ||
195 | 49 | |||
196 | 50 | project_name = configurationhandler.project_config['project'] | ||
197 | 51 | # String trailing -lens from project name, we'll add it back in as necessary | ||
198 | 52 | lens_name = project_name | ||
199 | 53 | if lens_name[:6] == 'unity-': | ||
200 | 54 | lens_name = lens_name[6:] | ||
201 | 55 | if lens_name[-5:] == '-lens': | ||
202 | 56 | lens_name = lens_name[:-5] | ||
203 | 57 | elif lens_name[:5] == 'lens-': | ||
204 | 58 | lens_name = lens_name[5:] | ||
205 | 59 | |||
206 | 60 | # install lens config file | ||
207 | 61 | if not os.path.exists('/usr/share/unity/lenses/%s' % lens_name): | ||
208 | 62 | os.mkdir('/usr/share/unity/lenses/%s' % lens_name) | ||
209 | 63 | shutil.copy('./%s.lens' % lens_name, '/usr/share/unity/lenses/%s' % lens_name) | ||
210 | 64 | shutil.copy('./unity-lens-%s.svg' % lens_name, '/usr/share/unity/lenses/%s' % lens_name) | ||
211 | 65 | |||
212 | 66 | # restart unity | ||
213 | 67 | os.system('sudo -u %s unity --replace &' % os.environ.get('SUDO_USER', 'root')) | ||
214 | 68 | |||
215 | 69 | print _("Congrats, your new lens has been installed.") | ||
216 | 70 | |||
217 | 71 | |||
218 | 72 | sys.exit(0) | ||
219 | 0 | 73 | ||
220 | === added directory 'unity-lens/project_root' | |||
221 | === added file 'unity-lens/project_root/AUTHORS' | |||
222 | --- unity-lens/project_root/AUTHORS 1970-01-01 00:00:00 +0000 | |||
223 | +++ unity-lens/project_root/AUTHORS 2012-06-12 18:05:22 +0000 | |||
224 | @@ -0,0 +1,1 @@ | |||
225 | 1 | Copyright (C) YYYY <Your Name> <Your E-mail> | ||
226 | 0 | 2 | ||
227 | === added directory 'unity-lens/project_root/bin' | |||
228 | === added file 'unity-lens/project_root/bin/project_name' | |||
229 | --- unity-lens/project_root/bin/project_name 1970-01-01 00:00:00 +0000 | |||
230 | +++ unity-lens/project_root/bin/project_name 2012-06-12 18:05:22 +0000 | |||
231 | @@ -0,0 +1,31 @@ | |||
232 | 1 | #!/usr/bin/python | ||
233 | 2 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
234 | 3 | ### BEGIN LICENSE | ||
235 | 4 | # This file is in the public domain | ||
236 | 5 | ### END LICENSE | ||
237 | 6 | |||
238 | 7 | import os | ||
239 | 8 | import sys | ||
240 | 9 | |||
241 | 10 | from singlet.utils import run_lens | ||
242 | 11 | |||
243 | 12 | # Add project root directory (enable symlink, and trunk execution). | ||
244 | 13 | PROJECT_ROOT_DIRECTORY = os.path.abspath( | ||
245 | 14 | os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))) | ||
246 | 15 | |||
247 | 16 | python_path = [] | ||
248 | 17 | if os.path.abspath(__file__).startswith('/opt'): | ||
249 | 18 | syspath = sys.path[:] # copy to avoid infinite loop in pending objects | ||
250 | 19 | for path in syspath: | ||
251 | 20 | opt_path = path.replace('/usr', '/opt/extras.ubuntu.com/project_name') | ||
252 | 21 | python_path.insert(0, opt_path) | ||
253 | 22 | sys.path.insert(0, opt_path) | ||
254 | 23 | if (os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, 'python_name')) | ||
255 | 24 | and PROJECT_ROOT_DIRECTORY not in sys.path): | ||
256 | 25 | python_path.insert(0, PROJECT_ROOT_DIRECTORY) | ||
257 | 26 | sys.path.insert(0, PROJECT_ROOT_DIRECTORY) | ||
258 | 27 | if python_path: | ||
259 | 28 | os.putenv('PYTHONPATH', "%s:%s" % (os.getenv('PYTHONPATH', ''), ':'.join(python_path))) # for subprocesses | ||
260 | 29 | |||
261 | 30 | from python_name import camel_case_nameLens | ||
262 | 31 | run_lens(camel_case_nameLens, sys.argv) | ||
263 | 0 | 32 | ||
264 | === added file 'unity-lens/project_root/lens_name.lens' | |||
265 | --- unity-lens/project_root/lens_name.lens 1970-01-01 00:00:00 +0000 | |||
266 | +++ unity-lens/project_root/lens_name.lens 2012-06-12 18:05:22 +0000 | |||
267 | @@ -0,0 +1,11 @@ | |||
268 | 1 | [Lens] | ||
269 | 2 | DBusName=unity.singlet.lens.lens_name | ||
270 | 3 | DBusPath=/unity/singlet/lens/lens_name | ||
271 | 4 | Name=sentence_name | ||
272 | 5 | Icon=/usr/share/unity/lenses/lens_name/unity-lens-lens_name.svg | ||
273 | 6 | Description=sentence_name Lens | ||
274 | 7 | SearchHint=Search sentence_name | ||
275 | 8 | #Shortcut=c | ||
276 | 9 | |||
277 | 10 | [Desktop Entry] | ||
278 | 11 | X-Ubuntu-Gettext-Domain=project_name | ||
279 | 0 | 12 | ||
280 | === added directory 'unity-lens/project_root/python' | |||
281 | === added file 'unity-lens/project_root/python/__init__.py' | |||
282 | --- unity-lens/project_root/python/__init__.py 1970-01-01 00:00:00 +0000 | |||
283 | +++ unity-lens/project_root/python/__init__.py 2012-06-12 18:05:22 +0000 | |||
284 | @@ -0,0 +1,33 @@ | |||
285 | 1 | import logging | ||
286 | 2 | import optparse | ||
287 | 3 | |||
288 | 4 | import gettext | ||
289 | 5 | from gettext import gettext as _ | ||
290 | 6 | gettext.textdomain('project_name') | ||
291 | 7 | |||
292 | 8 | from singlet.lens import SingleScopeLens, IconViewCategory, ListViewCategory | ||
293 | 9 | |||
294 | 10 | from python_name import python_nameconfig | ||
295 | 11 | |||
296 | 12 | class camel_case_nameLens(SingleScopeLens): | ||
297 | 13 | |||
298 | 14 | class Meta: | ||
299 | 15 | name = 'lens_name' | ||
300 | 16 | description = 'sentence_name Lens' | ||
301 | 17 | search_hint = 'Search sentence_name' | ||
302 | 18 | icon = 'lens_name.svg' | ||
303 | 19 | search_on_blank=True | ||
304 | 20 | |||
305 | 21 | # TODO: Add your categories | ||
306 | 22 | example_category = ListViewCategory("Examples", 'help') | ||
307 | 23 | |||
308 | 24 | def search(self, search, results): | ||
309 | 25 | # TODO: Add your search results | ||
310 | 26 | results.append('https://wiki.ubuntu.com/Unity/Lenses/Singlet', | ||
311 | 27 | 'ubuntu-logo', | ||
312 | 28 | self.example_category, | ||
313 | 29 | "text/html", | ||
314 | 30 | 'Learn More', | ||
315 | 31 | 'Find out how to write your Unity Lens', | ||
316 | 32 | 'https://wiki.ubuntu.com/Unity/Lenses/Singlet') | ||
317 | 33 | pass | ||
318 | 0 | 34 | ||
319 | === added file 'unity-lens/project_root/python/python_nameconfig.py' | |||
320 | --- unity-lens/project_root/python/python_nameconfig.py 1970-01-01 00:00:00 +0000 | |||
321 | +++ unity-lens/project_root/python/python_nameconfig.py 2012-06-12 18:05:22 +0000 | |||
322 | @@ -0,0 +1,59 @@ | |||
323 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
324 | 2 | ### BEGIN LICENSE | ||
325 | 3 | # This file is in the public domain | ||
326 | 4 | ### END LICENSE | ||
327 | 5 | |||
328 | 6 | # THIS IS camel_case_name CONFIGURATION FILE | ||
329 | 7 | # YOU CAN PUT THERE SOME GLOBAL VALUE | ||
330 | 8 | # Do not touch unless you know what you're doing. | ||
331 | 9 | # you're warned :) | ||
332 | 10 | |||
333 | 11 | __all__ = [ | ||
334 | 12 | 'project_path_not_found', | ||
335 | 13 | 'get_data_file', | ||
336 | 14 | 'get_data_path', | ||
337 | 15 | ] | ||
338 | 16 | |||
339 | 17 | # Where your project will look for your data (for instance, images and ui | ||
340 | 18 | # files). By default, this is ../data, relative your trunk layout | ||
341 | 19 | __python_name_data_directory__ = '../data/' | ||
342 | 20 | __license__ = '' | ||
343 | 21 | __version__ = 'VERSION' | ||
344 | 22 | |||
345 | 23 | import os | ||
346 | 24 | |||
347 | 25 | import gettext | ||
348 | 26 | from gettext import gettext as _ | ||
349 | 27 | gettext.textdomain('project_name') | ||
350 | 28 | |||
351 | 29 | class project_path_not_found(Exception): | ||
352 | 30 | """Raised when we can't find the project directory.""" | ||
353 | 31 | |||
354 | 32 | |||
355 | 33 | def get_data_file(*path_segments): | ||
356 | 34 | """Get the full path to a data file. | ||
357 | 35 | |||
358 | 36 | Returns the path to a file underneath the data directory (as defined by | ||
359 | 37 | `get_data_path`). Equivalent to os.path.join(get_data_path(), | ||
360 | 38 | *path_segments). | ||
361 | 39 | """ | ||
362 | 40 | return os.path.join(get_data_path(), *path_segments) | ||
363 | 41 | |||
364 | 42 | |||
365 | 43 | def get_data_path(): | ||
366 | 44 | """Retrieve project_name data path | ||
367 | 45 | |||
368 | 46 | This path is by default <python_name_lib_path>/../data/ in trunk | ||
369 | 47 | and /usr/share/project_name in an installed version but this path | ||
370 | 48 | is specified at installation time. | ||
371 | 49 | """ | ||
372 | 50 | |||
373 | 51 | # Get pathname absolute or relative. | ||
374 | 52 | path = os.path.join( | ||
375 | 53 | os.path.dirname(__file__), __python_name_data_directory__) | ||
376 | 54 | |||
377 | 55 | abs_data_path = os.path.abspath(path) | ||
378 | 56 | if not os.path.exists(abs_data_path): | ||
379 | 57 | raise project_path_not_found | ||
380 | 58 | |||
381 | 59 | return abs_data_path | ||
382 | 0 | 60 | ||
383 | === added file 'unity-lens/project_root/setup.py' | |||
384 | --- unity-lens/project_root/setup.py 1970-01-01 00:00:00 +0000 | |||
385 | +++ unity-lens/project_root/setup.py 2012-06-12 18:05:22 +0000 | |||
386 | @@ -0,0 +1,75 @@ | |||
387 | 1 | #!/usr/bin/env python | ||
388 | 2 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
389 | 3 | ### BEGIN LICENSE | ||
390 | 4 | # This file is in the public domain | ||
391 | 5 | ### END LICENSE | ||
392 | 6 | |||
393 | 7 | ###################### DO NOT TOUCH THIS (HEAD TO THE SECOND PART) ###################### | ||
394 | 8 | |||
395 | 9 | import os | ||
396 | 10 | import sys | ||
397 | 11 | |||
398 | 12 | try: | ||
399 | 13 | import DistUtilsExtra.auto | ||
400 | 14 | from DistUtilsExtra.command import build_extra | ||
401 | 15 | except ImportError: | ||
402 | 16 | print >> sys.stderr, 'To build project_name you need https://launchpad.net/python-distutils-extra' | ||
403 | 17 | sys.exit(1) | ||
404 | 18 | assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18' | ||
405 | 19 | |||
406 | 20 | def update_config(values = {}): | ||
407 | 21 | |||
408 | 22 | oldvalues = {} | ||
409 | 23 | try: | ||
410 | 24 | fin = file('python_name/python_nameconfig.py', 'r') | ||
411 | 25 | fout = file(fin.name + '.new', 'w') | ||
412 | 26 | |||
413 | 27 | for line in fin: | ||
414 | 28 | fields = line.split(' = ') # Separate variable from value | ||
415 | 29 | if fields[0] in values: | ||
416 | 30 | oldvalues[fields[0]] = fields[1].strip() | ||
417 | 31 | line = "%s = %s\n" % (fields[0], values[fields[0]]) | ||
418 | 32 | fout.write(line) | ||
419 | 33 | |||
420 | 34 | fout.flush() | ||
421 | 35 | fout.close() | ||
422 | 36 | fin.close() | ||
423 | 37 | os.rename(fout.name, fin.name) | ||
424 | 38 | except (OSError, IOError), e: | ||
425 | 39 | print ("ERROR: Can't find python_name/python_nameconfig.py") | ||
426 | 40 | sys.exit(1) | ||
427 | 41 | return oldvalues | ||
428 | 42 | |||
429 | 43 | |||
430 | 44 | class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto): | ||
431 | 45 | def run(self): | ||
432 | 46 | values = {'__python_name_data_directory__': "'%s'" % (self.prefix + '/share/project_name/'), | ||
433 | 47 | '__version__': "'%s'" % (self.distribution.get_version())} | ||
434 | 48 | previous_values = update_config(values) | ||
435 | 49 | DistUtilsExtra.auto.install_auto.run(self) | ||
436 | 50 | update_config(previous_values) | ||
437 | 51 | |||
438 | 52 | |||
439 | 53 | |||
440 | 54 | ################################################################################## | ||
441 | 55 | ###################### YOU SHOULD MODIFY ONLY WHAT IS BELOW ###################### | ||
442 | 56 | ################################################################################## | ||
443 | 57 | |||
444 | 58 | DistUtilsExtra.auto.setup( | ||
445 | 59 | name='project_name', | ||
446 | 60 | version='0.1', | ||
447 | 61 | #license='GPL-3', | ||
448 | 62 | #author='Your Name', | ||
449 | 63 | #author_email='email@ubuntu.com', | ||
450 | 64 | #description='UI for managing …', | ||
451 | 65 | #long_description='Here a longer description', | ||
452 | 66 | #url='https://launchpad.net/project_name', | ||
453 | 67 | data_files=[ | ||
454 | 68 | ('share/unity/lenses/lens_name', ['lens_name.lens']), | ||
455 | 69 | ('share/dbus-1/services', ['unity-lens-lens_name.service']), | ||
456 | 70 | ('share/unity/lenses/lens_name', ['unity-lens-lens_name.svg']), | ||
457 | 71 | ('bin', ['bin/project_name']), | ||
458 | 72 | ], | ||
459 | 73 | cmdclass={"build": build_extra.build_extra, 'install': InstallAndUpdateDataDirectory} | ||
460 | 74 | ) | ||
461 | 75 | |||
462 | 0 | 76 | ||
463 | === added file 'unity-lens/project_root/unity-lens-lens_name.service' | |||
464 | --- unity-lens/project_root/unity-lens-lens_name.service 1970-01-01 00:00:00 +0000 | |||
465 | +++ unity-lens/project_root/unity-lens-lens_name.service 2012-06-12 18:05:22 +0000 | |||
466 | @@ -0,0 +1,3 @@ | |||
467 | 1 | [D-BUS Service] | ||
468 | 2 | Name=unity.singlet.lens.lens_name | ||
469 | 3 | Exec=/usr/bin/project_name | ||
470 | 0 | 4 | ||
471 | === added file 'unity-lens/project_root/unity-lens-lens_name.svg' | |||
472 | --- unity-lens/project_root/unity-lens-lens_name.svg 1970-01-01 00:00:00 +0000 | |||
473 | +++ unity-lens/project_root/unity-lens-lens_name.svg 2012-06-12 18:05:22 +0000 | |||
474 | @@ -0,0 +1,52 @@ | |||
475 | 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
476 | 2 | <!-- Created with Inkscape (http://www.inkscape.org/) --> | ||
477 | 3 | <svg id="svg3386" xmlns="http://www.w3.org/2000/svg" height="24" width="24" version="1.0" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
478 | 4 | <defs id="defs3388"> | ||
479 | 5 | <linearGradient id="linearGradient5060"> | ||
480 | 6 | <stop id="stop5062" offset="0"/> | ||
481 | 7 | <stop id="stop5064" style="stop-opacity:0" offset="1"/> | ||
482 | 8 | </linearGradient> | ||
483 | 9 | <linearGradient id="linearGradient2425" y2="5.4565" gradientUnits="userSpaceOnUse" x2="36.358" gradientTransform="matrix(.47785 0 0 .55248 .37225 -.076128)" y1="8.059" x1="32.892"> | ||
484 | 10 | <stop id="stop8591" style="stop-color:#fefefe" offset="0"/> | ||
485 | 11 | <stop id="stop8593" style="stop-color:#cbcbcb" offset="1"/> | ||
486 | 12 | </linearGradient> | ||
487 | 13 | <linearGradient id="linearGradient2429" y2="46.017" gradientUnits="userSpaceOnUse" x2="24" gradientTransform="matrix(.45454 0 0 .46512 1.0909 .33723)" y1="2" x1="24"> | ||
488 | 14 | <stop id="stop3213" style="stop-color:#fff" offset="0"/> | ||
489 | 15 | <stop id="stop3215" style="stop-color:#fff;stop-opacity:0" offset="1"/> | ||
490 | 16 | </linearGradient> | ||
491 | 17 | <radialGradient id="radialGradient2432" gradientUnits="userSpaceOnUse" cy="102.7" cx="92.09" gradientTransform="matrix(.17021 0 0 -.19072 1.1064 23.717)" r="139.56"> | ||
492 | 18 | <stop id="stop41" style="stop-color:#b7b8b9" offset="0"/> | ||
493 | 19 | <stop id="stop47" style="stop-color:#ececec" offset=".17403"/> | ||
494 | 20 | <stop id="stop49" style="stop-color:#fafafa;stop-opacity:0" offset=".23908"/> | ||
495 | 21 | <stop id="stop51" style="stop-color:#fff;stop-opacity:0" offset=".30111"/> | ||
496 | 22 | <stop id="stop53" style="stop-color:#fafafa;stop-opacity:0" offset=".53130"/> | ||
497 | 23 | <stop id="stop55" style="stop-color:#ebecec;stop-opacity:0" offset=".84490"/> | ||
498 | 24 | <stop id="stop57" style="stop-color:#e1e2e3;stop-opacity:0" offset="1"/> | ||
499 | 25 | </radialGradient> | ||
500 | 26 | <linearGradient id="linearGradient2435" y2="47.013" gradientUnits="userSpaceOnUse" x2="25.132" gradientTransform="matrix(.48572 0 0 .47803 .34283 -.70595)" y1=".98521" x1="25.132"> | ||
501 | 27 | <stop id="stop3602" style="stop-color:#f4f4f4" offset="0"/> | ||
502 | 28 | <stop id="stop3604" style="stop-color:#dbdbdb" offset="1"/> | ||
503 | 29 | </linearGradient> | ||
504 | 30 | <linearGradient id="linearGradient2438" y2="2.9062" gradientUnits="userSpaceOnUse" x2="-51.786" gradientTransform="matrix(.39221 0 0 .44736 29.199 -1.2387)" y1="50.786" x1="-51.786"> | ||
505 | 31 | <stop id="stop3106" style="stop-color:#aaa" offset="0"/> | ||
506 | 32 | <stop id="stop3108" style="stop-color:#c8c8c8" offset="1"/> | ||
507 | 33 | </linearGradient> | ||
508 | 34 | <radialGradient id="radialGradient2441" xlink:href="#linearGradient5060" gradientUnits="userSpaceOnUse" cy="486.65" cx="605.71" gradientTransform="matrix(.012049 0 0 .0082353 13.239 18.981)" r="117.14"/> | ||
509 | 35 | <radialGradient id="radialGradient2444" xlink:href="#linearGradient5060" gradientUnits="userSpaceOnUse" cy="486.65" cx="605.71" gradientTransform="matrix(-.012049 0 0 .0082353 10.761 18.981)" r="117.14"/> | ||
510 | 36 | <linearGradient id="linearGradient2447" y2="609.51" gradientUnits="userSpaceOnUse" x2="302.86" gradientTransform="matrix(.035207 0 0 .0082353 -.72485 18.981)" y1="366.65" x1="302.86"> | ||
511 | 37 | <stop id="stop5050" style="stop-opacity:0" offset="0"/> | ||
512 | 38 | <stop id="stop5056" offset=".5"/> | ||
513 | 39 | <stop id="stop5052" style="stop-opacity:0" offset="1"/> | ||
514 | 40 | </linearGradient> | ||
515 | 41 | </defs> | ||
516 | 42 | <rect id="rect2879" style="opacity:.15;fill:url(#linearGradient2447)" height="2" width="17" y="22" x="3.5"/> | ||
517 | 43 | <path id="path2881" style="opacity:.15;fill:url(#radialGradient2444)" d="m3.5 22v1.9999c-0.6205 0.004-1.5-0.448-1.5-1s0.6924-1 1.5-1z"/> | ||
518 | 44 | <path id="path2883" style="opacity:.15;fill:url(#radialGradient2441)" d="m20.5 22v1.9999c0.62047 0.0038 1.5-0.44807 1.5-1.0001 0-0.552-0.6924-0.99982-1.5-0.99982z"/> | ||
519 | 45 | <path id="path4160" style="stroke-linejoin:round;stroke:url(#linearGradient2438);stroke-width:.99992;fill:url(#linearGradient2435)" d="m3.5 0.49996h11.5c0.683 0.2373 4.541 3.1281 5.5 5 0 5.7292 0.000039 11.271 0.000039 17h-17v-22z"/> | ||
520 | 46 | <path id="path4191" style="fill:url(#radialGradient2432)" d="m4.1702 22c-0.0938 0-0.1702-0.086-0.1702-0.191v-20.598c0-0.105 0.0764-0.1905 0.1702-0.1905 3.5215 0.0527 7.4238-0.07883 10.941 0.0131l4.839 4.3272 0.05 16.448c0 0.105-0.076 0.191-0.17 0.191h-15.66z"/> | ||
521 | 47 | <path id="path2435" style="opacity:.6;stroke:url(#linearGradient2429);fill:none" d="m19.5 5.677v15.823h-15v-20h10.394"/> | ||
522 | 48 | <path id="path3370" style="opacity:.2;fill-rule:evenodd" d="m14.075 1c1.1563 0.32877 0.33906 4.6144 0.33906 4.6144s4.5154-0.42774 5.6077 1.195c1.489 2.2122-0.068-0.6352-0.173-0.8217-0.756-1.3401-3.867-4.5471-5.046-4.9412-0.088-0.0295-0.283-0.0465-0.728-0.0465z"/> | ||
523 | 49 | <path id="path4474" style="fill:url(#linearGradient2425);fill-rule:evenodd" d="m14 1c1.5262 0 1 4 1 4s4.9921-0.45326 4.9921 2c0-0.59774 0.05575-1.4784-0.06407-1.6559-0.839-1.243-3.744-3.8619-4.798-4.2976-0.086-0.0356-0.686-0.0465-1.13-0.0465z"/> | ||
524 | 50 | <path id="path9053" style="opacity:.6" d="m12.455 15.982c-0.03304-1.1794 0.23119-2.3243 1.3454-3.1353 1.1769-0.91718 2.3104-2.0647 2.1906-3.4174-0.026-1.3047-1.546-2.327-3.183-2.474-1.843-0.2551-4.0715 0.3759-4.6888 1.8145-0.3131 0.6997-0.0227 1.9552 1.0279 1.9552 0.61453 0 0.89678-0.39697 0.94315-0.7601 0.03508-0.27476-0.07772-0.52011-0.14433-0.74706-0.075905-0.2586 0.24813-0.75978 0.60104-0.96399 0.2949-0.17064 0.60344-0.22785 0.64892-0.23878 1.0591-0.25452 2.1148 0.30768 2.5553 0.99196 0.44048 0.68427-0.04435 1.7222-0.74143 2.7315-0.69707 1.0093-1.4452 2.1557-1.4422 3.3734 0 0.46356-0.0413 0.62104-0.01196 0.80859 0.02345 0.14984 0.51961 0.13174 0.89958 0.06145zm-0.48333 1.5874c-1.0126-0.05497-1.7135 1.093-1.1052 1.8244 0.54328 0.80755 2.0665 0.6082 2.3276-0.30627 0.27143-0.71112-0.38177-1.53-1.2224-1.5181v0.000001z"/> | ||
525 | 51 | <path id="path3298" style="opacity:.4;fill:#fff" d="m12.455 16.482c-0.03304-1.1794 0.23119-2.3243 1.3454-3.1353 1.1769-0.91718 2.3104-2.0647 2.1906-3.4174-0.026-1.3047-1.546-2.327-3.183-2.474-1.843-0.2551-4.0715 0.3759-4.6888 1.8145-0.3131 0.6997-0.0227 1.9552 1.0279 1.9552 0.61453 0 0.89678-0.39697 0.94315-0.7601 0.03508-0.27476-0.07772-0.52011-0.14433-0.74706-0.075905-0.2586 0.24813-0.75978 0.60104-0.96398 0.2949-0.17064 0.60344-0.22785 0.64892-0.23878 1.0591-0.25452 2.1148 0.30768 2.5553 0.99196 0.44048 0.68427-0.04435 1.7222-0.74143 2.7315-0.69707 1.0093-1.4452 2.1557-1.4422 3.3734 0 0.46356-0.0413 0.62104-0.01196 0.80859 0.02345 0.14984 0.51961 0.13174 0.89958 0.06145zm-0.48333 1.5874c-1.0126-0.05497-1.7135 1.093-1.1052 1.8244 0.54328 0.80755 2.0665 0.6082 2.3276-0.30627 0.27143-0.71112-0.38177-1.53-1.2224-1.5181z"/> | ||
526 | 52 | </svg> | ||
527 | 0 | 53 | ||
528 | === added file 'unity-lens/run.py' | |||
529 | --- unity-lens/run.py 1970-01-01 00:00:00 +0000 | |||
530 | +++ unity-lens/run.py 2012-06-12 18:05:22 +0000 | |||
531 | @@ -0,0 +1,75 @@ | |||
532 | 1 | #!/usr/bin/python | ||
533 | 2 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
534 | 3 | # Copyright 2009 Didier Roche | ||
535 | 4 | # | ||
536 | 5 | # This file is part of Quickly ubuntu-application template | ||
537 | 6 | # | ||
538 | 7 | #This program is free software: you can redistribute it and/or modify it | ||
539 | 8 | #under the terms of the GNU General Public License version 3, as published | ||
540 | 9 | #by the Free Software Foundation. | ||
541 | 10 | |||
542 | 11 | #This program is distributed in the hope that it will be useful, but | ||
543 | 12 | #WITHOUT ANY WARRANTY; without even the implied warranties of | ||
544 | 13 | #MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
545 | 14 | #PURPOSE. See the GNU General Public License for more details. | ||
546 | 15 | |||
547 | 16 | #You should have received a copy of the GNU General Public License along | ||
548 | 17 | #with this program. If not, see <http://www.gnu.org/licenses/>. | ||
549 | 18 | |||
550 | 19 | |||
551 | 20 | import os | ||
552 | 21 | import stat | ||
553 | 22 | import sys | ||
554 | 23 | import subprocess | ||
555 | 24 | |||
556 | 25 | import gettext | ||
557 | 26 | from gettext import gettext as _ | ||
558 | 27 | gettext.textdomain('quickly') | ||
559 | 28 | |||
560 | 29 | from quickly import configurationhandler | ||
561 | 30 | from quickly import templatetools | ||
562 | 31 | |||
563 | 32 | def usage(): | ||
564 | 33 | templatetools.print_usage(_('quickly run -- [program arguments]')) | ||
565 | 34 | def help(): | ||
566 | 35 | print _("""Runs your lens. This is the best way to try test it out | ||
567 | 36 | while you are developing it. It starts up the main project window. | ||
568 | 37 | |||
569 | 38 | You will need to have installed your lens using 'sudo quickly install' before | ||
570 | 39 | you can run it. | ||
571 | 40 | |||
572 | 41 | $ quickly run""") | ||
573 | 42 | templatetools.handle_additional_parameters(sys.argv, help, usage=usage) | ||
574 | 43 | |||
575 | 44 | # if config not already loaded | ||
576 | 45 | if not configurationhandler.project_config: | ||
577 | 46 | configurationhandler.loadConfig() | ||
578 | 47 | |||
579 | 48 | project_name = configurationhandler.project_config['project'] | ||
580 | 49 | # String trailing -lens from project name, we'll add it back in as necessary | ||
581 | 50 | lens_name = project_name | ||
582 | 51 | if lens_name[:6] == 'unity-': | ||
583 | 52 | lens_name = lens_name[6:] | ||
584 | 53 | if lens_name[-5:] == '-lens': | ||
585 | 54 | lens_name = lens_name[:-5] | ||
586 | 55 | elif lens_name[:5] == 'lens-': | ||
587 | 56 | lens_name = lens_name[5:] | ||
588 | 57 | if not os.path.exists('/usr/share/unity/lenses/%s/%s.lens' % (lens_name, lens_name)): | ||
589 | 58 | print _("You need to install your lens by running 'sudo quickly install' before it can be run") | ||
590 | 59 | sys.exit(1) | ||
591 | 60 | |||
592 | 61 | env = os.environ.copy() | ||
593 | 62 | |||
594 | 63 | project_bin = 'bin/' + configurationhandler.project_config['project'] | ||
595 | 64 | command_line = [project_bin] | ||
596 | 65 | command_line.extend([arg for arg in sys.argv[1:] if arg != "--"]) | ||
597 | 66 | |||
598 | 67 | # run with args if bin/project exist | ||
599 | 68 | st = os.stat(project_bin) | ||
600 | 69 | mode = st[stat.ST_MODE] | ||
601 | 70 | if mode & stat.S_IEXEC: | ||
602 | 71 | subprocess.call(command_line, env=env) | ||
603 | 72 | else: | ||
604 | 73 | print _("Can't execute %s") % project_bin | ||
605 | 74 | sys.exit(1) | ||
606 | 75 | |||
607 | 0 | 76 | ||
608 | === added file 'unity-lens/uninstall.py' | |||
609 | --- unity-lens/uninstall.py 1970-01-01 00:00:00 +0000 | |||
610 | +++ unity-lens/uninstall.py 2012-06-12 18:05:22 +0000 | |||
611 | @@ -0,0 +1,70 @@ | |||
612 | 1 | #!/usr/bin/python | ||
613 | 2 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
614 | 3 | # Copyright 2009 Didier Roche | ||
615 | 4 | # | ||
616 | 5 | # This file is part of Quickly ubuntu-application template | ||
617 | 6 | # | ||
618 | 7 | #This program is free software: you can redistribute it and/or modify it | ||
619 | 8 | #under the terms of the GNU General Public License version 3, as published | ||
620 | 9 | #by the Free Software Foundation. | ||
621 | 10 | |||
622 | 11 | #This program is distributed in the hope that it will be useful, but | ||
623 | 12 | #WITHOUT ANY WARRANTY; without even the implied warranties of | ||
624 | 13 | #MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
625 | 14 | #PURPOSE. See the GNU General Public License for more details. | ||
626 | 15 | |||
627 | 16 | #You should have received a copy of the GNU General Public License along | ||
628 | 17 | #with this program. If not, see <http://www.gnu.org/licenses/>. | ||
629 | 18 | |||
630 | 19 | import sys | ||
631 | 20 | import os | ||
632 | 21 | import shutil | ||
633 | 22 | import subprocess | ||
634 | 23 | |||
635 | 24 | from quickly import configurationhandler | ||
636 | 25 | from quickly import templatetools | ||
637 | 26 | |||
638 | 27 | import gettext | ||
639 | 28 | from gettext import gettext as _ | ||
640 | 29 | # set domain text | ||
641 | 30 | gettext.textdomain('quickly') | ||
642 | 31 | |||
643 | 32 | |||
644 | 33 | |||
645 | 34 | def usage(): | ||
646 | 35 | templatetools.print_usage(_('sudo quickly uninstall')) | ||
647 | 36 | def help(): | ||
648 | 37 | print _("""This will remove your lens description file from | ||
649 | 38 | /usr/share/unity/leneses/ and restart Unity""") | ||
650 | 39 | templatetools.handle_additional_parameters(sys.argv, help, usage=usage) | ||
651 | 40 | |||
652 | 41 | if os.getuid() > 0: | ||
653 | 42 | print _("Only root can uninstall lens files") | ||
654 | 43 | sys.exit(1) | ||
655 | 44 | |||
656 | 45 | # if config not already loaded | ||
657 | 46 | if not configurationhandler.project_config: | ||
658 | 47 | configurationhandler.loadConfig() | ||
659 | 48 | |||
660 | 49 | project_name = configurationhandler.project_config['project'] | ||
661 | 50 | # String trailing -lens from project name, we'll add it back in as necessary | ||
662 | 51 | lens_name = project_name | ||
663 | 52 | if lens_name[:6] == 'unity-': | ||
664 | 53 | lens_name = lens_name[6:] | ||
665 | 54 | if lens_name[-5:] == '-lens': | ||
666 | 55 | lens_name = lens_name[:-5] | ||
667 | 56 | elif lens_name[:5] == 'lens-': | ||
668 | 57 | lens_name = lens_name[5:] | ||
669 | 58 | |||
670 | 59 | # uninstall lens config file | ||
671 | 60 | os.remove(os.path.join('/usr/share/unity/lenses/%s' % lens_name, '%s.lens' % lens_name)) | ||
672 | 61 | os.remove(os.path.join('/usr/share/unity/lenses/%s' % lens_name, 'unity-lens-%s.svg' % lens_name)) | ||
673 | 62 | os.rmdir('/usr/share/unity/lenses/%s' % lens_name) | ||
674 | 63 | |||
675 | 64 | # restart unity | ||
676 | 65 | os.system('sudo -u %s unity --replace &' % os.environ.get('SUDO_USER', 'root')) | ||
677 | 66 | |||
678 | 67 | print _("Congrats, your new lens has been removed.") | ||
679 | 68 | |||
680 | 69 | |||
681 | 70 | sys.exit(0) |
Thanks Mike, looks good to me as the second addition to the Quickly community templates. As part of quickly- template- hackers you should have permissions to push the branch already, so feel free to do so.