From e32bbfbca5233d4ad7a5bee74698d614ff0b1f24 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Mon, 30 Jun 2008 15:59:01 +0000 Subject: Unicode support (from stousignant) (Resolves Ticket #549) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4731 ce84e21b-d406-0410-9b95-82705330c041 --- src/sbin/bcfg2 | 5 +++-- src/sbin/bcfg2-build-reports | 6 +++--- src/sbin/bcfg2-info | 13 +++++++------ src/sbin/bcfg2-ping-sweep | 2 +- src/sbin/bcfg2-server | 8 +++++--- 5 files changed, 19 insertions(+), 15 deletions(-) (limited to 'src/sbin') diff --git a/src/sbin/bcfg2 b/src/sbin/bcfg2 index 472eab795..5ac1e3aac 100755 --- a/src/sbin/bcfg2 +++ b/src/sbin/bcfg2 @@ -116,6 +116,7 @@ class Client: 'agent-background': Bcfg2.Options.CLIENT_BACKGROUND, 'key': Bcfg2.Options.SERVER_KEY, 'decision-list': DECISION_LIST, + 'encoding': Bcfg2.Options.ENCODING, } self.setup = Bcfg2.Options.OptionParser(optinfo) @@ -244,7 +245,7 @@ class Client: if len(probes.findall(".//probe")) > 0: try: # upload probe responses - proxy.RecvProbeData(Bcfg2.Client.XML.tostring(probedata)) + proxy.RecvProbeData(Bcfg2.Client.XML.tostring(probedata, encoding='UTF-8', xml_declaration=True)) except: self.logger.error("Failed to upload probe data", exc_info=1) raise SystemExit(1) @@ -293,7 +294,7 @@ class Client: feedback = self.tools.GenerateStats() try: - proxy.RecvStats(Bcfg2.Client.XML.tostring(feedback)) + proxy.RecvStats(Bcfg2.Client.XML.tostring(feedback, encoding='UTF-8', xml_declaration=True)) except xmlrpclib.Fault: self.logger.error("Failed to upload configuration statistics") raise SystemExit(2) diff --git a/src/sbin/bcfg2-build-reports b/src/sbin/bcfg2-build-reports index 534cbdd91..8ae8475a3 100755 --- a/src/sbin/bcfg2-build-reports +++ b/src/sbin/bcfg2-build-reports @@ -100,7 +100,7 @@ def rss(reportxml, delivery, report): for item in items: channel.append(item) - tree = "" + tostring(rssdata) + tree = tostring(rssdata, encoding='UTF-8', xml_declaration=True) fil.write(tree) fil.close() @@ -249,7 +249,7 @@ if __name__ == '__main__': #apply XSLT, different ones based on report type, and options if deliverymechanism == 'null-operator': #Special Cases - fileout(tostring(ElementTree(procnodereport).getroot()), deliv) + fileout(tostring(ElementTree(procnodereport).getroot(), encoding='UTF-8', xml_declaration=True), deliv) break transform = delivtype + '-' + deliverymechanism + '.xsl' @@ -301,7 +301,7 @@ if __name__ == '__main__': (toastring, socket.getfqdn(), outputstring) mail(outputstring, c) #call function to send else: - outputstring = tostring(stylesheet.apply(ElementTree(procnodereport)).getroot()) + outputstring = tostring(stylesheet.apply(ElementTree(procnodereport)).getroot(), encoding='UTF-8', xml_declaration=True) if deliverymechanism == 'rss': rss(outputstring, deliv, reprt) else: # must be deliverymechanism == 'www': diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info index dac7fa6bf..9cffc8719 100755 --- a/src/sbin/bcfg2-info +++ b/src/sbin/bcfg2-info @@ -23,10 +23,10 @@ def printTabular(rows): print fstring % row class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core): - def __init__(self, repo, struct, gens, passwd, svn): + def __init__(self, repo, struct, gens, passwd, svn, encoding): cmd.Cmd.__init__(self) try: - Bcfg2.Server.Core.Core.__init__(self, repo, struct, gens, passwd, svn) + Bcfg2.Server.Core.Core.__init__(self, repo, struct, gens, passwd, svn, encoding) except Bcfg2.Server.Core.CoreInitError, msg: print "Core load failed because %s" % msg raise SystemExit(1) @@ -97,7 +97,7 @@ Usage: [quit|exit]""" if len(args.split()) == 2: client, ofile = args.split() output = open(ofile, 'w') - data = lxml.etree.tostring(self.BuildConfiguration(client)) + data = lxml.etree.tostring(self.BuildConfiguration(client), encoding='UTF-8', xml_declaration=True) output.write(data) output.close() else: @@ -121,7 +121,7 @@ Usage: [quit|exit]""" entry = lxml.etree.Element('ConfigFile', name=fname) metadata = self.metadata.get_metadata(client) self.Bind(entry, metadata) - print lxml.etree.tostring(entry) + print lxml.etree.tostring(entry, encoding="UTF-8", xml_declaration=True) else: print 'Usage: buildfile filename hostname' @@ -271,12 +271,13 @@ if __name__ == '__main__': 'svn': Bcfg2.Options.SERVER_SVN, 'structures': Bcfg2.Options.SERVER_STRUCTURES, 'generators': Bcfg2.Options.SERVER_GENERATORS, - 'password': Bcfg2.Options.SERVER_PASSWORD}) + 'password': Bcfg2.Options.SERVER_PASSWORD, + 'encoding': Bcfg2.Options.ENCODING}) setup = Bcfg2.Options.OptionParser(optinfo) setup.parse(sys.argv[1:]) loop = infoCore(setup['repo'], setup['structures'], setup['generators'], - setup['password'], setup['svn']) + setup['password'], setup['svn'], setup['encoding']) loop.plugins['Metadata'] if "args" in setup and setup['args']: loop.onecmd(" ".join(setup['args'])) diff --git a/src/sbin/bcfg2-ping-sweep b/src/sbin/bcfg2-ping-sweep index 54c645277..88d8bd782 100755 --- a/src/sbin/bcfg2-ping-sweep +++ b/src/sbin/bcfg2-ping-sweep @@ -63,6 +63,6 @@ if __name__ == '__main__': elm.set("pingable",'N') fout = open(clientdatapath, 'w') - fout.write(lxml.etree.tostring(clientElement.getroot())) + fout.write(lxml.etree.tostring(clientElement.getroot(), encoding='UTF-8', xml_declaration=True)) fout.close() diff --git a/src/sbin/bcfg2-server b/src/sbin/bcfg2-server index a5c5310ba..d26fce9bf 100755 --- a/src/sbin/bcfg2-server +++ b/src/sbin/bcfg2-server @@ -41,7 +41,8 @@ class Bcfg2Serv(Bcfg2.Component.Component): try: self.Core = Core(setup['repo'], setup['structures'], - setup['generators'], setup['password'], setup['svn']) + setup['generators'], setup['password'], + setup['svn'], setup['encoding']) except CoreInitError, msg: logger.critical("Fatal error: %s" % (msg)) raise SystemExit, 1 @@ -104,7 +105,7 @@ class Bcfg2Serv(Bcfg2.Component.Component): if isinstance(p, Bcfg2.Server.Plugin.ProbingPlugin)]: for probe in plugin.GetProbes(meta): resp.append(probe) - return tostring(resp) + return tostring(resp, encoding='UTF-8', xml_declaration=True) except Bcfg2.Server.Plugins.Metadata.MetadataConsistencyError: warning = 'Client metadata resolution error for %s; check server log' % address[0] self.logger.warning(warning) @@ -158,7 +159,7 @@ class Bcfg2Serv(Bcfg2.Component.Component): '''Build config for a client''' try: client = self.Core.metadata.resolve_client(address) - return tostring(self.Core.BuildConfiguration(client)) + return tostring(self.Core.BuildConfiguration(client), encoding='UTF-8', xml_declaration=True) except Bcfg2.Server.Plugins.Metadata.MetadataConsistencyError: self.logger.warning("Metadata consistency failure for %s" % (address)) raise Fault, (6, "Metadata consistency failure") @@ -201,6 +202,7 @@ if __name__ == '__main__': 'location' : Bcfg2.Options.SERVER_LOCATION, 'passwd' : Bcfg2.Options.SERVER_PASSWORD, 'static' : Bcfg2.Options.SERVER_STATIC, + 'encoding' : Bcfg2.Options.ENCODING, }) -- cgit v1.2.3-1-g7c22