*Really* fixed supybot-adduser now.

This commit is contained in:
Jeremy Fincher 2004-02-07 22:23:12 +00:00
parent 6072094207
commit 0ab86752a7
2 changed files with 29 additions and 11 deletions

View File

@ -42,6 +42,7 @@ def main():
import log
import conf
conf.supybot.log.stdout.setValue(False)
#conf.supybot.log.level.set('DEBUG')
parser = optparse.OptionParser(usage='Usage: %prog [options] <configFile>',
version='supybot %s' % conf.version)
@ -65,8 +66,9 @@ def main():
if len(args) is not 1:
parser.error('specify the configuration file you\'d like to use.')
conf.supybot.directories.conf.setValue('.')
conf.supybot.databases.users.filename.setValue(args[0])
filename = os.path.abspath(args[0])
conf.supybot.directories.conf.setValue('/')
conf.supybot.databases.users.filename.setValue(filename)
import ircdb
if not options.name:
@ -120,6 +122,9 @@ def main():
for capability in capabilities:
user.addCapability(capability)
ircdb.users.setUser(id, user)
ircdb.users.flush()
os.system('cat %s' % filename)
ircdb.users.close()
print 'User %s added.' % name
if __name__ == '__main__':

View File

@ -407,8 +407,9 @@ class Creator(object):
class IrcUserCreator(Creator):
id = None
def __init__(self):
def __init__(self, users):
self.u = IrcUser()
self.users = users
def user(self, rest, lineno):
if self.id is not None:
@ -452,13 +453,14 @@ class IrcUserCreator(Creator):
def finish(self):
if self.u.name:
users.setUser(self.id, self.u)
self.users.setUser(self.id, self.u)
IrcUserCreator.id = None
class IrcChannelCreator(Creator):
name = None
def __init__(self):
def __init__(self, channels):
self.c = IrcChannel()
self.channels = channels
self.hadChannel = bool(self.name)
def channel(self, rest, lineno):
@ -493,7 +495,7 @@ class IrcChannelCreator(Creator):
def finish(self):
if self.hadChannel:
channels.setChannel(self.name, self.c)
self.channels.setChannel(self.name, self.c)
IrcChannelCreator.name = None
@ -502,14 +504,14 @@ class UsersDictionary(utils.IterableMap):
def __init__(self):
self.filename = None
self.users = {}
self.nextId = 1
self.nextId = 0
self._nameCache = {}
self._hostmaskCache = {}
# This is separate because the Creator has to access our instance.
def open(self, filename):
self.filename = filename
reader = unpreserve.Reader(IrcUserCreator)
reader = unpreserve.Reader(IrcUserCreator, self)
reader.readFile(filename)
def reload(self):
@ -538,6 +540,12 @@ class UsersDictionary(utils.IterableMap):
else:
log.warning('UsersDictionary.flush called with no filename.')
def close(self):
self.flush()
if self.flush in world.flushers:
world.flushers.remove(self.flush)
self.users.clear()
def iteritems(self):
return self.users.iteritems()
@ -636,14 +644,13 @@ class UsersDictionary(utils.IterableMap):
def newUser(self):
"""Allocates a new user in the database and returns it and its id."""
user = IrcUser()
id = self.nextId
self.nextId += 1
id = self.nextId
self.users[id] = user
self.flush()
return (id, user)
class ChannelsDictionary(utils.IterableMap):
def __init__(self):
self.filename = None
@ -651,7 +658,7 @@ class ChannelsDictionary(utils.IterableMap):
def open(self, filename):
self.filename = filename
reader = unpreserve.Reader(IrcChannelCreator)
reader = unpreserve.Reader(IrcChannelCreator, self)
reader.readFile(filename)
def flush(self):
@ -666,6 +673,12 @@ class ChannelsDictionary(utils.IterableMap):
else:
log.warning('ChannelsDictionary.flush without self.filename.')
def close(self):
self.flush()
if self.flush in world.flushers:
world.flushers.remove(self.flush)
self.channels.clear()
def reload(self):
"""Reloads the channel database from its file."""
if self.filename is not None: