[sysadmin-bin] py-install-module: prepare for making read_json work



commit 31fde78d009b64ddefc1bef364af56d15ff64734
Author: Olav Vitters <olav vitters nl>
Date:   Sat Mar 5 19:44:12 2011 +0100

    py-install-module: prepare for making read_json work

 py-install-module |   56 ++++++++++++++++++++++++++++++++--------------------
 1 files changed, 34 insertions(+), 22 deletions(-)
---
diff --git a/py-install-module b/py-install-module
index 1b27c7f..4874e1b 100755
--- a/py-install-module
+++ b/py-install-module
@@ -108,8 +108,6 @@ class ModuleInfo(object):
     def __init__(self, modulename):
         self.module = modulename
 
-        self.read_json()
-
         # Determine maintainers
         self.maintainers = []
         if self.module:
@@ -117,41 +115,55 @@ class ModuleInfo(object):
             if len(data):
                 self.maintainers = data[0][1]['maintainerUid']
 
+            self.jsonfile = os.path.join(self.FTPROOT, 'sources', self.module, '%s.json' % self.module)
+
+        self.read_json()
 
     def refresh(self):
         if self.module is None: return False
 
+        self.read_json(force_refresh=True)
+
+    def read_json(self, force_refresh=False):
+        if self.module is None: return False
+
         info = {}
         majmins = {}
 
-        top = os.path.join(self.FTPROOT, 'sources', self.module)
-        for root, dirs, files in os.walk(top, topdown=False):
-            for filename in files:
-                r = re_file.match(filename)
-                if r:
-                    fileinfo = r.groupdict()
-                    module = fileinfo['module']
-                    version = fileinfo['version']
-                    format = fileinfo['format']
-                    majmin = re_version.sub(r'\1', fileinfo['version'])
+        if force_refresh or not os.path.exists(self.jsonfile):
+            top = os.path.join(self.FTPROOT, 'sources', self.module)
+            for root, dirs, files in os.walk(top, topdown=False):
+                for filename in files:
+                    r = re_file.match(filename)
+                    if r:
+                        fileinfo = r.groupdict()
+                        module = fileinfo['module']
+                        version = fileinfo['version']
+                        format = fileinfo['format']
+
+                        if module != self.module:
+                            continue
+
+                        info.setdefault(version, {})[format] = filename
+        else:
+            # XXX - actually load the json file..
+            pass
+
+        # XXX - maybe remove versions where there are no .tar.*
 
-                    if module != self.module:
-                        continue
 
-                    info.setdefault(version, {})[format] = filename
-                    majmins.setdefault(majmin, set()).add(version)
+        # Group versions by major and minor number
+        for version in info:
+            majmin = re_version.sub(r'\1', fileinfo['version'])
+            if majmin not in majmins:
+                majmins[majmin] = set()
 
-        # XXX - maybe remove versions where there are no .tar.*
+            majmins[majmin].add(version)
 
         self.info = info
         self.majmin = majmins
         self.versions = sorted(info, version_cmp)
 
-    def read_json(self):
-        if self.module is None: return False
-
-        self.refresh()
-
 
     def write_json(self): # XXX - should write json
         if self.module is None: return False



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]