Sfoglia il codice sorgente

Make app registry location configurable

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.
Abraham Elmahrek 12 anni fa
parent
commit
db2e9f2f30
4 ha cambiato i file con 40 aggiunte e 11 eliminazioni
  1. 1 0
      data
  2. 16 0
      tools/app_reg/common.py
  3. 22 10
      tools/app_reg/pth.py
  4. 1 1
      tools/app_reg/registry.py

+ 1 - 0
data

@@ -0,0 +1 @@
+/var/lib/hue

+ 16 - 0
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 @@ ENV_PYTHON = os.path.join(VIRTUAL_ENV, 'bin', 'python')
 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')

+ 22 - 10
tools/app_reg/pth.py

@@ -26,28 +26,35 @@ import os
 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 @@ class PthFile(object):
         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"""

+ 1 - 1
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()