X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plc_config.py;h=913ccfdc80f3a2849f7b45f6de1ac68c0ed5abad;hb=e432974c3c8ef648782172d855d20cb6d51ed5ae;hp=b3ae90dade36dee93c499b244f5a204b086e543f;hpb=2b5a03e21b801468b9e509d49626b97e7798922e;p=myplc.git diff --git a/plc_config.py b/plc_config.py index b3ae90d..913ccfd 100644 --- a/plc_config.py +++ b/plc_config.py @@ -7,7 +7,7 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id$ +# $Id: plc_config.py,v 1.3 2006/04/18 15:32:48 thierry Exp $ # import xml.dom.minidom @@ -225,7 +225,7 @@ class PLCConfiguration: file = "/etc/planetlab/plc_config.xml" if type(file) in types.StringTypes: - fileobj = open(file, 'r+') + fileobj = open(file, 'w') else: fileobj = file @@ -388,6 +388,22 @@ class PLCConfiguration: 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. @@ -633,7 +649,7 @@ DO NOT EDIT. This file was automatically generated at 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. """ @@ -644,11 +660,12 @@ DO NOT EDIT. This file was automatically generated at 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) @@ -675,7 +692,7 @@ DO NOT EDIT. This file was automatically generated at buf.writelines(["// " + line + os.linesep for line in comments]) if value is None: value = 'NULL' - buf.write("DEFINE('%s', %s);" % (id, value) + os.linesep) + buf.write("define('%s', %s);" % (id, value) + os.linesep) buf.write("?>" + os.linesep) @@ -724,6 +741,19 @@ DO NOT EDIT. This file was automatically generated at 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 section of configuration.