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

View File

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