[sysadmin-bin] implement but not enable doap cache



commit ab78090d6a7e269acfce31ed3ca3c3e29147af5f
Author: Olav Vitters <olav vitters nl>
Date:   Tue Jan 20 21:57:21 2015 +0100

    implement but not enable doap cache

 ftpadmin |   37 ++++++++++++++++++++++++-------------
 1 files changed, 24 insertions(+), 13 deletions(-)
---
diff --git a/ftpadmin b/ftpadmin
index a9800f4..ee41307 100755
--- a/ftpadmin
+++ b/ftpadmin
@@ -304,16 +304,16 @@ class DOAP(BasicInfo):
     # http://www.artima.com/forums/flat.jsp?forum=122&thread=15024
 
     def __init__(self):
-        self._did_doap = False
-        self.doap()
+        self.jsonfile = self.DOAP_CACHE
+        self._init_doap()
 
-    def doap(self):
+    def _init_doap(self):
 
         # Get module maintainer data from DOAP file in Git
         # Note: some data is still in MAINTAINERS files. These are converted
         #       to DOAP information by scripts in gitadmin-bin module.
 
-       changed = False
+        changed = False
         etag = None
         last_modified = None
 
@@ -321,7 +321,7 @@ class DOAP(BasicInfo):
         #valid_uids = set(grp.getgrnam('olav').gr_mem)
         # XXX
         # XXX - unfinished
-        if not os.path.exists(self.DOAP_CACHE):
+        if not os.path.exists(self.jsonfile):
             force_refresh = True
 
         if not force_refresh:
@@ -358,6 +358,8 @@ class DOAP(BasicInfo):
         else:
             etag, last_modified, UID_TO_MODULES, TARBALL_TO_MODULE, info = self._parse_url_handle(url_handle)
 
+        self.etag = etag
+        self.last_modified = last_modified
         self.info = info
         self.tarball_to_module = TARBALL_TO_MODULE
         self.uid_to_module = UID_TO_MODULES
@@ -433,6 +435,15 @@ class DOAP(BasicInfo):
 
         return (etag, last_modified, UID_TO_MODULES, TARBALL_TO_MODULE, MODULE_INFO)
 
+    def write_json(self):
+        # Want to overwrite any existing file and change the owner
+        if os.path.exists(self.jsonfile):
+            os.remove(self.jsonfile)
+        with open(self.jsonfile, 'w') as f:
+            json.dump((self.JSONVERSION, self.etag, self.last_modified, self.info, self.tarball_to_module, 
self.uid_to_module), f)
+            if self.GROUPID is not None:
+                os.fchown(f.fileno(), -1, self.GROUPID)
+
 
 class TarInfo(BasicInfo):
 
@@ -865,18 +876,18 @@ class ModuleInfo(DirectoryInfo):
     def _set_doap(self):
         # Determine maintainers and module name
         doap = DOAP()
-       self.__class__._doap = doap
+        self.__class__._doap = doap
 
         self._maintainers = []
         self._reponame = self.module
-       
-       modules = doap.tarball_to_module.get(self.module, [])
-       if not modules: modules.append(self.module)
+        
+        modules = doap.tarball_to_module.get(self.module, [])
+        if not modules: modules.append(self.module)
 
-       if len(modules) == 1:
+        if len(modules) == 1:
             self._reponame = self.module
-       else:
-           self._reponame = list(modules)[0]
+        else:
+            self._reponame = list(modules)[0]
 
         # XXX - restrict to gnomecvs users
         self._maintainers = doap.info.get(self._reponame, {}).get('maintainers', [])
@@ -890,7 +901,7 @@ class ModuleInfo(DirectoryInfo):
 
     @property
     def reponame(self):
-       if not hasattr(self.__class__, '_doap'):
+        if not hasattr(self.__class__, '_doap'):
             self._set_doap()
 
         return self._reponame


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