2004-01-13 07:07:31 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
###
|
2004-01-13 16:56:58 +01:00
|
|
|
# Copyright (c) 2004, Jeremiah Fincher
|
2004-01-13 07:07:31 +01:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
###
|
|
|
|
|
|
|
|
__revision__ = "$Id$"
|
|
|
|
|
2004-01-20 18:09:57 +01:00
|
|
|
import re
|
2004-01-13 07:07:31 +01:00
|
|
|
import copy
|
2004-01-18 08:58:26 +01:00
|
|
|
import sets
|
2004-01-22 21:16:21 +01:00
|
|
|
import time
|
2004-01-18 08:58:26 +01:00
|
|
|
import types
|
2004-01-21 16:48:48 +01:00
|
|
|
import textwrap
|
2004-01-13 07:07:31 +01:00
|
|
|
|
2004-01-21 18:13:04 +01:00
|
|
|
import fix
|
2004-01-13 07:07:31 +01:00
|
|
|
import utils
|
|
|
|
|
|
|
|
class RegistryException(Exception):
|
|
|
|
pass
|
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
class InvalidRegistryFile(RegistryException):
|
|
|
|
pass
|
|
|
|
|
2004-01-13 07:07:31 +01:00
|
|
|
class InvalidRegistryValue(RegistryException):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class NonExistentRegistryEntry(RegistryException):
|
|
|
|
pass
|
|
|
|
|
2004-02-05 08:54:38 +01:00
|
|
|
_cache = utils.InsensitivePreservingDict()
|
2004-01-22 21:16:21 +01:00
|
|
|
_lastModified = 0
|
2004-01-14 07:05:58 +01:00
|
|
|
def open(filename):
|
|
|
|
"""Initializes the module by loading the registry file into memory."""
|
2004-01-22 21:16:21 +01:00
|
|
|
global _lastModified
|
2004-01-20 12:41:53 +01:00
|
|
|
_cache.clear()
|
2004-01-14 07:05:58 +01:00
|
|
|
fd = utils.nonCommentNonEmptyLines(file(filename))
|
2004-01-18 08:58:26 +01:00
|
|
|
for (i, line) in enumerate(fd):
|
|
|
|
line = line.rstrip('\r\n')
|
|
|
|
try:
|
2004-01-20 18:09:57 +01:00
|
|
|
(key, value) = re.split(r':\s*', line, 1)
|
2004-01-18 08:58:26 +01:00
|
|
|
except ValueError:
|
|
|
|
raise InvalidRegistryFile, 'Error unpacking line #%s' % (i+1)
|
2004-02-05 08:54:38 +01:00
|
|
|
_cache[key] = value
|
2004-01-22 21:16:21 +01:00
|
|
|
_lastModified = time.time()
|
2004-01-14 07:05:58 +01:00
|
|
|
|
2004-02-05 08:54:38 +01:00
|
|
|
def close(registry, filename, annotated=True, helpOnceOnly=False):
|
2004-01-21 18:13:04 +01:00
|
|
|
first = True
|
|
|
|
helpCache = sets.Set()
|
2004-01-14 07:05:58 +01:00
|
|
|
fd = file(filename, 'w')
|
2004-01-18 08:58:26 +01:00
|
|
|
for (name, value) in registry.getValues(getChildren=True):
|
2004-02-05 08:54:38 +01:00
|
|
|
if annotated and hasattr(value,'help') and value.help:
|
|
|
|
if not helpOnceOnly or value.help not in self.helpCache:
|
|
|
|
helpCache.add(value.help)
|
|
|
|
lines = textwrap.wrap(value.help)
|
|
|
|
for (i, line) in enumerate(lines):
|
|
|
|
lines[i] = '# %s\n' % line
|
|
|
|
lines.insert(0, '###\n')
|
|
|
|
if first:
|
|
|
|
first = False
|
|
|
|
else:
|
|
|
|
lines.insert(0, '\n')
|
2004-02-08 00:35:42 +01:00
|
|
|
if hasattr(value, 'value'):
|
|
|
|
lines.append('#\n')
|
2004-02-10 04:15:31 +01:00
|
|
|
if value.showDefault:
|
|
|
|
try:
|
|
|
|
original = value.value
|
|
|
|
value.value = value.default
|
|
|
|
lines.append('# Default value: %s\n' % value)
|
|
|
|
finally:
|
|
|
|
value.value = original
|
2004-02-05 08:54:38 +01:00
|
|
|
lines.append('###\n')
|
|
|
|
fd.writelines(lines)
|
2004-02-08 00:35:42 +01:00
|
|
|
if hasattr(value, 'value'): # This lets us print help for non-valued.
|
|
|
|
fd.write('%s: %s\n' % (name, value))
|
2004-01-14 07:05:58 +01:00
|
|
|
fd.close()
|
2004-01-18 08:58:26 +01:00
|
|
|
|
|
|
|
|
2004-02-03 17:43:22 +01:00
|
|
|
class Group(object):
|
|
|
|
def __init__(self, supplyDefault=False):
|
|
|
|
self.name = 'unset'
|
|
|
|
self.added = []
|
2004-02-05 08:54:38 +01:00
|
|
|
self.children = utils.InsensitivePreservingDict()
|
2004-02-03 17:43:22 +01:00
|
|
|
self._lastModified = 0
|
|
|
|
self.supplyDefault = supplyDefault
|
|
|
|
OriginalClass = self.__class__
|
|
|
|
class X(OriginalClass):
|
|
|
|
"""This class exists to differentiate those values that have
|
|
|
|
been changed from their default from those that haven't."""
|
|
|
|
def set(self, *args):
|
|
|
|
self.__class__ = OriginalClass
|
|
|
|
self.set(*args)
|
|
|
|
def setValue(self, *args):
|
|
|
|
self.__class__ = OriginalClass
|
|
|
|
self.setValue(*args)
|
|
|
|
self.X = X
|
|
|
|
|
|
|
|
def __nonExistentEntry(self, attr):
|
|
|
|
s = '%s is not a valid entry in %s' % (attr, self.name)
|
|
|
|
raise NonExistentRegistryEntry, s
|
|
|
|
|
|
|
|
def __makeChild(self, attr, s):
|
|
|
|
v = self.__class__(self.default, self.help)
|
|
|
|
v.set(s)
|
|
|
|
v.__class__ = self.X
|
|
|
|
v.supplyDefault = False
|
2004-02-05 08:54:38 +01:00
|
|
|
v.help = '' # Clear this so it doesn't print a bazillion times.
|
2004-02-03 17:43:22 +01:00
|
|
|
self.register(attr, v)
|
|
|
|
return v
|
|
|
|
|
|
|
|
def __getattr__(self, attr):
|
|
|
|
if attr in self.children:
|
|
|
|
return self.children[attr]
|
|
|
|
elif self.supplyDefault:
|
2004-02-05 08:54:38 +01:00
|
|
|
return self.__makeChild(attr, str(self))
|
2004-02-03 17:43:22 +01:00
|
|
|
else:
|
2004-02-05 08:54:38 +01:00
|
|
|
self.__nonExistentEntry(attr)
|
2004-02-03 17:43:22 +01:00
|
|
|
|
|
|
|
def get(self, attr):
|
|
|
|
# Not getattr(self, attr) because some nodes might have groups that
|
|
|
|
# are named the same as their methods.
|
|
|
|
return self.__getattr__(attr)
|
|
|
|
|
|
|
|
def setName(self, name):
|
|
|
|
self.name = name
|
2004-02-05 08:54:38 +01:00
|
|
|
if name in _cache and self._lastModified < _lastModified:
|
|
|
|
self.set(_cache[name])
|
2004-02-03 17:43:22 +01:00
|
|
|
if self.supplyDefault:
|
|
|
|
for (k, v) in _cache.iteritems():
|
|
|
|
if k.startswith(self.name):
|
|
|
|
(_, group) = rsplit(k, '.', 1)
|
2004-02-06 10:19:54 +01:00
|
|
|
try:
|
|
|
|
self.__makeChild(group, v)
|
|
|
|
except InvalidRegistryValue:
|
|
|
|
# It's probably supposed to be registered later.
|
|
|
|
pass
|
2004-02-03 17:43:22 +01:00
|
|
|
|
|
|
|
def register(self, name, node=None):
|
|
|
|
if node is None:
|
|
|
|
node = Group()
|
|
|
|
if name not in self.children: # XXX Is this right?
|
|
|
|
self.children[name] = node
|
2004-02-05 08:54:38 +01:00
|
|
|
self.added.append(name)
|
|
|
|
fullname = '%s.%s' % (self.name, name)
|
2004-02-03 17:43:22 +01:00
|
|
|
node.setName(fullname)
|
|
|
|
|
|
|
|
def unregister(self, name):
|
|
|
|
try:
|
|
|
|
del self.children[name]
|
2004-02-05 08:54:38 +01:00
|
|
|
self.added.remove(name)
|
2004-02-03 17:43:22 +01:00
|
|
|
except KeyError:
|
2004-02-05 08:54:38 +01:00
|
|
|
self.__nonExistentEntry(name)
|
2004-02-03 17:43:22 +01:00
|
|
|
|
|
|
|
def getValues(self, getChildren=False, fullNames=True):
|
|
|
|
L = []
|
2004-02-05 08:54:38 +01:00
|
|
|
for name in self.added:
|
2004-02-03 17:43:22 +01:00
|
|
|
node = self.children[name]
|
2004-02-08 00:35:42 +01:00
|
|
|
if hasattr(node, 'value') or hasattr(node, 'help'):
|
2004-02-03 17:43:22 +01:00
|
|
|
if node.__class__ is not self.X:
|
|
|
|
L.append((node.name, node))
|
|
|
|
if getChildren:
|
|
|
|
L.extend(node.getValues(getChildren, fullNames))
|
|
|
|
if not fullNames:
|
|
|
|
L = [(rsplit(s, '.', 1)[1], node) for (s, node) in L]
|
|
|
|
return L
|
|
|
|
|
|
|
|
|
|
|
|
class Value(Group):
|
2004-02-10 04:15:31 +01:00
|
|
|
def __init__(self, default, help, showDefault=True, **kwargs):
|
2004-02-03 17:43:22 +01:00
|
|
|
Group.__init__(self, **kwargs)
|
2004-01-18 08:58:26 +01:00
|
|
|
self.default = default
|
2004-02-10 04:15:31 +01:00
|
|
|
self.showDefault = showDefault
|
2004-01-18 08:58:26 +01:00
|
|
|
self.help = utils.normalizeWhitespace(help.strip())
|
|
|
|
self.setValue(default)
|
2004-01-13 07:07:31 +01:00
|
|
|
|
2004-02-03 17:43:22 +01:00
|
|
|
def setName(self, *args):
|
|
|
|
if self.name == 'unset':
|
|
|
|
self._lastModified = 0
|
|
|
|
Group.setName(self, *args)
|
|
|
|
self._lastModified = time.time()
|
|
|
|
|
2004-01-13 07:07:31 +01:00
|
|
|
def set(self, s):
|
|
|
|
"""Override this with a function to convert a string to whatever type
|
2004-01-20 16:08:08 +01:00
|
|
|
you want, and call self.setValue to set the value."""
|
2004-01-13 07:07:31 +01:00
|
|
|
raise NotImplementedError
|
2004-01-15 13:17:50 +01:00
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
def setValue(self, v):
|
2004-01-20 16:08:08 +01:00
|
|
|
"""Check conditions on the actual value type here. I.e., if you're a
|
|
|
|
IntegerLessThanOneHundred (all your values must be integers less than
|
|
|
|
100) convert to an integer in set() and check that the integer is less
|
2004-01-22 21:16:21 +01:00
|
|
|
than 100 in this method. You *must* call this parent method in your
|
|
|
|
own setValue."""
|
|
|
|
self._lastModified = time.time()
|
2004-01-18 08:58:26 +01:00
|
|
|
self.value = v
|
2004-02-09 17:32:00 +01:00
|
|
|
if self.supplyDefault:
|
|
|
|
for (name, v) in self.children.items():
|
|
|
|
if v.__class__ is self.X:
|
|
|
|
self.unregister(name)
|
2004-01-18 08:58:26 +01:00
|
|
|
|
2004-01-13 07:07:31 +01:00
|
|
|
def __str__(self):
|
2004-01-22 21:16:21 +01:00
|
|
|
return repr(self())
|
2004-01-13 07:07:31 +01:00
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
# This is simply prettier than naming this function get(self)
|
|
|
|
def __call__(self):
|
2004-02-03 17:43:22 +01:00
|
|
|
if _lastModified > self._lastModified:
|
2004-02-05 08:54:38 +01:00
|
|
|
if self.name in _cache:
|
|
|
|
self.set(_cache[self.name])
|
2004-01-18 08:58:26 +01:00
|
|
|
return self.value
|
2004-01-30 20:27:02 +01:00
|
|
|
|
2004-01-13 07:07:31 +01:00
|
|
|
class Boolean(Value):
|
|
|
|
def set(self, s):
|
|
|
|
s = s.lower()
|
2004-01-21 16:48:48 +01:00
|
|
|
if s in ('true', 'on', 'enable', 'enabled'):
|
2004-01-20 16:08:08 +01:00
|
|
|
value = True
|
2004-01-21 16:48:48 +01:00
|
|
|
elif s in ('false', 'off', 'disable', 'disabled'):
|
2004-01-20 16:08:08 +01:00
|
|
|
value = False
|
2004-01-18 08:58:26 +01:00
|
|
|
elif s == 'toggle':
|
2004-01-20 16:08:08 +01:00
|
|
|
value = not self.value
|
2004-01-13 07:07:31 +01:00
|
|
|
else:
|
2004-02-02 09:31:11 +01:00
|
|
|
raise InvalidRegistryValue, '%r is not True or False.' % s
|
2004-01-20 16:08:08 +01:00
|
|
|
self.setValue(value)
|
|
|
|
|
|
|
|
def setValue(self, v):
|
2004-01-22 21:16:21 +01:00
|
|
|
Value.setValue(self, bool(v))
|
2004-01-13 07:07:31 +01:00
|
|
|
|
|
|
|
class Integer(Value):
|
|
|
|
def set(self, s):
|
|
|
|
try:
|
2004-01-20 16:08:08 +01:00
|
|
|
self.setValue(int(s))
|
2004-01-13 07:07:31 +01:00
|
|
|
except ValueError:
|
2004-02-02 09:31:11 +01:00
|
|
|
raise InvalidRegistryValue, '%r is not an integer.' % s
|
2004-01-13 07:07:31 +01:00
|
|
|
|
2004-01-20 00:42:50 +01:00
|
|
|
class PositiveInteger(Value):
|
|
|
|
def set(self, s):
|
|
|
|
try:
|
2004-01-20 16:08:08 +01:00
|
|
|
self.setValue(int(s))
|
2004-01-20 00:42:50 +01:00
|
|
|
except ValueError:
|
2004-02-02 09:31:11 +01:00
|
|
|
raise InvalidRegistryValue, '%r is not a positive integer.' % s
|
2004-01-20 00:42:50 +01:00
|
|
|
|
2004-01-20 16:08:08 +01:00
|
|
|
def setValue(self, v):
|
|
|
|
if v <= 0:
|
2004-02-02 09:31:11 +01:00
|
|
|
raise InvalidRegistryValue, '%r is not a positive integer.' % v
|
2004-01-22 21:16:21 +01:00
|
|
|
Value.setValue(self, v)
|
2004-01-20 16:08:08 +01:00
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
class Float(Value):
|
|
|
|
def set(self, s):
|
|
|
|
try:
|
2004-01-20 16:08:08 +01:00
|
|
|
self.setValue(float(s))
|
2004-01-18 08:58:26 +01:00
|
|
|
except ValueError:
|
2004-02-02 09:31:11 +01:00
|
|
|
raise InvalidRegistryValue, '%r is not a float.' % s
|
2004-01-18 08:58:26 +01:00
|
|
|
|
2004-01-21 16:48:48 +01:00
|
|
|
def setValue(self, v):
|
|
|
|
try:
|
2004-01-22 21:16:21 +01:00
|
|
|
Value.setValue(self, float(v))
|
2004-01-21 16:48:48 +01:00
|
|
|
except ValueError:
|
2004-02-02 09:31:11 +01:00
|
|
|
raise InvalidRegistryValue, '%r is not a float.' % v
|
2004-01-21 16:48:48 +01:00
|
|
|
|
2004-01-13 07:07:31 +01:00
|
|
|
class String(Value):
|
|
|
|
def set(self, s):
|
2004-01-21 16:48:48 +01:00
|
|
|
if not s:
|
|
|
|
s = '""'
|
|
|
|
elif s[0] != s[-1] or s[0] not in '\'"':
|
2004-01-13 07:07:31 +01:00
|
|
|
s = repr(s)
|
|
|
|
try:
|
|
|
|
v = utils.safeEval(s)
|
2004-01-20 05:36:49 +01:00
|
|
|
if not isinstance(v, basestring):
|
2004-01-13 07:07:31 +01:00
|
|
|
raise ValueError
|
2004-02-03 19:21:19 +01:00
|
|
|
self.setValue(v)
|
2004-01-13 07:07:31 +01:00
|
|
|
except ValueError: # This catches utils.safeEval(s) errors too.
|
2004-02-02 09:31:11 +01:00
|
|
|
raise InvalidRegistryValue, '%r is not a string.' % s
|
2004-01-13 07:07:31 +01:00
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
class NormalizedString(String):
|
|
|
|
def set(self, s):
|
|
|
|
s = utils.normalizeWhitespace(s.strip())
|
|
|
|
String.set(self, s)
|
|
|
|
|
2004-01-19 21:51:04 +01:00
|
|
|
def setValue(self, s):
|
|
|
|
s = utils.normalizeWhitespace(s.strip())
|
|
|
|
String.setValue(self, s)
|
|
|
|
|
2004-01-13 07:07:31 +01:00
|
|
|
class StringSurroundedBySpaces(String):
|
|
|
|
def set(self, s):
|
|
|
|
String.set(self, s)
|
2004-01-20 16:08:08 +01:00
|
|
|
self.setValue(self.value)
|
|
|
|
|
|
|
|
def setValue(self, v):
|
|
|
|
if v.lstrip() == v:
|
2004-01-21 16:48:48 +01:00
|
|
|
v= ' ' + v
|
2004-01-20 16:08:08 +01:00
|
|
|
if v.rstrip() == v:
|
|
|
|
v += ' '
|
2004-01-22 21:16:21 +01:00
|
|
|
String.setValue(self, v)
|
2004-01-13 07:07:31 +01:00
|
|
|
|
2004-01-23 14:28:53 +01:00
|
|
|
class StringWithSpaceOnRight(String):
|
|
|
|
def setValue(self, v):
|
|
|
|
if v.rstrip() == v:
|
|
|
|
v += ' '
|
|
|
|
String.setValue(self, v)
|
2004-01-27 19:14:44 +01:00
|
|
|
|
|
|
|
class Regexp(Value):
|
|
|
|
def set(self, s):
|
|
|
|
try:
|
|
|
|
if s:
|
|
|
|
self.value = utils.perlReToPythonRe(s)
|
2004-02-03 19:21:19 +01:00
|
|
|
self._lastModified = time.time()
|
2004-01-27 19:14:44 +01:00
|
|
|
else:
|
2004-02-03 19:21:19 +01:00
|
|
|
self.setValue(None)
|
2004-01-27 19:14:44 +01:00
|
|
|
self.sr = s
|
|
|
|
except ValueError, e:
|
2004-02-02 09:31:11 +01:00
|
|
|
raise InvalidRegistryValue, '%r is not a valid regexp: %s' % (s, e)
|
2004-01-27 19:14:44 +01:00
|
|
|
|
|
|
|
def setValue(self, v):
|
|
|
|
if v is None:
|
|
|
|
self.sr = ''
|
2004-02-03 19:21:19 +01:00
|
|
|
Value.setValue(self, None)
|
2004-01-27 19:14:44 +01:00
|
|
|
else:
|
|
|
|
raise InvalidRegistryValue, \
|
|
|
|
'Can\'t set to a regexp, there would be an inconsistency ' \
|
|
|
|
'between the regexp and the recorded string value.'
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.sr
|
2004-01-23 14:28:53 +01:00
|
|
|
|
2004-01-21 17:15:31 +01:00
|
|
|
class SeparatedListOf(Value):
|
2004-01-30 23:15:39 +01:00
|
|
|
List = list
|
2004-01-21 17:15:31 +01:00
|
|
|
Value = Value
|
|
|
|
def splitter(self, s):
|
|
|
|
"""Override this with a function that takes a string and returns a list
|
|
|
|
of strings."""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def joiner(self, L):
|
|
|
|
"""Override this to join the internal list for output."""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
def set(self, s):
|
2004-01-21 17:15:31 +01:00
|
|
|
L = self.splitter(s)
|
|
|
|
for (i, s) in enumerate(L):
|
|
|
|
v = self.Value(s, 'help does not matter here')
|
|
|
|
L[i] = v()
|
|
|
|
self.setValue(L)
|
2004-01-18 08:58:26 +01:00
|
|
|
|
2004-01-27 12:25:36 +01:00
|
|
|
def setValue(self, v):
|
2004-01-30 23:15:39 +01:00
|
|
|
Value.setValue(self, self.List(v))
|
2004-01-27 12:25:36 +01:00
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
def __str__(self):
|
2004-01-21 17:15:31 +01:00
|
|
|
return self.joiner(self.value)
|
|
|
|
|
2004-01-21 18:13:04 +01:00
|
|
|
class SpaceSeparatedListOfStrings(SeparatedListOf):
|
|
|
|
Value = String
|
|
|
|
def splitter(self, s):
|
2004-01-21 20:12:51 +01:00
|
|
|
return s.split()
|
2004-01-21 18:13:04 +01:00
|
|
|
joiner = ' '.join
|
|
|
|
|
2004-01-21 17:15:31 +01:00
|
|
|
class CommaSeparatedListOfStrings(SeparatedListOf):
|
|
|
|
Value = String
|
|
|
|
def splitter(self, s):
|
|
|
|
return re.split(r'\s*,\s*', s)
|
2004-01-21 18:13:04 +01:00
|
|
|
joiner = ', '.join
|
2004-01-21 17:15:31 +01:00
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
class CommaSeparatedSetOfStrings(CommaSeparatedListOfStrings):
|
2004-01-30 23:15:39 +01:00
|
|
|
List = sets.Set
|
2004-01-13 07:07:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2004-02-03 17:43:22 +01:00
|
|
|
#if 1:
|
2004-01-18 08:58:26 +01:00
|
|
|
import sys
|
|
|
|
sys.setrecursionlimit(40)
|
2004-01-13 07:07:31 +01:00
|
|
|
supybot = Group()
|
|
|
|
supybot.setName('supybot')
|
2004-01-18 08:58:26 +01:00
|
|
|
supybot.register('throttleTime', Float(1, """Determines the minimum
|
2004-01-13 07:07:31 +01:00
|
|
|
number of seconds the bot will wait between sending messages to the server.
|
|
|
|
"""))
|
2004-02-03 17:43:22 +01:00
|
|
|
supybot.register('plugins')
|
2004-02-04 16:55:56 +01:00
|
|
|
supybot.plugins.register('Topic')
|
2004-02-03 17:43:22 +01:00
|
|
|
supybot.plugins.topic.register('separator',
|
|
|
|
StringSurroundedBySpaces(' || ', """Determines what separator the bot
|
|
|
|
uses to separate topic entries.""", supplyDefault=True))
|
2004-01-22 21:16:21 +01:00
|
|
|
supybot.plugins.topic.separator.get('#supybot').set(' |||| ')
|
2004-01-13 07:26:35 +01:00
|
|
|
supybot.plugins.topic.separator.set(' <> ')
|
2004-01-13 07:07:31 +01:00
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
supybot.throttleTime.set(10)
|
|
|
|
|
2004-02-03 17:43:22 +01:00
|
|
|
supybot.register('log')
|
|
|
|
supybot.log.register('stdout', Boolean(False, """Help for stdout."""))
|
2004-01-18 08:58:26 +01:00
|
|
|
supybot.log.stdout.register('colorized', Boolean(False,
|
|
|
|
'Help colorized'))
|
|
|
|
supybot.log.stdout.setValue(True)
|
|
|
|
|
2004-01-13 07:07:31 +01:00
|
|
|
for (k, v) in supybot.getValues():
|
|
|
|
print '%s: %s' % (k, v)
|
2004-01-13 16:56:58 +01:00
|
|
|
|
2004-01-14 07:05:58 +01:00
|
|
|
print
|
|
|
|
print 'Asking children'
|
|
|
|
print
|
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
for (k, v) in supybot.getValues(getChildren=True):
|
2004-01-14 07:05:58 +01:00
|
|
|
print '%s: %s' % (k, v)
|
|
|
|
|
2004-01-18 08:58:26 +01:00
|
|
|
print supybot.throttleTime.help
|
|
|
|
print supybot.plugins.topic.separator.help
|
2004-01-13 07:07:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
|
|
|
|