diff --git a/data b/data new file mode 120000 index 00000000000..e8bbe426292 --- /dev/null +++ b/data @@ -0,0 +1 @@ +/var/lib/hue \ No newline at end of file diff --git a/tools/app_reg/common.py b/tools/app_reg/common.py index 42381cff854..ee176fe6fb2 100644 --- a/tools/app_reg/common.py +++ b/tools/app_reg/common.py @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import glob +import logging import os.path # The root of the Hue installation @@ -32,3 +34,17 @@ def cmp_version(ver1, ver2): """Compare two version strings in the form of 1.2.34""" return cmp(ver1.split('.'), ver2.split('.')) + +def _get_python_lib_dir(): + glob_path = os.path.join(VIRTUAL_ENV, 'lib', 'python*') + res = glob.glob(glob_path) + if len(res) == 0: + raise SystemError("Cannot find a Python installation in %s. " + "Did you do `make hue'?" % glob_path) + elif len(res) > 1: + raise SystemError("Found multiple Python installations in %s. " + "Please `make clean' first." % glob_path) + return res[0] + +def _get_python_site_packages_dir(): + return os.path.join(_get_python_lib_dir(), 'site-packages') diff --git a/tools/app_reg/pth.py b/tools/app_reg/pth.py index 8a6644ffe89..f1071c7a785 100644 --- a/tools/app_reg/pth.py +++ b/tools/app_reg/pth.py @@ -26,28 +26,35 @@ import common LOG = logging.getLogger(__name__) +PTH_SYMLINK = 'hue.link.pth' PTH_FILE = 'hue.pth' +def _get_pth_symlink(): + """ + _get_pth_symlink -> Path to the .pth symlink. + May raise SystemError if the virtual env is absent. + """ + return os.path.join(common._get_python_site_packages_dir(), PTH_SYMLINK) + + def _get_pth_filename(): """ _get_pth_filename -> Path to the .pth file. + Location can be defined via HUE_PTH_DIR environment variable. May raise SystemError if the virtual env is absent. """ - glob_path = os.path.join(common.VIRTUAL_ENV, 'lib', 'python*', 'site-packages') - res = glob.glob(glob_path) - if len(res) == 0: - raise SystemError("Cannot find a Python installation in %s. " - "Did you do `make hue'?" % (glob_path,)) - elif len(res) > 1: - raise SystemError("Found multiple Python installations in %s. " - "Please `make clean' first." % (glob_path,)) - return os.path.join(res[0], PTH_FILE) + pth_dir = os.environ.get('HUE_PTH_DIR', None) + if pth_dir: + return os.path.join(pth_dir, PTH_FILE) + else: + return os.path.join(common._get_python_site_packages_dir(), PTH_FILE) class PthFile(object): def __init__(self): """May raise SystemError if the virtual env is absent""" + self._symlink_path = _get_pth_symlink() self._path = _get_pth_filename() self._entries = [ ] self._read() @@ -85,11 +92,16 @@ def remove(self, app): self._entries.remove(path) def save(self): - """Save the pth file""" + """ + Save the pth file + Create a symlink to the path if it does not already exist. + """ tmp_path = self._path + '.new' file(tmp_path, 'w').write('\n'.join(sorted(self._entries))) os.rename(tmp_path, self._path) LOG.info('=== Saved %s' % (self._path,)) + if not os.path.exists(self._symlink_path): + os.symlink(self._path, self._symlink_path) def sync(self, apps): """Sync the .pth file with the installed apps""" diff --git a/tools/app_reg/registry.py b/tools/app_reg/registry.py index 75050c8cdd9..f0092dc9291 100644 --- a/tools/app_reg/registry.py +++ b/tools/app_reg/registry.py @@ -37,7 +37,7 @@ class AppRegistry(object): """ def __init__(self): """Open the existing registry""" - self._reg_path = os.path.join(common.INSTALL_ROOT, 'app.reg') + self._reg_path = os.path.join(os.environ.get("HUE_APP_REG_DIR", common.INSTALL_ROOT), 'app.reg') self._initialized = False self._apps = { } # Map of name -> HueApp self._open()