From 5e143677d83518fd2cd33b475718a79bebeab432 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sat, 5 Apr 2008 18:48:46 +0000 Subject: [PATCH] r1097@denkpolster: jan | 2008-04-05 20:48:26 +0200 fixed unicode handling for templates (fixes #14) * templates are now assumed to be UTF-8 encoded * output files are written in UTF-8 encoding too git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/trunk@253 a67ec6bc-e5d5-0310-a910-815c51eb3124 --- gnuviechadmin/backend/BackendEntity.py | 2 +- gnuviechadmin/backend/domain.py | 2 ++ gnuviechadmin/backend/settings.py | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gnuviechadmin/backend/BackendEntity.py b/gnuviechadmin/backend/BackendEntity.py index bfb9c15..8990293 100644 --- a/gnuviechadmin/backend/BackendEntity.py +++ b/gnuviechadmin/backend/BackendEntity.py @@ -105,7 +105,7 @@ class BackendEntity(object): def write_to_file(self, filename, template): """Write the data from template to the specified file.""" tmp = tempfile.NamedTemporaryFile() - tmp.write(template) + tmp.write(template.encode('utf_8')) tmp.flush() cmd = 'cp "%s" "%s"' % (tmp.name, filename) self.sucommand(cmd) diff --git a/gnuviechadmin/backend/domain.py b/gnuviechadmin/backend/domain.py index 28c9c56..8a74e30 100644 --- a/gnuviechadmin/backend/domain.py +++ b/gnuviechadmin/backend/domain.py @@ -120,11 +120,13 @@ class DomainEntity(BackendEntity): def _create_vhost_dir(self): vhostdir = self._get_vhost_dir() + self.logger.debug("creating virtual host dir %s" % (vhostdir)) cmd = 'mkdir -p "%s"' % (vhostdir) self.sucommand(cmd) for tpl in [tpl for tpl in os.listdir( get_template_dir(config.get('domain', 'htdocstemplate'))) \ if not tpl.startswith('.')]: + self.logger.debug("processing template %s" % (tpl)) template = get_template(config.get('domain', 'htdocstemplate'), tpl) template = template.substitute({ diff --git a/gnuviechadmin/backend/settings.py b/gnuviechadmin/backend/settings.py index 08217ee..83043ca 100644 --- a/gnuviechadmin/backend/settings.py +++ b/gnuviechadmin/backend/settings.py @@ -43,7 +43,8 @@ def get_template(dirname, filename): """Returns the template data from the given template file.""" templatefile = file(os.path.join(get_template_dir(dirname), filename)) - return string.Template(templatefile.read()) + templatedata = templatefile.read() + return string.Template(templatedata.decode('utf_8')) def get_template_string(templatestring): """Returns a template object for the given template string."""