Merge lp:~rafalcieslak256/ubuntu-accomplishments-daemon/982246 into lp:ubuntu-accomplishments-daemon

Proposed by Rafał Cieślak
Status: Merged
Merged at revision: 13
Proposed branch: lp:~rafalcieslak256/ubuntu-accomplishments-daemon/982246
Merge into: lp:ubuntu-accomplishments-daemon
Diff against target: 164 lines (+77/-26)
5 files modified
accomplishments/daemon/api.py (+8/-3)
accomplishments/util/__init__.py (+3/-0)
accomplishments/util/paths.py (+44/-15)
bin/accomplishments-daemon (+11/-4)
bin/accomplishments-daemon-fg (+11/-4)
To merge this branch: bzr merge lp:~rafalcieslak256/ubuntu-accomplishments-daemon/982246
Reviewer Review Type Date Requested Status
Jono Bacon Pending
Review via email: mp+102030@code.launchpad.net

Description of the change

This branch is meant to fix #982246 in daemon, by introducing proper PATH setting.

It allows to install the daemon with a given prefix. (python setup.py install --prefix /where/to/install
Although this is possible at the moment, the daemon will start only if the prefix is /usr, or it is being run without installation, in any other case it will crash on startup. This branch fixes this issue.

This feature is quite cool, I am delighted to be able to successfully install the application to /opt/accomplishments (or any other directory), it makes it much easier to browse it's installed files, makes me sure I won't accidentally hurt any significant system file, and simplifies uninstallation (just remove whole directory)

=========
First part of the fix is in the bin/accomplishments-daemon file. It failed to import anything from accomplishments.* modules, because python was looking for them in /usr/lib/python2.7/... while our modules were installed to the prefixed directory (e.g. /opt/accomplishments/lib/python2.7/...). This is fixed by determining the prefix (stored in basepath variable), and adding required directories to the PATH. The basepath itself is added to the PATH too, which is exactly the same as adding ./ when the daemon is run from branch.

The same code is added to bin/accomplishments-daemon-fg file.

Next piece of fix is a complete rewrite of accomplishments/utils/paths.py. The problem was that it has supported only two cases (run from branch and installed to /usr), as it had hadr-coded paths. Proposed code determines the prefix (to basepath) and sets the required variables as needed.

Lastly, the new PATH variable is not passed to subprocesses - I've solved that by setting module_dir variables in paths.py, storing the path to accomplishment.* modules. This way they can be used to prepare os.environ in the api.py file.

To post a comment you must log in.
16. By Rafał Cieślak

unneeded import

17. By Rafał Cieślak

this unsafe function is not used anymore

Revision history for this message
Rafał Cieślak (rafalcieslak256) wrote :

Notes concerning integration with viewer when installing both are available in related viewer's branch's merge request: https://code.launchpad.net/~rafalcieslak256/ubuntu-accomplishments-viewer/982246/+merge/102031

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'accomplishments/daemon/api.py'
--- accomplishments/daemon/api.py 2012-04-14 17:07:55 +0000
+++ accomplishments/daemon/api.py 2012-04-15 16:19:19 +0000
@@ -38,13 +38,18 @@
38from ubuntuone.platform.tools import SyncDaemonTool38from ubuntuone.platform.tools import SyncDaemonTool
39from ubuntuone.couch import auth39from ubuntuone.couch import auth
4040
41os.environ["PYTHONPATH"] = "$PYTHONPATH:."
42
43import accomplishments41import accomplishments
44from accomplishments import exceptions42from accomplishments import exceptions
45from accomplishments.daemon import dbusapi43from accomplishments.daemon import dbusapi
46from accomplishments.util import get_data_file, SubprocessReturnCodeProtocol44from accomplishments.util import get_data_file, SubprocessReturnCodeProtocol
47from accomplishments.util.paths import media_dir45from accomplishments.util.paths import media_dir, module_dir1, module_dir2, installed
46
47os.environ["PYTHONPATH"] = "$PYTHONPATH:."
48# The directories with accomplishment.* modules, that are being used by scripts,
49# may happen to be in a completelly different directory, if the daemon was
50# installed using a non-default prefix.
51if installed:
52 os.environ["PYTHONPATH"] = module_dir1 + ":" + module_dir2 + ":" + os.environ["PYTHONPATH"]
4853
49MATRIX_USERNAME = "openiduser155707"54MATRIX_USERNAME = "openiduser155707"
50LOCAL_USERNAME = getpass.getuser()55LOCAL_USERNAME = getpass.getuser()
5156
=== modified file 'accomplishments/util/__init__.py'
--- accomplishments/util/__init__.py 2012-04-12 03:02:29 +0000
+++ accomplishments/util/__init__.py 2012-04-15 16:19:19 +0000
@@ -52,6 +52,9 @@
5252
5353
54def get_data_path():54def get_data_path():
55 # XXX: NOTE: This function will most likely work incorrectly when daemon is installed in non-default path.
56 # Luckily, this function is no longer used anywhere.
57 # If you feel you need to get this path, please refer to utils/paths.py instead.
55 """Retrieve accomplishments-daemon data path58 """Retrieve accomplishments-daemon data path
5659
57 This path is by default <accomplishments_daemon_lib_path>/../data/ in trunk60 This path is by default <accomplishments_daemon_lib_path>/../data/ in trunk
5861
=== modified file 'accomplishments/util/paths.py'
--- accomplishments/util/paths.py 2012-04-12 03:02:29 +0000
+++ accomplishments/util/paths.py 2012-04-15 16:19:19 +0000
@@ -1,16 +1,45 @@
1import os1import os
2from accomplishments.util import get_data_path2
33if __file__[0] is '/':
4def uses_system_lib():4 #the script run with absolute path
5 return os.path.dirname(__file__).startswith("/usr")5 scriptpath = __file__
66else:
7runs_in_branch = not uses_system_lib()7 scriptpath = os.path.join(os.getcwd(),__file__)
8#systemdata_dir = "data/daemon/"8
9#media_dir = "data/media/"9# okay, so as we have the full path, we're ready to analise it...
10if not runs_in_branch:10
11 systemdata_dir = "/usr/share/accomplishments-daemon/"11# start by looking 2 levels higher. This is either the branch directory,
12 media_dir = "/usr/share/accomplishments-daemon/media/"12# or the python2.7/...-packages directory, if the application is run installed.
13else:13branchpath = os.path.split(os.path.split(os.path.split(scriptpath)[0])[0])[0]
14 localdatapath = get_data_path()14branchdir_name = os.path.split(branchpath)[1]
15 systemdata_dir = os.path.join(localdatapath, "daemon")15if ((branchdir_name == "site-packages") or (branchdir_name == 'dist-packages')):
16 media_dir = os.path.join(localdatapath, "media")16 installed = True
17else:
18 installed = False
19
20# Great, at that level we know whether the application is run from branch, or
21# has been installed. This allows us to interpret the directories further...
22
23
24if installed:
25 basepath = os.path.split(os.path.split(os.path.split(branchpath)[0])[0])[0]
26 # basepath should equal to prefix given on installation.
27 print "Daemon seems to be installed to: " + basepath
28
29 # finally, setting these significant data directories...
30 systemdata_dir = os.path.join(basepath, 'share/accomplishments-daemon')
31 media_dir = os.path.join(basepath, 'share/accomplishments-daemon/media')
32 # these two may need to be set for the accomplismhents scripts, so that they
33 # can use OUR accomplishments module, using this installation.
34 module_dir1 = os.path.join(basepath, 'lib/python2.7/site-packages')
35 module_dir2 = os.path.join(basepath, 'lib/python2.7/dist-packages')
36else:
37 # using branch root directory as the base path
38 basepath = branchpath
39 print "Daemon seems to be run not installed, branch base path used: " + basepath
40
41 # finally, setting these significant data directories...
42 systemdata_dir = os.path.join(basepath, 'data/daemon')
43 media_dir = os.path.join(basepath, 'data/media')
44 module_dir1 = None # always using default
45 module_dir2 = None # always using default
1746
=== modified file 'bin/accomplishments-daemon'
--- bin/accomplishments-daemon 2012-04-12 00:20:10 +0000
+++ bin/accomplishments-daemon 2012-04-15 16:19:19 +0000
@@ -11,14 +11,21 @@
11import dbus11import dbus
12from dbus.mainloop.glib import DBusGMainLoop12from dbus.mainloop.glib import DBusGMainLoop
1313
14# Importing from accomplishments.paths would fail, if the path is set wrongly.
15# We need to ensure that the script will load the correct version of
16# accomplishment.* that is installed with this script.
17scriptpath = os.path.abspath(__file__)
18# basepaths shall be equal to prefix used while installing - if the application is run from source, it does not really matter.
19basepath = os.path.split(os.path.split(scriptpath)[0])[0]
20sys.path.insert(0, basepath)
21sys.path.insert(0, basepath + "/lib/python2.7")
22sys.path.insert(0, basepath + "/lib/python2.7/site-packages")
23sys.path.insert(0, basepath + "/lib/python2.7/dist-packages")
24
14from accomplishments.daemon import app25from accomplishments.daemon import app
1526
16from accomplishments.util import paths27from accomplishments.util import paths
1728
18if paths.runs_in_branch:
19 # PYTHONPATH mangling
20 sys.path.insert(0, ".")
21
22dbus_loop = DBusGMainLoop(set_as_default=True)29dbus_loop = DBusGMainLoop(set_as_default=True)
23application = app.applicationFactory(30application = app.applicationFactory(
24 app_name="Ubuntu Accomplishments",31 app_name="Ubuntu Accomplishments",
2532
=== modified file 'bin/accomplishments-daemon-fg'
--- bin/accomplishments-daemon-fg 2012-04-12 00:20:10 +0000
+++ bin/accomplishments-daemon-fg 2012-04-15 16:19:19 +0000
@@ -11,14 +11,21 @@
11import dbus11import dbus
12from dbus.mainloop.glib import DBusGMainLoop12from dbus.mainloop.glib import DBusGMainLoop
1313
14# Importing from accomplishments.paths would fail, if the path is set wrongly.
15# We need to ensure that the script will load the correct version of
16# accomplishment.* that is installed with this script.
17scriptpath = os.path.abspath(__file__)
18# basepaths shall be equal to prefix used while installing - if the application is run from source, it does not really matter.
19basepath = os.path.split(os.path.split(scriptpath)[0])[0]
20sys.path.insert(0, basepath)
21sys.path.insert(0, basepath + "/lib/python2.7")
22sys.path.insert(0, basepath + "/lib/python2.7/site-packages")
23sys.path.insert(0, basepath + "/lib/python2.7/dist-packages")
24
14from accomplishments.daemon import app25from accomplishments.daemon import app
1526
16from accomplishments.util import paths27from accomplishments.util import paths
1728
18if paths.runs_in_branch:
19 # PYTHONPATH mangling
20 sys.path.insert(0, ".")
21
22dbus_loop = DBusGMainLoop(set_as_default=True)29dbus_loop = DBusGMainLoop(set_as_default=True)
23application = app.applicationFactory(30application = app.applicationFactory(
24 app_name="Ubuntu Accomplishments",31 app_name="Ubuntu Accomplishments",

Subscribers

People subscribed via source and target branches