From fbefe1e611cf53570ba8a744ab95112d6131d8c5 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Wed, 9 Jun 2010 22:46:17 +0100 Subject: [PATCH] try to wrap long lines in config file, attributes are still sorted into alpha order :-( --- pyfpdb/Configuration.py | 30 +++++++++++++++++++++++++++++- pyfpdb/HUD_config.xml.example | 5 +++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index ee957e2d..4b5134af 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -32,6 +32,7 @@ import string import traceback import shutil import locale +import re import xml.dom.minidom from xml.dom.minidom import Node @@ -662,7 +663,34 @@ class Config: pass with open(file, 'w') as f: - self.doc.writexml(f) + #self.doc.writexml(f) + f.write( self.wrap_long_lines( self.doc.toxml() ) ) + + def wrap_long_lines(self, s): + lines = [ self.wrap_long_line(l) for l in s.splitlines() ] + return('\n'.join(lines) + '\n') + + def wrap_long_line(self, l): + if 'config_wrap_len' in self.general: + wrap_len = int(self.general['config_wrap_len']) + else: + wrap_len = -1 # < 0 means no wrap + + if wrap_len >= 0 and len(l) > wrap_len: + m = re.compile('\s+\S+\s+') + mo = m.match(l) + if mo: + indent_len = mo.end() + #print "indent = %s (%s)" % (indent_len, l[0:indent_len]) + indent = '\n' + ' ' * indent_len + m = re.compile('(\S+="[^"]+"\s+)') + parts = [x for x in m.split(l[indent_len:]) if x] + if len(parts) > 1: + #print "parts =", parts + l = l[0:indent_len] + indent.join(parts) + return(l) + else: + return(l) def edit_layout(self, site_name, max, width = None, height = None, fav_seat = None, locations = None): diff --git a/pyfpdb/HUD_config.xml.example b/pyfpdb/HUD_config.xml.example index 5a72c4c6..617a34d3 100644 --- a/pyfpdb/HUD_config.xml.example +++ b/pyfpdb/HUD_config.xml.example @@ -2,6 +2,11 @@ + + day_start="5" + /> +