def parse_installed_plugins_worker(jar_queue, result_queue): """ Worker function of list_plugins. This function takes jars in the `jar_queue`, calculates the checksum, and extracts the main class, name and version and push this data to the `result_queue`. """ while not jar_queue.empty(): jar = jar_queue.get() checksum = common.checksum_file(jar) try: with ZipFile(jar, 'r') as zipped: if 'plugin.yml' not in zipped.namelist(): continue yml = yaml.load(zipped.read('plugin.yml').decode()) plugin_name = yml['name'] main = yml['main'] version = str(yml['version']) result_queue.put((checksum, main, plugin_name, version, jar)) except BadZipFile: print(" Could not read '{}'.".format(jar)) jar_queue.task_done()
def identify(self): """ Identify what server a jar file is. """ self.p_main('Calculating checksum of `{}`'.format(self.args.jar.name)) checksum = utils.checksum_file(self.args.jar) self.args.jar.close() self.p_main('Finding build on SpaceGDN') build = backend.build_by_checksum(checksum) if build is None: self.p_main('Found no build on SpaceGDN with matching checksum') return server, channel, version, build_num = backend.get_roots(build) self.p_main('Checking for updates in channel') new_version, new_build = backend.find_newest(server, channel) appendix = '' if new_build > build_num: appendix = ' -- Out of date. Newest build: {} {}'.format( new_version, new_build) self.result( 'Found build:', '{} {} {} {}'.format(server, channel, version, build_num) + appendix)
def identify(self): """ Identify what server a jar file is. """ self.p_main("Calculating checksum of `{}`".format(self.args.jar.name)) checksum = utils.checksum_file(self.args.jar) self.args.jar.close() self.p_main("Finding build on SpaceGDN") build = backend.build_by_checksum(checksum) if build is None: self.p_main("Found no build on SpaceGDN with matching checksum") return server, channel, version, build_num = backend.get_roots(build) self.p_main("Checking for updates in channel") new_version, new_build = backend.find_newest(server, channel) appendix = "" if new_build > build_num: appendix = " -- Out of date. Newest build: {} {}".format(new_version, new_build) self.result("Found build:", "{} {} {} {}".format(server, channel, version, build_num) + appendix)
def list_servers(): """ List servers in the current dir. Returned is a dictionary from jar file(relative path) to id """ files = dict() for file in os.listdir(): if not file.endswith('.jar'): continue checksum = common.checksum_file(file) build = build_by_checksum(checksum) if build is not None: files[file] = build['id'] return files
def test_path(self): """ Test with file path. """ md5 = common.checksum_file(self.path) assert md5 == self.md5
def test_file(self): """ Test with file object. """ with open(self.path, 'rb') as file: md5 = common.checksum_file(file) assert md5 == self.md5