# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: plc_config.py,v 1.1.1.1 2006/03/27 17:36:46 mlhuang Exp $
+# $Id$
#
import xml.dom.minidom
import types
+class ConfigurationException(Exception): pass
+
class PLCConfiguration:
"""
Configuration file store. Optionally instantiate with a file path
file = "/etc/planetlab/plc_config.xml"
if type(file) in types.StringTypes:
- fileobj = open(file, 'r+')
+ fileobj = open(file, 'w')
else:
fileobj = file
fileobj.close()
+ def verify(self, default, read):
+ """ Confirm that the existing configuration is consistent according to
+ the checks below.
+
+ It looks for filled-in values in the order of, local object (self),
+ followed by cread (read values), and finally default values.
+
+ Arguments:
+
+ None
+
+ Returns:
+
+ None. If an exception is found, ConfigurationException is raised.
+
+ """
+
+ (category,maint_user) = self.get('plc_api', 'maintenance_user')
+ if maint_user == None:
+ (category, maint_user) = read.get('plc_api', 'maintenance_user')
+ if maint_user == None:
+ (category,maint_user) = default.get('plc_api', 'maintenance_user')
+ if maint_user == None:
+ raise ConfigurationException("Cannot find PLC_API_MAINTENANCE_USER")
+
+ (category,root_user) = self.get('plc', 'root_user')
+ if root_user == None:
+ (category,root_user) = read.get('plc', 'root_user')
+ if root_user == None:
+ root_user = default.get('plc', 'root_user')
+ if root_user == None:
+ raise ConfigurationException("Cannot find PLC_ROOT_USER")
+
+ muser= maint_user['value']
+ ruser= root_user['value']
+
+ if muser == ruser:
+ raise ConfigurationException("The Maintenance Account email address cannot be the same as the Root User email address")
+ return
+
def get(self, category_id, variable_id):
"""
variables[variable_id] = variable
+ def locate_varname (self, varname):
+ """
+ Locates category and variable from a variable's (shell) name
+
+ Returns:
+ (variable, category) when found
+ (None, None) otherwise
+ """
+
+ for (category_id, (category, variables)) in self._variables.iteritems():
+ for variable in variables.values():
+ (id, name, value, comments) = self._sanitize_variable(category_id, variable)
+ if (id == varname):
+ return (category,variable)
+ return (None,None)
+
def get_package(self, group_id, package_name):
"""
Get the specified package in the specified package group.
return header.strip().split(os.linesep)
- def output_shell(self, encoding = "utf-8"):
+ def output_shell(self, show_comments = True, encoding = "utf-8"):
"""
Return variables as a shell script.
"""
for (category_id, (category, variables)) in self._variables.iteritems():
for variable in variables.values():
(id, name, value, comments) = self._sanitize_variable(category_id, variable)
- buf.write(os.linesep)
- if name is not None:
- buf.write("# " + name + os.linesep)
- if comments is not None:
- buf.writelines(["# " + line + os.linesep for line in comments])
+ if show_comments:
+ buf.write(os.linesep)
+ if name is not None:
+ buf.write("# " + name + os.linesep)
+ if comments is not None:
+ buf.writelines(["# " + line + os.linesep for line in comments])
# bash does not have the concept of NULL
if value is not None:
buf.write(id + "=" + value + os.linesep)
return buf.getvalue()
+ def output_groups(self, encoding = "utf-8"):
+ """
+ Return list of all package group names.
+ """
+
+ buf = codecs.lookup(encoding)[3](StringIO())
+
+ for (group, packages) in self._packages.values():
+ buf.write(group['name'] + os.linesep)
+
+ return buf.getvalue()
+
+
def output_comps(self, encoding = "utf-8"):
"""
Return <comps> section of configuration.
if __name__ == '__main__':
import sys
- if len(sys.argv) > 1 and sys.argv[1] in ['build', 'install']:
+ if len(sys.argv) > 1 and sys.argv[1] in ['build', 'install', 'uninstall']:
from distutils.core import setup
setup(py_modules=["plc_config"])