Merge lp:~tony-badwolf/quickly/quickly-extras into lp:quickly

Proposed by Tony Byrne
Status: Needs review
Proposed branch: lp:~tony-badwolf/quickly/quickly-extras
Merge into: lp:quickly
Diff against target: 134 lines (+51/-23)
3 files modified
data/templates/ubuntu-application/project_root/bin/project_name (+32/-8)
data/templates/ubuntu-application/project_root/setup.py (+18/-2)
data/templates/ubuntu-application/run.py (+1/-13)
To merge this branch: bzr merge lp:~tony-badwolf/quickly/quickly-extras
Reviewer Review Type Date Requested Status
Michael Terry (community) Needs Fixing
Review via email: mp+106498@code.launchpad.net

Description of the change

quickly package --extras does not set up paths and environment correctly and omits compiling schemas
This branch fixes paths and environment for working in /opt

Partially addresses bug 998910 quickly package --extras creates broken deb
and fixes related bug 976817 Compiling schemas not part of the application template

TODO: glib-compile-schemas needs to be called as part of quickly package --extras

To post a comment you must log in.
Revision history for this message
Michael Terry (mterry) wrote :

So I finally got around to looking at this! Sorry! This is a good code change. The one I put in for an SRU did a similar thing, but was too hacky to stay in.

The bin/project_name changes make sense, though you made a lot of not-strictly-necessary changes that will make it hard to 'quickly upgrade' existing setup.py's to match. It might be better to reduce your changes just to adding the DATADIR stuff.

In setup.py, you had good intent, but it's probably not a good idea to have setup.py look at debian/rules. setup.py is supposed to be independent and a lower conceptual level than debian/rules. I think it would be better to have bin/project_name to set DATADIR to an environment variable like QUICKLY_DATADIR or have the __python_name_data_directory__ variable be defined dynamically and duplicate some of the logic in bin/project_name.

In neither case does your branch have upgrade.py logic to match.

Our lives would be easier if we actually implemented the code we planned way back when we split the project_root up to override bin/ and python_lib/ contents at-will. I recall you were not thrilled with that plan back in the day. How do you feel these days?

review: Needs Fixing
Revision history for this message
Michael Terry (mterry) wrote :

(FYI, I've started work on just such a branch, that will overwrite quickly-owned files as needed.)

Unmerged revisions

669. By Tony Byrne <email address hidden> <email address hidden>

bin/project_name cleaned with pylint and pep8

668. By Tony Byrne <email address hidden> <email address hidden>

merge from trunk

667. By Tony Byrne <email address hidden> <email address hidden>

quickly package --extras does not set up paths and environment correctly and omits compiling schemas
This branch fixes paths and environment for working in /opt

Partially addresses bug 998910 quickly package --extras creates broken deb
and fixes related bug 976817 Compiling schemas not part of the application template

TODO: glib-compile-schemas needs to be called as part of quickly package --extras
but I don't know how to do that.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/templates/ubuntu-application/project_root/bin/project_name'
2--- data/templates/ubuntu-application/project_root/bin/project_name 2011-02-24 02:14:23 +0000
3+++ data/templates/ubuntu-application/project_root/bin/project_name 2012-05-19 19:01:19 +0000
4@@ -4,30 +4,54 @@
5 # This file is in the public domain
6 ### END LICENSE
7
8+'''points to python code, glib schemas etc. so that project can run
9+
10+ in /usr and non-standard locations (/opt and source tree)'''
11+
12 import sys
13 import os
14+import subprocess
15
16 import gettext
17-from gettext import gettext as _
18+_ = gettext.gettext
19 gettext.textdomain('project_name')
20
21 # Add project root directory (enable symlink and trunk execution)
22 PROJECT_ROOT_DIRECTORY = os.path.abspath(
23 os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0]))))
24
25-python_path = []
26+
27+def setup_environment(datapath, python_path):
28+ '''adjust environment so project can run in non-standard locations'''
29+ if os.path.exists(os.path.join(datapath, 'glib-2.0/schemas')):
30+ os.putenv('XDG_DATA_DIRS',
31+ "%s:%s" % (datapath, os.getenv('XDG_DATA_DIRS', '')))
32+
33+ if python_path:
34+ # for subprocesses
35+ os.putenv('PYTHONPATH',
36+ "%s:%s" % (os.getenv('PYTHONPATH', ''), ':'.join(python_path)))
37+
38+PYTHONPATH = []
39+SCHEMAPATH = None
40 if os.path.abspath(__file__).startswith('/opt'):
41- syspath = sys.path[:] # copy to avoid infinite loop in pending objects
42- for path in syspath:
43+ SYSPATH = sys.path[:] # copy to avoid infinite loop in pending objects
44+ for path in SYSPATH:
45 opt_path = path.replace('/usr', '/opt/extras.ubuntu.com/project_name')
46- python_path.insert(0, opt_path)
47+ PYTHONPATH.insert(0, opt_path)
48 sys.path.insert(0, opt_path)
49+ DATADIR = os.path.join(PROJECT_ROOT_DIRECTORY, 'project_name', "share")
50+ setup_environment(DATADIR, PYTHONPATH)
51+
52 if (os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, 'python_name'))
53 and PROJECT_ROOT_DIRECTORY not in sys.path):
54- python_path.insert(0, PROJECT_ROOT_DIRECTORY)
55+ PYTHONPATH.insert(0, PROJECT_ROOT_DIRECTORY)
56 sys.path.insert(0, PROJECT_ROOT_DIRECTORY)
57-if python_path:
58- os.putenv('PYTHONPATH', "%s:%s" % (os.getenv('PYTHONPATH', ''), ':'.join(python_path))) # for subprocesses
59+ DATADIR = os.path.join(PROJECT_ROOT_DIRECTORY, "data")
60+ setup_environment(DATADIR, PYTHONPATH)
61+
62+ SCHEMAPATH = os.path.join(DATADIR, 'glib-2.0/schemas')
63+ subprocess.call(["glib-compile-schemas", SCHEMAPATH])
64
65 import python_name
66 python_name.main()
67
68=== modified file 'data/templates/ubuntu-application/project_root/setup.py'
69--- data/templates/ubuntu-application/project_root/setup.py 2011-03-31 15:19:55 +0000
70+++ data/templates/ubuntu-application/project_root/setup.py 2012-05-19 19:01:19 +0000
71@@ -58,13 +58,29 @@
72 print ("ERROR: Can't find project_name.desktop.in")
73 sys.exit(1)
74
75+def path_from_debian_rules(default):
76+ try:
77+ fin = open('debian/rules', 'r')
78+ lines = fin.readlines()
79+ fin.close()
80+ except:
81+ return default
82+
83+ lines = [x for x in lines if 'dh_auto_install' in x and '--install-data' in x]
84+ if len(lines) != 1:
85+ return default
86+ results = [x for x in lines[0].split('--install') if x.startswith('-data')]
87+ results = [x.strip() for x in results[0].split('=')]
88+
89+ return results[1]
90
91 class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto):
92 def run(self):
93- values = {'__python_name_data_directory__': "'%s'" % (self.prefix + '/share/project_name/'),
94+ prefix = path_from_debian_rules(default=self.prefix)
95+ values = {'__python_name_data_directory__': "'%s'" % (prefix + '/share/project_name/'),
96 '__version__': "'%s'" % self.distribution.get_version()}
97 previous_values = update_config(values)
98- update_desktop_file(self.prefix + '/share/project_name/')
99+ update_desktop_file(prefix + '/share/project_name/')
100 DistUtilsExtra.auto.install_auto.run(self)
101 update_config(previous_values)
102
103
104=== modified file 'data/templates/ubuntu-application/run.py'
105--- data/templates/ubuntu-application/run.py 2012-02-20 09:00:14 +0000
106+++ data/templates/ubuntu-application/run.py 2012-05-19 19:01:19 +0000
107@@ -50,18 +50,6 @@
108 print _("Can't access to X server, so can't run gtk application")
109 sys.exit(1)
110
111-env = os.environ.copy()
112-# Compile schema if present
113-schemapath = os.path.abspath("data/glib-2.0/schemas")
114-if os.path.exists(schemapath):
115- subprocess.call(["glib-compile-schemas", schemapath])
116-
117- datadir = os.path.abspath("data")
118- if 'XDG_DATA_DIRS' in env:
119- env['XDG_DATA_DIRS'] = "%s:%s" % (datadir, env['XDG_DATA_DIRS'])
120- else:
121- env['XDG_DATA_DIRS'] = datadir
122-
123 project_bin = 'bin/' + configurationhandler.project_config['project']
124 command_line = [project_bin]
125 command_line.extend([arg for arg in sys.argv[1:] if arg != "--"])
126@@ -70,7 +58,7 @@
127 st = os.stat(project_bin)
128 mode = st[stat.ST_MODE]
129 if mode & stat.S_IEXEC:
130- subprocess.call(command_line, env=env)
131+ subprocess.call(command_line)
132 else:
133 print _("Can't execute %s") % project_bin
134 sys.exit(1)

Subscribers

People subscribed via source and target branches