6341ac3273b56e00915e1793c0a0434fb86a705d
[myslice.git] / myslice / configengine.py
1 import os.path
2 from ConfigParser import RawConfigParser
3 from myslice.settings import ROOT
4
5 #
6 # DO NOT EDIT !!!
7 #
8 # This file does not contain any user-modifiable data
9 #
10 # te defaults here are, well, only default values, 
11 # and, you have the option to override them
12 # by writing a file myslice/myslice.ini
13 # that looks like this
14 #[manifold]
15 #url = http://manifold.pl.sophia.inria.fr:7080/
16 #admin_user = admin
17 #admin_password = admin
18 #[googlemap]
19 #api_key=theapikeyasprovidedbygoogle
20
21 # use a singleton instead of staticmethods
22 from myslice.util.singleton    import Singleton
23
24 class ConfigEngine(object):
25     __metaclass__ = Singleton
26
27     # the OpenLab-wide backend as managed by UPMC
28     # xxx production should probably use https of course
29     default_manifold_url = "https://test.myslice.info:7080/"
30     # the devel/unstable version runs on "https://dev.myslice.info:7080/"
31     # if you use a development backend running on this box, use "http://localhost:7080/"
32     # the INRIA setup is with "https://manifold.pl.sophia.inria.fr:7080/"
33
34     default_manifold_admin_user     = 'admin'
35     default_manifold_admin_password = 'demo'
36     default_myslice_theme           = 'onelab'
37
38     #iotlab dev url
39     default_iotlab_url = "https://devwww.iot-lab.info/rest/admin/users"
40     default_iotlab_admin_user = "xxx"
41     default_iotlab_admin_password= "yyy"
42
43     def __init__ (self):
44         parser = RawConfigParser ()
45         parser.add_section('manifold')
46         parser.set ('manifold', 'url', ConfigEngine.default_manifold_url)
47         parser.set ('manifold', 'admin_user', ConfigEngine.default_manifold_admin_user)
48         parser.set ('manifold', 'admin_password', ConfigEngine.default_manifold_admin_password)
49
50         parser.add_section('myslice')
51         parser.set ('myslice', 'theme', ConfigEngine.default_myslice_theme)
52
53         parser.add_section('iotlab')
54         parser.set ('iotlab', 'url', ConfigEngine.default_iotlab_url)
55         parser.set ('iotlab', 'admin_user', ConfigEngine.default_iotlab_admin_user)
56         parser.set ('iotlab', 'admin_password', ConfigEngine.default_iotlab_admin_password)
57
58         parser.add_section('googlemap')
59         parser.set ('googlemap','api_key', None)
60         parser.read (os.path.join(ROOT,'myslice/myslice.ini'))
61         self.config_parser=parser
62
63     def __getattr__(self, section):
64         if self.config_parser.has_section(section):
65             return ConfigSection(self.config_parser, section)
66         
67     def manifold_url (self):
68         return self.config_parser.get('manifold','url')
69
70     def manifold_admin_user_password(self):
71         return (self.config_parser.get('manifold','admin_user'),
72                 self.config_parser.get('manifold','admin_password'))
73
74     def iotlab_url (self):
75         return self.config_parser.get('iotlab','url')
76
77     def iotlab_admin_user(self):
78         return self.config_parser.get('iotlab','admin_user')
79
80     def iotlab_admin_password(self):
81         return self.config_parser.get('iotlab','admin_password')
82
83     def googlemap_api_key (self):
84         return self.config_parser.get('googlemap','api_key')
85
86     # exporting these details to js
87     def manifold_js_export (self):
88         return "var MANIFOLD_URL = '%s';\n"%self.manifold_url();
89
90 class ConfigSection(object) :
91     
92     def __init__(self, parser, section):
93         self._parser = parser
94         self._section = section
95     
96     def __getattr__(self, key):
97         if self._parser.has_option(self._section, key):
98             return self._parser.get(self._section, key)