Browse Source

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
master
Jan Dittberner 14 years ago
parent
commit
5e143677d8
  1. 2
      gnuviechadmin/backend/BackendEntity.py
  2. 2
      gnuviechadmin/backend/domain.py
  3. 3
      gnuviechadmin/backend/settings.py

2
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)

2
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({

3
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."""

Loading…
Cancel
Save