Removed some useless options from close.

This commit is contained in:
Jeremy Fincher 2004-10-03 22:18:12 +00:00
parent 849de99827
commit 76fc8b946e
3 changed files with 32 additions and 30 deletions

View File

@ -216,7 +216,7 @@ if __name__ == '__main__':
if world.dying: if world.dying:
logger = log.info logger = log.info
logger('Writing registry file to %s', registryFilename) logger('Writing registry file to %s', registryFilename)
registry.close(conf.supybot, registryFilename, annotated=True) registry.close(conf.supybot, registryFilename)
logger('Finished writing registry file.') logger('Finished writing registry file.')
world.flushers.append(closeRegistry) world.flushers.append(closeRegistry)
world.registryFilename = registryFilename world.registryFilename = registryFilename

View File

@ -89,35 +89,37 @@ def open(filename, clear=False):
_lastModified = time.time() _lastModified = time.time()
_fd.close() _fd.close()
def close(registry, filename, annotated=True, helpOnceOnly=False): def close(registry, filename, private=True):
first = True first = True
helpCache = sets.Set()
fd = utils.transactionalFile(filename) fd = utils.transactionalFile(filename)
for (name, value) in registry.getValues(getChildren=True): for (name, value) in registry.getValues(getChildren=True):
if annotated and hasattr(value,'_help') and value._help: help = value.help()
if not helpOnceOnly or value._help not in helpCache: if help:
helpCache.add(value._help) lines = textwrap.wrap(value._help)
lines = textwrap.wrap(value._help) for (i, line) in enumerate(lines):
for (i, line) in enumerate(lines): lines[i] = '# %s\n' % line
lines[i] = '# %s\n' % line lines.insert(0, '###\n')
lines.insert(0, '###\n') if first:
if first: first = False
first = False else:
else: lines.insert(0, '\n')
lines.insert(0, '\n') if hasattr(value, 'value'):
if hasattr(value, 'value'): if value._showDefault:
if value._showDefault: lines.append('#\n')
lines.append('#\n') x = value.__class__(value._default, value._help)
x = value.__class__(value._default, value._help) try:
try: lines.append('# Default value: %s\n' % x)
lines.append('# Default value: %s\n' % x) except Exception, e:
except Exception, e: exception('Exception printing default value:')
exception('Exception printing default value:') lines.append('###\n')
lines.append('###\n') fd.writelines(lines)
fd.writelines(lines)
if hasattr(value, 'value'): # This lets us print help for non-valued. if hasattr(value, 'value'): # This lets us print help for non-valued.
try: try:
fd.write('%s: %s\n' % (name, value.serialize())) if private or not value._private:
s = value.serialize()
else:
s = 'CENSORED'
fd.write('%s: %s\n' % (name, s))
except Exception, e: except Exception, e:
exception('Exception printing value:') exception('Exception printing value:')
@ -151,13 +153,14 @@ def join(names):
class Group(object): class Group(object):
"""A group; it doesn't hold a value unless handled by a subclass.""" """A group; it doesn't hold a value unless handled by a subclass."""
def __init__(self, help='', def __init__(self, help='', supplyDefault=False,
supplyDefault=False, orderAlphabetically=False): orderAlphabetically=False, private=False):
self._help = help self._help = help
self._name = 'unset' self._name = 'unset'
self._added = [] self._added = []
self._children = utils.InsensitivePreservingDict() self._children = utils.InsensitivePreservingDict()
self._lastModified = 0 self._lastModified = 0
self._private = private
self._supplyDefault = supplyDefault self._supplyDefault = supplyDefault
self._orderAlphabetically = orderAlphabetically self._orderAlphabetically = orderAlphabetically
OriginalClass = self.__class__ OriginalClass = self.__class__
@ -284,11 +287,10 @@ class Value(Group):
"""Invalid registry value. If you're getting this message, report it, """Invalid registry value. If you're getting this message, report it,
because we forgot to put a proper help string here.""" because we forgot to put a proper help string here."""
def __init__(self, default, help, setDefault=True, def __init__(self, default, help, setDefault=True,
private=False, showDefault=True, **kwargs): showDefault=True, **kwargs):
self.__parent = super(Value, self) self.__parent = super(Value, self)
self.__parent.__init__(help, **kwargs) self.__parent.__init__(help, **kwargs)
self._default = default self._default = default
self._private = private
self._showDefault = showDefault self._showDefault = showDefault
self._help = utils.normalizeWhitespace(help.strip()) self._help = utils.normalizeWhitespace(help.strip())
if setDefault: if setDefault:

View File

@ -74,7 +74,7 @@ ircs = [] # A list of all the IRCs.
def _flushUserData(): def _flushUserData():
userdataFilename = os.path.join(conf.supybot.directories.conf(), userdataFilename = os.path.join(conf.supybot.directories.conf(),
'userdata.conf') 'userdata.conf')
registry.close(conf.users, userdataFilename, annotated=False) registry.close(conf.users, userdataFilename)
flushers = [_flushUserData] # A periodic function will flush all these. flushers = [_flushUserData] # A periodic function will flush all these.