def getPluginInfo(jarFilename): if not (os.path.isfile(jarFilename) and jarFilename.endswith(".jar")): raise InvalidPluginError("JES plugins must be .jar files.") jar = JarFile(jarFilename) manifest = jar.getManifest() if manifest is None: raise InvalidPluginError("JES plugins need to have a JAR manifest " "indicating that they are for JES.") attrs = manifest.mainAttributes for attr in REQUIRED_ATTRIBUTES: if attrs.getValue(attr) is None: raise InvalidPluginError("JES plugins need to define a %s " "in their JAR manifest." % attr) entry = jar.getEntry(".JESDescription.txt") if entry is None: raise InvalidPluginError( "JES plugins need to include a description file.") inputStream = jar.getInputStream(entry) scanner = Scanner(inputStream).useDelimiter("\\A") description = scanner.next() if scanner.hasNext( ) else "(No description given.)" inputStream.close() info = { 'filename': jarFilename, 'basename': os.path.basename(jarFilename), 'dirname': os.path.dirname(jarFilename), 'title': attrs.getValue("JES-Plugin-Title"), 'version': attrs.getValue("JES-Plugin-Version"), 'description': description } info['display'] = "%s %s (%s)" % (info['title'], info['version'], info['basename']) info['longDescription'] = info['display'] + '\n' + description jar.close() return info
def extract_tools_data_from_jar_files(self): """Create tools directories from JAR files with tools data Read directories from tools/data and create jar files in tools/jar """ jarDir = File(self.jarDir) for jarFileName in jarDir.list(): toolDir = File.separator.join([self.toolsDir, jarFileName[:-4]]) self.delete_old_tool_directory(File(toolDir)) jar = JarFile(File(self.jarDir, jarFileName)) for entry in jar.entries(): f = File(File.separator.join([self.toolsDir, entry.getName()])) if entry.isDirectory(): f.mkdir() continue inputStream = jar.getInputStream(entry) fos = FileOutputStream(f) while inputStream.available() > 0: fos.write(inputStream.read()) fos.close() inputStream.close()
def extract_tools_data_from_jar_files(self): """Create tools directories from JAR files with tools data Read directories from tools/data and create jar files in tools/jar """ jarDir = File(self.jarDir) for jarFileName in jarDir.list(): toolDir = File.separator.join([self.toolsDir, jarFileName[:-4]]) self.delete_old_tool_directory(File(toolDir)) jar = JarFile(File(self.jarDir, jarFileName)) for entry in jar.entries(): f = File(File.separator.join([self.toolsDir, entry.getName()])) if entry.isDirectory(): f.mkdir() continue inputStream = jar.getInputStream(entry) fos = FileOutputStream(f) while inputStream.available() > 0: fos.write(inputStream.read()) fos.close() inputStream.close()
def getPluginInfo(jarFilename): if not (os.path.isfile(jarFilename) and jarFilename.endswith(".jar")): raise InvalidPluginError("JES plugins must be .jar files.") jar = JarFile(jarFilename) manifest = jar.getManifest() if manifest is None: raise InvalidPluginError("JES plugins need to have a JAR manifest " "indicating that they are for JES.") attrs = manifest.mainAttributes for attr in REQUIRED_ATTRIBUTES: if attrs.getValue(attr) is None: raise InvalidPluginError("JES plugins need to define a %s " "in their JAR manifest." % attr) entry = jar.getEntry(".JESDescription.txt") if entry is None: raise InvalidPluginError("JES plugins need to include a description file.") inputStream = jar.getInputStream(entry) scanner = Scanner(inputStream).useDelimiter("\\A") description = scanner.next() if scanner.hasNext() else "(No description given.)" inputStream.close() info = { 'filename': jarFilename, 'basename': os.path.basename(jarFilename), 'dirname': os.path.dirname(jarFilename), 'title': attrs.getValue("JES-Plugin-Title"), 'version': attrs.getValue("JES-Plugin-Version"), 'description': description } info['display'] = "%s %s (%s)" % (info['title'], info['version'], info['basename']) info['longDescription'] = info['display'] + '\n' + description jar.close() return info