try to wrap long lines in config file, attributes are still sorted into alpha order :-(

This commit is contained in:
sqlcoder 2010-06-09 22:46:17 +01:00
parent 5803933ba0
commit fbefe1e611
2 changed files with 34 additions and 1 deletions

View File

@ -32,6 +32,7 @@ import string
import traceback import traceback
import shutil import shutil
import locale import locale
import re
import xml.dom.minidom import xml.dom.minidom
from xml.dom.minidom import Node from xml.dom.minidom import Node
@ -662,7 +663,34 @@ class Config:
pass pass
with open(file, 'w') as f: 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, def edit_layout(self, site_name, max, width = None, height = None,
fav_seat = None, locations = None): fav_seat = None, locations = None):

View File

@ -2,6 +2,11 @@
<FreePokerToolsConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FreePokerToolsConfig.xsd"> <FreePokerToolsConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FreePokerToolsConfig.xsd">
<general config_wrap_len="-1" <!-- preferred max line length in this file, -1 means no max -->
day_start="5" <!-- time that logical day starts, e.g. 5 means that any play
between 00:00 and 04:59:59 counts as being on the previous day -->
/>
<import callFpdbHud = "True" interval = "10" fastStoreHudCache="False" hhArchiveBase="~/.fpdb/HandHistories/" saveActions="True"></import> <import callFpdbHud = "True" interval = "10" fastStoreHudCache="False" hhArchiveBase="~/.fpdb/HandHistories/" saveActions="True"></import>
<!-- These values determine what stats are displayed in the HUD <!-- These values determine what stats are displayed in the HUD