- add example
[nodemanager.git] / config.py
1 #!/usr/bin/python
2 #
3 # Parses the PLC configuration file /etc/planetlab/plc_config, which
4 # is bootstrapped by Boot Manager, but managed by us.
5 #
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2006 The Trustees of Princeton University
8 #
9 # $Id: config.py,v 1.3 2006/10/31 23:15:12 mlhuang Exp $
10 #
11
12 class Config:
13     """
14     Parses Python configuration files; all variables in the file are
15     assigned to class attributes.
16     """
17
18     def __init__(self, file = "/etc/planetlab/plc_config"):
19         try:
20             execfile(file, self.__dict__)
21         except:
22             raise Exception, "Could not parse " + file
23
24         if int(self.PLC_API_PORT) == 443:
25             uri = "https://"
26         else:
27             uri = "http://"
28
29         uri += self.PLC_API_HOST + \
30                ":" + str(self.PLC_API_PORT) + \
31                "/" + self.PLC_API_PATH + "/"
32
33         self.plc_api_uri = uri
34
35 if __name__ == '__main__':
36     from pprint import pprint
37     pprint(Config().__dict__.items())