fix broken config, and no more static method for Config (which now is a singleton)
[myslice.git] / myslice / config.py
1 import os.path
2 from ConfigParser import RawConfigParser
3 from myslice.settings import ROOT
4
5 # as this code suggests, you have the option to override these defaults
6 # by writing a file myslice/myslice.ini
7 # that looks like this
8 #[manifold]
9 #url = http://manifold.pl.sophia.inria.fr:7080/
10 #admin_user = admin
11 #admin_password = admin
12
13 # use a singleton instead of staticmethods
14 from manifold.util.singleton    import Singleton
15
16 class Config(object):
17     __metaclass__ = Singleton
18
19     # the OpenLab-wide backend as managed by UPMC
20     # xxx production should probably use https of course
21     default_manifold_url = "http://test.myslice.info:7080/"
22     # the devel/unstable version runs on "http://dev.myslice.info:7080/"
23     # if you use a development backend running on this box, use "http://localhost:7080/"
24     # the INRIA setup is with "http://manifold.pl.sophia.inria.fr:7080/"
25
26     default_manifold_admin_user     = 'admin'
27     default_manifold_admin_password = 'admin'
28
29
30     def __init__ (self):
31         parser = RawConfigParser ()
32         parser.add_section('manifold')
33         parser.set ('manifold', 'url', Config.default_manifold_url)
34         parser.set ('manifold', 'admin_user', Config.default_manifold_admin_user)
35         parser.set ('manifold', 'admin_password', Config.default_manifold_admin_password)
36         parser.read (os.path.join(ROOT,'myslice/myslice.ini'))
37         self.config_parser=parser
38
39     def manifold_url (self):
40         return self.config_parser.get('manifold','url')
41
42     def manifold_admin_user_password(self):
43         return (self.config_parser.get('manifold','admin_user'),
44                 self.config_parser.get('manifold','admin_password'))
45
46     # exporting these details to js
47     def manifold_js_export (self):
48         return "var MANIFOLD_URL = '%s';\n"%self.manifold_url();