瀏覽代碼

HUE-13. app_reg should show app's author

For backward compatibility, the author is "Unknown" for apps that are already
registered.
bc Wong 15 年之前
父節點
當前提交
ed955094de
共有 2 個文件被更改,包括 15 次插入10 次删除
  1. 9 7
      tools/app_reg/app_reg.py
  2. 6 3
      tools/app_reg/registry.py

+ 9 - 7
tools/app_reg/app_reg.py

@@ -84,7 +84,9 @@ def get_app_info(app_loc):
   save_cwd = os.getcwd()
   save_cwd = os.getcwd()
   os.chdir(app_loc)
   os.chdir(app_loc)
   try:
   try:
-    cmdv = [ common.ENV_PYTHON, 'setup.py', '--name', '--version', '--description' ]
+    cmdv = [ common.ENV_PYTHON, 'setup.py',
+             '--name', '--version', '--description',
+             '--author' ]
     LOG.debug("Running '%s'" % (' '.join(cmdv),))
     LOG.debug("Running '%s'" % (' '.join(cmdv),))
     popen = subprocess.Popen(cmdv, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     popen = subprocess.Popen(cmdv, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     res = popen.wait()
     res = popen.wait()
@@ -94,7 +96,7 @@ def get_app_info(app_loc):
       LOG.error("Error getting application info from %s:\n%s" % (app_loc, stderr))
       LOG.error("Error getting application info from %s:\n%s" % (app_loc, stderr))
       raise OSError(stderr)
       raise OSError(stderr)
     LOG.debug("Command output:\n<<<\n%s\n>>>" % (stdout,))
     LOG.debug("Command output:\n<<<\n%s\n>>>" % (stdout,))
-    return stdout.split('\n')[:3]
+    return stdout.split('\n')[:4]
   finally:
   finally:
     os.chdir(save_cwd)
     os.chdir(save_cwd)
 
 
@@ -104,12 +106,12 @@ def _do_install_one(reg, app_loc):
   LOG.info("=== Installing app at %s" % (app_loc,))
   LOG.info("=== Installing app at %s" % (app_loc,))
   try:
   try:
     app_loc = os.path.realpath(app_loc)
     app_loc = os.path.realpath(app_loc)
-    app_name, version, desc = get_app_info(app_loc)
+    app_name, version, desc, author = get_app_info(app_loc)
   except (ValueError, OSError), ex:
   except (ValueError, OSError), ex:
     LOG.error(ex)
     LOG.error(ex)
     return False
     return False
 
 
-  app = registry.DesktopApp(app_name, version, app_loc, desc)
+  app = registry.DesktopApp(app_name, version, app_loc, desc, author)
   if reg.contains(app):
   if reg.contains(app):
     LOG.warn("=== %s is already installed" % (app,))
     LOG.warn("=== %s is already installed" % (app,))
     return True
     return True
@@ -131,10 +133,10 @@ def do_list():
   """List all apps. Returns True/False."""
   """List all apps. Returns True/False."""
   reg = registry.AppRegistry()
   reg = registry.AppRegistry()
   apps = reg.get_all_apps()
   apps = reg.get_all_apps()
-  LOG.info("%-20s %-7s %s" % ('Name', 'Version', 'Path'))
-  LOG.info("%s %s %s" % ('-' * 20, '-' * 7, '-' * 50))
+  LOG.info("%-18s %-7s %-15s %s" % ('Name', 'Version', 'Author', 'Path'))
+  LOG.info("%s %s %s %s" % ('-' * 18, '-' * 7, '-' * 15, '-' * 35))
   for app in sorted(apps):
   for app in sorted(apps):
-    LOG.info("%-20s %-7s %s" % (app.name, app.version, app.path))
+    LOG.info("%-18s %-7s %-15s %s" % (app.name, app.version, app.author, app.path))
   return True
   return True
 
 
 
 

+ 6 - 3
tools/app_reg/registry.py

@@ -48,6 +48,7 @@ class AppRegistry(object):
       reg_file.close()
       reg_file.close()
 
 
       for app_json in app_list:
       for app_json in app_list:
+        app_json.setdefault('author', 'Unknown')        # Added after 0.9
         app = DesktopApp.create(app_json)
         app = DesktopApp.create(app_json)
         self._apps[app.name] = app
         self._apps[app.name] = app
 
 
@@ -122,13 +123,14 @@ class DesktopApp(object):
   """
   """
   @staticmethod
   @staticmethod
   def create(json):
   def create(json):
-    return DesktopApp(json['name'], json['version'], json['path'], json['desc'])
+    return DesktopApp(json['name'], json['version'], json['path'], json['desc'], json['author'])
 
 
-  def __init__(self, name, version, path, desc):
+  def __init__(self, name, version, path, desc, author):
     self.name = name
     self.name = name
     self.version = version
     self.version = version
     self.path = path
     self.path = path
     self.desc = desc
     self.desc = desc
+    self.author = author
 
 
   def __str__(self):
   def __str__(self):
     return "%s (version %s)" % (self.name, self.version)
     return "%s (version %s)" % (self.name, self.version)
@@ -139,7 +141,8 @@ class DesktopApp(object):
     return cmp((self.name, self.version), (other.name, other.version))
     return cmp((self.name, self.version), (other.name, other.version))
 
 
   def jsonable(self):
   def jsonable(self):
-    return dict(name=self.name, version=self.version, path=self.path, desc=self.desc)
+    return dict(name=self.name, version=self.version, path=self.path,
+                desc=self.desc, author=self.author)
 
 
   def find_ext_pys(self):
   def find_ext_pys(self):
     """find_ext_pys() -> A list of paths for all ext-py packages"""
     """find_ext_pys() -> A list of paths for all ext-py packages"""