fix broken config, and no more static method for Config (which now is a singleton)
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 24 Oct 2013 11:00:38 +0000 (13:00 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 24 Oct 2013 11:00:38 +0000 (13:00 +0200)
manifold/manifoldapi.py
myslice/config.py
portal/homeview.py
portal/sliceview.py
unfold/page.py

index c00882a..e7c6ce9 100644 (file)
@@ -20,13 +20,13 @@ class ManifoldAPI:
 
     def __init__(self, auth=None, cainfo=None):
         
-        config = Config()
         self.auth = auth
         self.cainfo = cainfo
         self.errors = []
         self.trace = []
         self.calls = {}
         self.multicall = False
+        config = Config()
         self.url = config.manifold_url()
         self.server = xmlrpclib.Server(self.url, verbose=False, allow_none=True)
 
index 31dc7e3..61c2281 100644 (file)
@@ -2,15 +2,19 @@ import os.path
 from ConfigParser import RawConfigParser
 from myslice.settings import ROOT
 
-# myslice/myslice.ini
-# as this code suggests, you have the option to write myslice/myslice.ini
+# as this code suggests, you have the option to override these defaults
+# by writing a file myslice/myslice.ini
 # that looks like this
 #[manifold]
 #url = http://manifold.pl.sophia.inria.fr:7080/
 #admin_user = admin
 #admin_password = admin
 
-class Config:
+# use a singleton instead of staticmethods
+from manifold.util.singleton    import Singleton
+
+class Config(object):
+    __metaclass__ = Singleton
 
     # the OpenLab-wide backend as managed by UPMC
     # xxx production should probably use https of course
@@ -20,40 +24,25 @@ class Config:
     # the INRIA setup is with "http://manifold.pl.sophia.inria.fr:7080/"
 
     default_manifold_admin_user     = 'admin'
-    default_manifold_admin_password = None
-
-    _config_parser = None
-
-    # having grown tired of screwing up with git stashes 
-    # taking away my local config, we now more properly use
-    # an external config file to override teh default
-    # XXX we might use support from manifold util classes --jordan
-    @staticmethod
-    def manifold_url ():
-        if Config._config_parser: 
-            return Config._config_parser.get('manifold','url')
-        config = RawConfigParser ()
-        config.add_section('manifold')
-        config.set ('manifold', 'url', Config.default_manifold_url)
-        config.read (os.path.join(ROOT,'myslice/myslice.ini'))
-        Config._config_parser=config
-        return Config.manifold_url()
-
-    @staticmethod
-    def manifold_admin_user_password():
-        if Config._config_parser: 
-            admin_user = Config._config_parser.get('manifold','admin_user')
-            admin_password = Config._config_parser.get('manifold','admin_password')
-            return (admin_user, admin_password)
-        config = RawConfigParser ()
-        config.add_section('manifold')
-        config.set ('manifold', 'admin_user', Config.default_manifold_admin_user)
-        config.set ('manifold', 'admin_password', Config.default_manifold_admin_password)
-        config.read (os.path.join(ROOT,'myslice/myslice.ini'))
-        Config._config_parser=config
-        return Config.manifold_admin_user_password()
+    default_manifold_admin_password = 'admin'
+
+
+    def __init__ (self):
+        parser = RawConfigParser ()
+        parser.add_section('manifold')
+        parser.set ('manifold', 'url', Config.default_manifold_url)
+        parser.set ('manifold', 'admin_user', Config.default_manifold_admin_user)
+        parser.set ('manifold', 'admin_password', Config.default_manifold_admin_password)
+        parser.read (os.path.join(ROOT,'myslice/myslice.ini'))
+        self.config_parser=parser
+
+    def manifold_url (self):
+        return self.config_parser.get('manifold','url')
+
+    def manifold_admin_user_password(self):
+        return (self.config_parser.get('manifold','admin_user'),
+                self.config_parser.get('manifold','admin_password'))
 
     # exporting these details to js
-    @staticmethod
-    def manifold_js_export ():
-        return "var MANIFOLD_URL = '%s';\n"%Config.manifold_url();
+    def manifold_js_export (self):
+        return "var MANIFOLD_URL = '%s';\n"%self.manifold_url();
index 0be0105..960c8f0 100644 (file)
@@ -14,8 +14,9 @@ class HomeView (View):
 
     # expose this so we can mention the backend URL on the welcome page
     def default_env (self):
+        config=Config()
         return { 
-                 'MANIFOLD_URL':Config.manifold_url(),
+                 'MANIFOLD_URL':config.manifold_url(),
                  }
 
     def post (self,request):
index 9d335f4..efceec4 100644 (file)
@@ -37,7 +37,8 @@ class SliceView (LoginRequiredAutoLogoutView):
         page.add_js_files  ( [ "js/common.functions.js" ] )
         page.add_js_chunks ('$(function() { messages.debug("sliceview: jQuery version " + $.fn.jquery); });')
         page.add_js_chunks ('$(function() { messages.debug("sliceview: users turned %s"); });'%("on" if do_query_users else "off"))
-        page.add_js_chunks ('$(function() { messages.debug("manifold URL %s"); });'%(Config.manifold_url()))
+        config=Config()
+        page.add_js_chunks ('$(function() { messages.debug("manifold URL %s"); });'%(config.manifold_url()))
         page.expose_js_metadata()
     
         metadata = page.get_metadata()
index 07879e7..3627e16 100644 (file)
@@ -140,7 +140,8 @@ class Page:
         self.add_js_chunks("var MANIFOLD_METADATA =" + self.get_metadata().to_json() + ";")
 
     def expose_js_manifold_config (self):
-        self.add_js_chunks(Config.manifold_js_export())
+        config=Config()
+        self.add_js_chunks(config.manifold_js_export())
 
     #################### requirements/prelude management
     # just forward to self.prelude - see decorator above