mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 19:22:45 +01:00
Allow revision to accept wildcards.
This commit is contained in:
parent
02cd153e3d
commit
21dea0efc5
57
src/Misc.py
57
src/Misc.py
@ -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 name in args:
|
||||||
for dir in conf.supybot.directories.plugins():
|
name = normalize(name)
|
||||||
if module.__file__.startswith(dir):
|
if name not in sys.modules:
|
||||||
names[name] = getVersion(module.__revision__)
|
irc.error('I couldn\'t find a Supybot named %s.'%name)
|
||||||
break
|
return
|
||||||
L = ['%s: %s' % (k, v) for (k, v) in names.items() if v]
|
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):
|
||||||
|
Loading…
Reference in New Issue
Block a user