51bf4b7967e0d829f1f9f2166dff0a72a77e5e2a
[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 write myslice/myslice.ini
6 # that looks like this
7 #[manifold]
8 #url = http://manifold.pl.sophia.inria.fr:7080/
9
10 class Config:
11
12     # the OpenLab-wide backend as managed by UPMC
13     # xxx production should probably use https of course
14     default_manifold_url = "http://test.myslice.info:7080/"
15     # the devel/unstable version runs on "http://dev.myslice.info:7080/"
16     # if you use a development backend running on this box, use "http://localhost:7080/"
17     # the INRIA setup is with "http://manifold.pl.sophia.inria.fr:7080/"
18
19     default_manifold_admin_user     = 'admin'
20     default_manifold_admin_password = None
21
22     _config_parser = None
23
24     # having grown tired of screwing up with git stashes 
25     # taking away my local config, we now more properly use
26     # an external config file to override teh default
27     # XXX we might use support from manifold util classes --jordan
28     @staticmethod
29     def manifold_url ():
30         if Config._config_parser: 
31             return Config._config_parser.get('manifold','url')
32         config = RawConfigParser ()
33         config.add_section('manifold')
34         config.set ('manifold', 'url', Config.default_manifold_url)
35         config.read (os.path.join(ROOT,'myslice/myslice.ini'))
36         Config._config_parser=config
37         return Config.manifold_url()
38
39     @staticmethod
40     def manifold_admin_user_password():
41         if Config._config_parser: 
42             admin_user = Config._config_parser.get('manifold','admin_user')
43             admin_password = Config._config_parser.get('manifold','admin_password')
44             return (admin_user, admin_password)
45         config = RawConfigParser ()
46         config.add_section('manifold')
47         config.set ('manifold', 'admin_user', Config.default_manifold_admin_user)
48         config.set ('manifold', 'admin_password', Config.default_manifold_admin_password)
49         config.read (os.path.join(ROOT,'myslice/myslice.ini'))
50         Config._config_parser=config
51         return Config.manifold_admin_user_password()
52
53     # exporting these details to js
54     @staticmethod
55     def manifold_js_export ():
56         return "var MANIFOLD_URL = '%s';\n"%Config.manifold_url();