Allow revision to accept wildcards.

This commit is contained in:
Jeremy Fincher 2004-08-22 15:22:17 +00:00
parent 02cd153e3d
commit 21dea0efc5

View File

@ -263,10 +263,26 @@ class Misc(callbacks.Privmsg):
Gives the latest revision of <module>. If <module> isn't given, gives Gives the latest revision of <module>. If <module> isn't given, gives
the revision of all Supybot modules. the revision of all Supybot modules.
""" """
name = privmsgs.getArgs(args, required=0, optional=1) def normalize(name):
if name:
if name.endswith('.py'): if name.endswith('.py'):
name = name[:-3] name = name[:-3]
return name
def getRevisionNumber(module):
def getVersion(s):
try:
return s.split(None, 3)[2]
except:
self.log.exception('Couldn\'t get id string: %r', s)
if hasattr(module, '__revision__'):
if 'supybot' in module.__file__:
return getVersion(module.__revision__)
else:
for dir in conf.supybot.directories.plugins():
if module.__file__.startswith(dir):
return getVersion(module.__revision__)
if len(args) == 1 and '*' not in args[0] and '?' not in args[0]:
# wildcards are handled below.
name = normalize(args[0])
try: try:
def startsWithPluginsDir(filename): def startsWithPluginsDir(filename):
for dir in conf.supybot.directories.plugins(): for dir in conf.supybot.directories.plugins():
@ -299,23 +315,26 @@ class Misc(callbacks.Privmsg):
else: else:
irc.error('Module %s has no __revision__ string.' % name) irc.error('Module %s has no __revision__ string.' % name)
else: else:
def getVersion(s): names = []
try: if not args:
return s.split(None, 3)[2] # I shouldn't use iteritems here for some reason.
except: for (name, module) in sys.modules.items():
self.log.exception('Couldn\'t get id string: %r', s) names.append((name, getRevisionNumber(module)))
names = {} elif len(args) == 1: # wildcards
dirs = map(os.path.abspath, conf.supybot.directories.plugins()) pattern = args[0]
for (name, module) in sys.modules.items(): # Don't use iteritems. for (name, module) in sys.modules.items():
if hasattr(module, '__revision__'): if ircutils.hostmaskPatternEqual(pattern, name):
if 'supybot' in module.__file__: names.append((name, getRevisionNumber(module)))
names[name] = getVersion(module.__revision__)
else: else:
for dir in conf.supybot.directories.plugins(): for name in args:
if module.__file__.startswith(dir): name = normalize(name)
names[name] = getVersion(module.__revision__) if name not in sys.modules:
break irc.error('I couldn\'t find a Supybot named %s.'%name)
L = ['%s: %s' % (k, v) for (k, v) in names.items() if v] return
module = sys.modules[name]
names.append((name, getRevisionNumber(module)))
names.sort()
L = ['%s: %s' % (k, v) for (k, v) in names if v]
irc.reply(utils.commaAndify(L)) irc.reply(utils.commaAndify(L))
def source(self, irc, msg, args): def source(self, irc, msg, args):