Merge branch 'upstreammaster'
[sfa.git] / sfa / util / topology.py
1 ##
2 # SFA Topology Info
3 #
4 # This module holds topology configuration for SFA. It is implemnted as a 
5 # list of site_id tuples
6
7 import os.path
8 import traceback
9 from sfa.util.sfalogging import logger
10
11 class Topology(set):
12     """
13     Parse the topology configuration file. 
14     """
15
16     #def __init__(self, config_file = "/etc/sfa/topology"):
17     def __init__(self, config_file = "/tmp/topology"):
18         set.__init__(self) 
19         self.config_file = None
20         self.config_path = None
21         self.load(config_file)
22
23     def load(self, config_file):
24         try:
25             
26             self.config_file = config_file
27             # path to configuration data
28             self.config_path = os.path.dirname(config_file)
29             # load the links
30             f = open(config_file, 'r')
31             for line in f:
32                 ignore = line.find('#')
33                 if ignore > -1:
34                     line = line[0:ignore]
35                 tup = line.split()
36                 if len(tup) > 1:
37                     self.add((tup[0], tup[1]))    
38         except Exception, e:
39             logger.log_exc("Could not find or load the configuration file: %s" % config_file)
40             raise