Package flumotion :: Package admin :: Module config
[hide private]

Source Code for Module flumotion.admin.config

 1  # -*- Mode: Python; test-case-name: flumotion.test.test_config -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3   
 4  # Flumotion - a streaming media server 
 5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
 6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
 7  # All rights reserved. 
 8  # 
 9  # This file may be distributed and/or modified under the terms of 
10  # the GNU Lesser General Public License version 2.1 as published by 
11  # the Free Software Foundation. 
12  # This file is distributed without any warranty; without even the implied 
13  # warranty of merchantability or fitness for a particular purpose. 
14  # See "LICENSE.LGPL" in the source distribution for more information. 
15  # 
16  # Headers in this file shall remain intact. 
17   
18  """ 
19  parsing of admin configuration files 
20  """ 
21   
22  from flumotion.common import errors 
23  from flumotion.common import config as fluconfig 
24   
25  __version__ = "$Rev$" 
26   
27   
28 -class AdminConfigParser(fluconfig.BaseConfigParser):
29 """ 30 Admin configuration file parser. 31 """ 32 logCategory = 'config' 33
34 - def __init__(self, sockets, file):
35 """ 36 @param file: The file to parse, either as an open file object, 37 or as the name of a file to open. 38 @type file: str or file. 39 """ 40 self.plugs = {} 41 for socket in sockets: 42 self.plugs[socket] = [] 43 44 # will start the parse via self.add() 45 fluconfig.BaseConfigParser.__init__(self, file)
46
47 - def _parse(self):
48 # <admin> 49 # <plugs> 50 root = self.doc.documentElement 51 if not root.nodeName == 'admin': 52 raise errors.ConfigError("unexpected root node': %s" % 53 (root.nodeName, )) 54 55 def parseplugs(node): 56 return fluconfig.buildPlugsSet(self.parsePlugs(node), 57 self.plugs.keys())
58 59 def addplugs(plugs): 60 for socket in plugs: 61 self.plugs[socket].extend(plugs[socket])
62 parsers = {'plugs': (parseplugs, addplugs)} 63 64 self.parseFromTable(root, parsers) 65 self.doc.unlink() 66 self.doc = None 67
68 - def add(self, file):
69 """ 70 @param file: The file to parse, either as an open file object, 71 or as the name of a file to open. 72 @type file: str or file. 73 """ 74 fluconfig.BaseConfigParser.add(self, file) 75 self._parse()
76