Skip to content

Commit

Permalink
Make app registry location configurable
Browse files Browse the repository at this point in the history
Using environment variables:
- HUE_APP_REG_DIR
- HUE_PTH_DIR

A link from build/env/lib/python*/site-packages/hue.link.pth will
point to <HUE_PTH_DIR>/hue.pth.

If the app registry is in a non-default location, all Hue
commands will need to be executed with HUE_APP_REG_DIR set.

relinking will be a manual process for now.
  • Loading branch information
generalpiston authored and romainr committed May 9, 2013
1 parent 663680a commit db2e9f2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions data
16 changes: 16 additions & 0 deletions tools/app_reg/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
32 changes: 22 additions & 10 deletions tools/app_reg/pth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion tools/app_reg/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit db2e9f2

Please sign in to comment.