Bläddra i källkod

[core] relative paths in app_reg

- Specify relative paths as an option
Abraham Elmahrek 12 år sedan
förälder
incheckning
66d08bf6f9

+ 1 - 1
apps/Makefile

@@ -54,7 +54,7 @@ EGG_INFO_TARGETS := $(APPS:%=.recursive-egg-info/%)
 
 .PHONY: env-install
 env-install: $(EGG_INFO_TARGETS)
-	$(APP_REG) --install $(APPS)
+	$(APP_REG) --install $(APPS) --relative-paths
 
 
 ################################################

+ 0 - 1
desktop/libs/liboozie/Makefile

@@ -34,4 +34,3 @@ default::
 env-install: compile ext-env-install
 	@echo '--- Installing $(APP_NAME) into virtual-env'
 	@$(ENV_PYTHON) setup.py develop -N -q
-

+ 13 - 5
tools/app_reg/app_reg.py

@@ -101,10 +101,11 @@ def get_app_info(app_loc):
     os.chdir(save_cwd)
 
 
-def _do_install_one(reg, app_loc):
+def _do_install_one(reg, app_loc, relative_path):
   """Install one app, without saving. Returns True/False."""
   LOG.info("=== Installing app at %s" % (app_loc,))
   try:
+    # Relative to cwd.
     app_loc = os.path.realpath(app_loc)
     app_name, version, desc, author = get_app_info(app_loc)
   except (ValueError, OSError), ex:
@@ -112,17 +113,21 @@ def _do_install_one(reg, app_loc):
     return False
 
   app = registry.HueApp(app_name, version, app_loc, desc, author)
+  if relative_path:
+    app.use_rel_path()
+  else:
+    app.use_abs_path()
   if reg.contains(app):
     LOG.warn("=== %s is already installed" % (app,))
     return True
   return reg.register(app) and build.make_app(app) and app.install_conf()
 
 
-def do_install(app_loc_list):
+def do_install(app_loc_list, relative_paths=False):
   """Install the apps. Returns True/False."""
   reg = registry.AppRegistry()
   for app_loc in app_loc_list:
-    if not _do_install_one(reg, app_loc):
+    if not _do_install_one(reg, app_loc, relative_paths):
       return False
   reg.save()
 
@@ -218,7 +223,10 @@ def main():
       LOG_LEVEL = logging.DEBUG
 
   if action == DO_INSTALL:
-    app_loc_list = tail
+    # ['..', '--relative-paths', 'a', 'b'] => True
+    # ['..', 'a', 'b'] -> False
+    relative_paths = reduce(lambda accum, x: accum or x, map(lambda x: x in ['--relative-paths'], tail))
+    app_loc_list = filter(lambda x: x not in ['--relative-paths'], tail)
   elif len(tail) != 0:
     usage("Unknown trailing arguments: %s" % ' '.join(tail))
 
@@ -230,7 +238,7 @@ def main():
 
   # Dispatch
   if action == DO_INSTALL:
-    ok = do_install(app_loc_list)
+    ok = do_install(app_loc_list, relative_paths)
   elif action == DO_REMOVE:
     ok = do_remove(app)
   elif action == DO_LIST:

+ 1 - 1
tools/app_reg/build.py

@@ -45,7 +45,7 @@ def make_app(app):
 
   Call `make egg-info ext-eggs' on the app.
   """
-  cmdv = [ 'make', '-C', app.path, 'egg-info', 'ext-eggs' ]
+  cmdv = [ 'make', '-C', app.rel_path, 'egg-info', 'ext-eggs' ]
   return runcmd(cmdv, dict(ROOT=common.INSTALL_ROOT)) == 0
 
 

+ 3 - 0
tools/app_reg/common.py

@@ -24,6 +24,9 @@ from posixpath import curdir, sep, pardir, join
 # The root of the Hue installation
 INSTALL_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..'))
 
+# The apps location
+APPS_ROOT = os.path.join(INSTALL_ROOT, 'apps')
+
 # The Hue config directory
 HUE_CONF_DIR = os.path.join(INSTALL_ROOT, 'desktop', 'conf')
 

+ 8 - 5
tools/app_reg/pth.py

@@ -66,22 +66,25 @@ class PthFile(object):
   def add(self, app):
     """
     Add the app and its ext eggs into the pth file
+
+    PTH files need paths relative to the pth file, not APPS_ROOT
     """
-    module_path = os.path.join(app.path, 'src')
-    LOG.debug('Add to %s: %s' % (self._path, module_path))
-    self._entries.add(module_path)
+    abs_module_path = os.path.join(app.abs_path, 'src')
+    rel_module_path = os.path.relpath(abs_module_path, self._path)
+    LOG.debug('Add to %s: %s' % (self._path, rel_module_path))
+    self._entries.add(rel_module_path)
 
     # Eggs could be in ext-py/<pkg>/dist/*.egg
     ext_pys = app.find_ext_pys()
     for py in ext_pys:
       ext_egg = glob.glob(os.path.join(py, 'dist', '*.egg'))
       LOG.debug('Add to %s: %s' % (self._path, ext_egg))
-      self._entries.update(ext_egg)
+      self._entries.update(os.path.relpath(ext_egg, self._path))
 
     # And eggs could also be in ext-eggs/*.egg
     for egg_file in glob.glob(os.path.join(app.path, 'ext-eggs', '*.egg')):
       LOG.debug('Add to %s: %s' % (self._path, egg_file))
-      self._entries.add(egg_file)
+      self._entries.add(os.path.relpath(egg_file, self._path))
 
   def remove(self, app):
     """

+ 25 - 11
tools/app_reg/registry.py

@@ -42,7 +42,6 @@ class AppRegistry(object):
     self._apps = { }    # Map of name -> HueApp
     self._open()
 
-
   def _open(self):
     """Open the registry file. May raise OSError"""
     if os.path.exists(self._reg_path):
@@ -57,14 +56,12 @@ class AppRegistry(object):
 
     self._initialized = True
 
-
   def _write(self, path):
     """Write out the registry to the given path"""
     outfile = file(path, 'w')
     json.dump(self._apps.values(), outfile, cls=AppJsonEncoder, indent=2)
     outfile.close()
 
-
   def contains(self, app):
     """Returns whether the app (of the same version) is in the registry"""
     try:
@@ -73,7 +70,6 @@ class AppRegistry(object):
     except KeyError:
       return False
 
-
   def register(self, app):
     """register(app) -> True/False"""
     assert self._initialized, "Registry not yet initialized"
@@ -95,7 +91,6 @@ class AppRegistry(object):
     self._apps[app.name] = app
     return True
 
-
   def unregister(self, app_name):
     """unregister(app_Name) -> HueApp. May raise KeyError"""
     assert self._initialized, "Registry not yet initialized"
@@ -104,12 +99,10 @@ class AppRegistry(object):
     del self._apps[app_name]
     return app
 
-
   def get_all_apps(self):
     """get_all_apps() -> List of HueApp"""
     return self._apps.values()
 
-
   def save(self):
     """Save and write out the registry"""
     assert self._initialized, "Registry not yet initialized"
@@ -123,6 +116,8 @@ class AppRegistry(object):
 class HueApp(object):
   """
   Represents an app.
+
+  Path provided should be absolute or relative to common.APPS_ROOT
   """
   @staticmethod
   def create(json):
@@ -143,18 +138,37 @@ class HueApp(object):
       raise TypeError
     return cmp((self.name, self.version), (other.name, other.version))
 
+  @property
+  def rel_path(self):
+    if os.path.isabs(self.path):
+      return os.path.relpath(self.path, common.APPS_ROOT)
+    else:
+      return self.path
+
+  @property
+  def abs_path(self):
+    if not os.path.isabs(self.path):
+      return os.path.abspath(os.path.join(common.APPS_ROOT, self.path))
+    else:
+      return self.path
+
+  def use_rel_path(self):
+    self.path = self.rel_path
+
+  def use_abs_path(self):
+    self.path = self.abs_path
+
   def jsonable(self):
     return dict(name=self.name, version=self.version, path=self.path,
                 desc=self.desc, author=self.author)
 
   def find_ext_pys(self):
     """find_ext_pys() -> A list of paths for all ext-py packages"""
-    return glob.glob(os.path.join(self.path, 'ext-py', '*'))
+    return glob.glob(os.path.join(self.abs_path, 'ext-py', '*'))
 
   def get_conffiles(self):
     """get_conffiles() -> A list of config (.ini) files"""
-    ini_files = glob.glob(os.path.join(self.path, 'conf', '*.ini'))
-    return [ os.path.abspath(ini) for ini in ini_files ]
+    return glob.glob(os.path.join(self.abs_path, 'conf', '*.ini'))
 
 
   def install_conf(self):
@@ -201,7 +215,7 @@ class HueApp(object):
 
   def uninstall_conf(self):
     """uninstall_conf() -> True/False"""
-    app_conf_dir = os.path.abspath(os.path.join(self.path, 'conf'))
+    app_conf_dir = os.path.abspath(os.path.join(self.abs_path, 'conf'))
     if not os.path.isdir(app_conf_dir):
       return True