def plugin_details(server, plugin, version='', **query): '''Retreives the plugin object. Optionally a specific version can be specified. All query variables specified by the API docs will work here. ''' result = api.plugin_details(server, plugin, version=version, **query) if result is None: return None return Plugin(result)
def display_plugin(self, plugin, check=False, *opts): ''' Outputs to Screen information about the plugin. ''' opts = list(opts) conf = self.get_plugin(plugin) if check: ret = api.plugin_details(self.stype, conf['bukget']) if ret is not None: current = ret['versions'][0] for version in ret['versions']: if conf['version'] == version['version']: if current['date'] > version['date']: opts.append('Current: %s' % current['version']) print '%-20s %-10s %s' % (conf['name'], conf['version'], ', '.join(opts))
def do_scan(self, s): '''scan Scans the currently installed plugins and will add any not currently being tracked into the baskit config as well as update any version numbers for plugins that have been updated manually. ''' plugins = self.plugin_listing() for filename in os.listdir(self.plugin_path): filepath = os.path.join(self.plugin_path, filename) if 'jar' == filename[-3:].lower(): p = False for plugin in plugins: if plugin['jar'] == filename: p = plugin if p: plug = api.plugin_details(self.stype, p['bukget']) else: plugs = self.get_plugin_info(filepath) if len(plugs) == 0: print 'Plugin %s does not exist in BukGet.' % filename continue elif len(plugs) == 1: plug = plugs[0] if len(plugs) > 1: print 'Multiple Matches for %s. Please Select One (default 0)' % filename for item in plugs: print '%2d: %-30s %s' % (plugs.index(item), item['plugin_name'], item['slug']) try: plug = plugs[int(raw_input('Plugin ID : '))] except ValueError: plug = plugs[0] filehash = self.hash_file(filepath) notes = [] for version in plug['versions']: if version['md5'] == filehash: self.save_plugin(plug['plugin_name'].lower(), jar=filename, bukget=plug['slug'], md5=filehash, version=version['version'], enabled=True) if p and p['md5'] != version['md5']: notes.append('Manually Updated') self.display_plugin(plug['plugin_name'].lower(), True, *notes)
def install(self, plugin, version): ''' Installs or Updates a Plugin. ''' plug = api.plugin_details(self.stype, plugin, version) if plug == None: print 'Not a Valid BukGet Plugin Name...' return pname = plug['versions'][0]['filename'] data = api.plugin_download(self.stype, plugin, version) if pname[-3:].lower() == 'jar': with open(os.path.join(self.plugin_path, pname[:-3] + 'jar'), 'wb') as jar: jar.write(data) if pname[-3:].lower() == 'zip': dataobj = StringIO() dataobj.write(data) try: zfile = ZipFile(dataobj) except BadZipfile: print 'ERROR: Corrupt Zip File. Could Not Install' return zfile.extractall(self.plugin_path) print '\n'.join([ 'NOTE: As this plugin was bundled as a zip file, it\'s', ' impossible to determine if the plugin was installed', ' correctly. Please check the plugin installtion to be', ' sure that everything is set up correctly.']) dataobj.close() self.save_plugin(plug['plugin_name'].lower(), jar=pname[:-3] + 'jar', bukget=plug['slug'], md5=plug['versions'][0]['md5'], version=plug['versions'][0]['version'], enabled=True) print 'Plugin %s/%s installed' % (plug['plugin_name'], plug['versions'][0]['version'])