def download_plugin(plugin, prefix=''): """ Download plugin. This function takes two parameters. The first is the plugin. The plugin must be a dictionary returned by bukget with at least the following fields: versions.download, plugin_name, versions.md5, versions.filename The second parameter is a prefix to print before each output line, typically a counter on which download this it. Example: ( 5/20) """ target_folder = common.find_plugins_folder() + '/' url = plugin['versions'][0]['download'] filename = common.format_name(plugin['plugin_name']) md5 = plugin['versions'][0]['md5'] suffix = plugin['versions'][0]['filename'].split('.')[-1] full_name = target_folder + filename + '.' + suffix common.download(url, destination=full_name, checksum=md5, prefix=prefix, display_name=filename) if suffix == 'zip': print(' ' * len(prefix) + 'Unzipping...', end=' ') unzip_plugin(full_name, target_folder) os.remove(full_name) print('Success')
def download(self): """ Download a server. """ self.p_main('Finding build on SpaceGDN') try: result = backend.get_builds(self.args.server, self.args.channel, self.args.version, self.args.build) if type(result) is not list: self.error(result) return if len(result) < 1: self.p_sub('Could not find any build') return channel, version, build = backend.find_latest_build(result) self.result( 'Found build:', '{} {} {} {}'.format(self.args.server, channel, version, build['build'])) if utils.ask('Continue to download?', skip=self.args.no_confirm): utils.download(build['url'], destination=self.args.output, checksum=build['checksum'], prefix=' ' * 4) self.p_blank() self.p_raw('Done!') except ValueError as error: self.p_sub(error.args[0])
def download_plugin(plugin, prefix=''): """ Download plugin. This function takes two parameters. The first is the plugin. The plugin must be a dictionary returned by bukget with at least the following fields: versions.download, plugin_name, versions.md5, versions.filename The second parameter is a prefix to print before each output line, typically a counter on which download this it. Example: ( 5/20) """ target_folder = common.find_plugins_folder() + '/' url = plugin['versions'][0]['download'] filename = common.format_name(plugin['plugin_name']) md5 = plugin['versions'][0]['md5'] suffix = plugin['versions'][0]['filename'].split('.')[-1] full_name = target_folder + filename + '.' + suffix common.download(url, destination=full_name, checksum=md5, prefix=prefix, display_name=filename) if suffix == 'zip': print(' '*len(prefix) + 'Unzipping...', end=' ') unzip_plugin(full_name, target_folder) os.remove(full_name) print('Success')
def download(self): """ Download a server. """ self.p_main("Finding build on SpaceGDN") try: result = backend.get_builds(self.args.server, self.args.channel, self.args.version, self.args.build) if type(result) is not list: self.error(result) return if len(result) < 1: self.p_sub("Could not find any build") return channel, version, build = backend.find_latest_build(result) self.result("Found build:", "{} {} {} {}".format(self.args.server, channel, version, build["build"])) if utils.ask("Continue to download?", skip=self.args.no_confirm): utils.download(build["url"], destination=self.args.output, checksum=build["checksum"], prefix=" " * 4) self.p_blank() self.p_raw("Done!") except ValueError as error: self.p_sub(error.args[0])
def test(checksum, destination=self.filename, prefix=self.prefix, display_name=self.display_name): common.download(self.url, destination=destination, checksum=checksum, prefix=prefix, display_name=display_name)
def run(self): """ Run the command. """ if self.args.input is not stdin: self.p_main('Parsing file and finding plugins and servers') document = json.loads('\n'.join(self.args.input)) plugins = document['plugins'] remote_plugins = p_backend.find_versions([ (e['slug'], e['version-slug']) for e in plugins ]) servers = document['servers'] remote_servers = s_backend.find_servers([e['id'] for e in servers]) self.parse_plugins(plugins, remote_plugins) self.parse_servers(servers, remote_servers) self.p_main('Files to download:') self.p_blank() self.p_sub(common.list_names([i[0] for i in self.to_download])) self.p_blank() if not common.ask('Do you want to continue?', skip=self.args.no_confirm): return prefix = '({{part:>{}}}/{}) '.format(len(str(len(self.to_download))), len(self.to_download)) for i in range(len(self.to_download)): jar = self.to_download[i] this_prefix = prefix.format(part=i + 1) destination = self.args.destination + '/' + jar[0] if jar[1].endswith('.zip'): destination = jar[1].split('/')[-1] common.download(jar[1], destination=destination, checksum=jar[2], prefix=this_prefix) if jar[1].endswith('.zip'): print(' ' * len(this_prefix) + "Unzipping...", end=' ') p_backend.unzip_plugin(destination, '/'.join(jar[0].split('/')[:-1]) + '/') os.remove(destination) print('Success')
def run(self): """ Run the command. """ if self.args.input is not stdin: self.p_main('Parsing file and finding plugins and servers') document = json.loads('\n'.join(self.args.input)) plugins = document['plugins'] remote_plugins = p_backend.find_versions( [(e['slug'], e['version-slug']) for e in plugins]) servers = document['servers'] remote_servers = s_backend.find_servers([e['id'] for e in servers]) self.parse_plugins(plugins, remote_plugins) self.parse_servers(servers, remote_servers) self.p_main('Files to download:') self.p_blank() self.p_sub(common.list_names([i[0] for i in self.to_download])) self.p_blank() if not common.ask('Do you want to continue?', skip=self.args.no_confirm): return prefix = '({{part:>{}}}/{}) '.format( len(str(len(self.to_download))), len(self.to_download)) for i in range(len(self.to_download)): jar = self.to_download[i] this_prefix = prefix.format(part=i+1) destination = self.args.destination + '/' + jar[0] if jar[1].endswith('.zip'): destination = jar[1].split('/')[-1] common.download(jar[1], destination=destination, checksum=jar[2], prefix=this_prefix) if jar[1].endswith('.zip'): print(' ' * len(this_prefix) + "Unzipping...", end=' ') p_backend.unzip_plugin(destination, '/'.join(jar[0].split('/')[:-1]) + '/') os.remove(destination) print('Success')