PluginDownloader: Add @info command.

This commit is contained in:
Valentin Lorentz 2012-04-29 17:55:41 +00:00
parent 99660aa4b0
commit 9cba1e4d08
2 changed files with 76 additions and 18 deletions

View File

@ -5,7 +5,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2012-04-29 19:20+EEST\n" "POT-Creation-Date: 2012-04-29 17:55+UTC\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -15,7 +15,7 @@ msgstr ""
"Generated-By: pygettext.py 1.5\n" "Generated-By: pygettext.py 1.5\n"
#: plugin.py:245 #: plugin.py:260
#, docstring #, docstring
msgid "" msgid ""
"This plugin allows you to install unofficial plugins from\n" "This plugin allows you to install unofficial plugins from\n"
@ -25,7 +25,7 @@ msgid ""
" just run command \"install <repository> <plugin>\"." " just run command \"install <repository> <plugin>\"."
msgstr "" msgstr ""
#: plugin.py:253 #: plugin.py:268
#, docstring #, docstring
msgid "" msgid ""
"[<repository>]\n" "[<repository>]\n"
@ -35,19 +35,19 @@ msgid ""
" repositories." " repositories."
msgstr "" msgstr ""
#: plugin.py:261 plugin.py:272 #: plugin.py:276 plugin.py:287
msgid ", " msgid ", "
msgstr "" msgstr ""
#: plugin.py:263 plugin.py:282 #: plugin.py:278 plugin.py:297 plugin.py:322
msgid "This repository does not exist or is not known by this bot." msgid "This repository does not exist or is not known by this bot."
msgstr "" msgstr ""
#: plugin.py:270 #: plugin.py:285
msgid "No plugin found in this repository." msgid "No plugin found in this repository."
msgstr "" msgstr ""
#: plugin.py:277 #: plugin.py:292
#, docstring #, docstring
msgid "" msgid ""
"<repository> <plugin>\n" "<repository> <plugin>\n"
@ -55,7 +55,23 @@ msgid ""
" Downloads and installs the <plugin> from the <repository>." " Downloads and installs the <plugin> from the <repository>."
msgstr "" msgstr ""
#: plugin.py:287 #: plugin.py:302 plugin.py:327
msgid "This plugin does not exist in this repository." msgid "This plugin does not exist in this repository."
msgstr "" msgstr ""
#: plugin.py:317
#, docstring
msgid ""
"<repository> <plugin>\n"
"\n"
" Displays informations on the <plugin> in the <repository>."
msgstr ""
#: plugin.py:331
msgid "No README found for this plugin"
msgstr ""
#: plugin.py:334
msgid "This plugin has no description."
msgstr ""

View File

@ -130,19 +130,24 @@ class GithubRepository(GitRepository):
# Remember we pop(0)ed the path # Remember we pop(0)ed the path
return None return None
def _download(self, plugin):
try:
fileObject = urllib2.urlopen(self._downloadUrl)
fileObject2 = StringIO()
fileObject2.write(fileObject.read())
fileObject.close()
fileObject2.seek(0)
return tarfile.open(fileobj=fileObject2, mode='r:gz')
finally:
del fileObject
def install(self, plugin): def install(self, plugin):
archive = self._download(plugin)
prefix = archive.getnames()[0]
dirname = ''.join((self._path, plugin))
directories = conf.supybot.directories.plugins() directories = conf.supybot.directories.plugins()
directory = self._getWritableDirectoryFromList(directories) directory = self._getWritableDirectoryFromList(directories)
assert directory is not None assert directory is not None
dirname = ''.join((self._path, plugin))
fileObject = urllib2.urlopen(self._downloadUrl)
fileObject2 = StringIO()
fileObject2.write(fileObject.read())
fileObject.close()
fileObject2.seek(0)
archive = tarfile.open(fileobj=fileObject2, mode='r:gz')
prefix = archive.getnames()[0]
try: try:
assert archive.getmember(prefix + dirname).isdir() assert archive.getmember(prefix + dirname).isdir()
@ -161,8 +166,18 @@ class GithubRepository(GitRepository):
open(newFileName, 'a').write(extractedFile.read()) open(newFileName, 'a').write(extractedFile.read())
finally: finally:
archive.close() archive.close()
fileObject2.close() del archive
del archive, fileObject, fileObject2
def getInfo(self, plugin):
archive = self._download(plugin)
prefix = archive.getnames()[0]
dirname = ''.join((self._path, plugin))
print repr(prefix + dirname + '/README.txt')
for file in archive.getmembers():
print repr(file)
if file.name == prefix + dirname + '/README.txt':
extractedFile = archive.extractfile(file)
return extractedFile.read()
def _getWritableDirectoryFromList(self, directories): def _getWritableDirectoryFromList(self, directories):
for directory in directories: for directory in directories:
@ -297,6 +312,33 @@ class PluginDownloader(callbacks.Plugin):
install = wrap(install, ['owner', 'something', 'something']) install = wrap(install, ['owner', 'something', 'something'])
@internationalizeDocstring
def info(self, irc, msg, args, repository, plugin):
"""<repository> <plugin>
Displays informations on the <plugin> in the <repository>."""
global repositories
if repository not in repositories:
irc.error(_(
'This repository does not exist or is not known by '
'this bot.'
))
elif plugin not in repositories[repository].getPluginList():
irc.error(_('This plugin does not exist in this repository.'))
else:
info = repositories[repository].getInfo(plugin)
if info is None:
irc.error(_('No README found for this plugin'))
else:
if info.startswith('Insert a description of your plugin here'):
irc.error(_('This plugin has no description.'))
else:
info = info.split('\n\n')[0]
for line in info.split('\n'):
if line != '':
irc.reply(line)
info = wrap(info, ['something', optional('something')])
PluginDownloader = internationalizeDocstring(PluginDownloader) PluginDownloader = internationalizeDocstring(PluginDownloader)
Class = PluginDownloader Class = PluginDownloader