def getAvailablePackages(self): try: with open(utils.INDEX_PATH) as f: data = json.load(f) for metadata in data: if metadata['name'] == "rudder-plugin-%s" % (self.name): version = rpkg.PluginVersion(metadata['version']) package = rpkg.Rpkg(metadata['name'], self.name, metadata['path'], version, metadata) self.packagesInfo.add(package) if version.mode == 'release': self.releasePackagesInfo.add(package) elif version.mode == 'nightly': self.nightlyPackagesInfo.add(package) else: utils.fail( 'Unknown release mode, found %s and expecting release or nightly' % (version.mode)) except Exception as e: logger.error( "Verify that %s is correctly configured, run `rudder package update` and retry" % (utils.CONFIG_PATH)) utils.fail("could not parse the index file %s" % (utils.INDEX_PATH)) if not len(self.packagesInfo): logger.debug('No packages were found corresponding to %s' % (self.name)) else: logger.debug("Found corresponding packages: %s" % (self.packagesInfo))
def install_file(package_files, version, exit_on_error=True): for package_file in package_files: logger.info("Installing " + package_file) # First, check if file exists if not os.path.isfile(package_file): utils.fail("Error: Package file " + package_file + " does not exist") metadata = utils.rpkg_metadata(package_file) exist = utils.package_check(metadata, version) # As dependencies are only displayed messages for now, # wait until the end to make them visible. # This should be moved before actual installation once implemented. if not utils.install_dependencies(metadata): if exit_on_error: exit(1) if exist: short_name = metadata['name'].replace("rudder-plugin-", "") # These don't have upgrade scripts for now if short_name.startswith("cis-") or short_name == "openscap": logger.info("Skipping update, this package cannot be updated") break logger.info("The package is already installed, I will upgrade it.") script_dir = utils.extract_scripts(metadata, package_file) utils.run_script("preinst", script_dir, exist, exit_on_error=exit_on_error) utils.install(metadata, package_file, exist) utils.run_script("postinst", script_dir, exist, exit_on_error=exit_on_error) if metadata['type'] == 'plugin' and 'jar-files' in metadata: for j in metadata['jar-files']: utils.jar_status(j, True)
def __init__(self, pluginLongVersion): match = re.search( r'(?P<rudderVersion>(?P<rudderMajor>[0-9]+\.[0-9]+)(\.[0-9]+(~(beta|rc)[0-9]+)?)?)-(?P<pluginShortVersion>[0-9]+\.[0-9]+)(-(?P<mode>[a-zA-Z]+))?', pluginLongVersion) if match.group('mode') is None: self.mode = 'release' elif match.group('mode') in ['SNAPSHOT', 'nightly']: self.mode = 'nightly' else: utils.fail( "The version %s does not respect the version syntax. Unknown mode found: %s" % (pluginLongVersion, match.group('mode'))) if match.group('rudderVersion') is None or match.group( 'pluginShortVersion') is None: utils.fail( "The version %s does not respect the version syntax [0-9]+.[0-9]+-[0-9]+.[0-9]+(-SNAPSHOT)?" % (pluginLongVersion)) else: self.rudderVersion = match.group('rudderVersion').replace( "~beta", "a").replace("~rc", "b") self.rudderMajor = match.group('rudderMajor') self.pluginShortVersion = match.group('pluginShortVersion') self.pluginLongVersion = pluginLongVersion self.versionToCompare = RudderVersion(self.rudderVersion + "-" + self.pluginShortVersion)
def package_install_specific_version(name, longVersion, mode="release"): pkgs = plugin.Plugin(name[0]) pkgs.getAvailablePackages() rpkg = pkgs.getRpkgByLongVersion(longVersion, mode) if rpkg is not None: rpkgPath = utils.downloadByRpkg(rpkg) install_file([rpkgPath], None) else: utils.fail("Could not find any package for %s in version %s" % (name, longVersion))
def plugin_status(plugins, status): for plugin in plugins: if status: print("Enabling " + plugin) else: print("Disabling " + plugin) if plugin not in utils.DB["plugins"]: utils.fail("Unknown plugin " + plugin) metadata = utils.DB["plugins"][plugin] if 'jar-files' in metadata: for j in metadata['jar-files']: utils.jar_status(j, status)
def package_install_latest(name, mode="release"): utils.readConf() pkgs = plugin.Plugin(name[0]) pkgs.getAvailablePackages() if mode == "release": rpkg = pkgs.getLatestCompatibleRelease() else: rpkg = pkgs.getLatestCompatibleNightly() if rpkg is not None: rpkgPath = utils.downloadByRpkg(rpkg) install_file([rpkgPath]) utils.fail("Could not find any compatible %s for %s"%(mode, name))
def package_show(name, version, mode): pkgs = plugin.Plugin(name[0]) pkgs.getAvailablePackages() if version != "": rpkg = pkgs.getRpkgByLongVersion(version, mode) else: if mode == "release": rpkg = pkgs.getLatestCompatibleRelease(None) else: rpkg = pkgs.getLatestCompatibleNightly(None) if rpkg is not None: rpkg.show_metadata() else: utils.fail("Could not find any package in %s for %s" % (mode, name))
def remove(package_names): for package_name in package_names: logger.info("Removing " + package_name) if package_name not in utils.DB["plugins"]: utils.fail("This package is not installed. Aborting!", 2) script_dir = utils.DB_DIRECTORY + "/" + package_name metadata = utils.DB["plugins"][package_name] if metadata['type'] == 'plugin' and 'jar-files' in metadata: for j in metadata['jar-files']: utils.jar_status(j, False) utils.run_script("prerm", script_dir, None) utils.remove_files(metadata) utils.run_script("postrm", script_dir, None) shutil.rmtree(script_dir) del utils.DB["plugins"][package_name] utils.db_save()
def package_install_latest(name, mode="release", version=None, exit_on_error=True): pkgs = plugin.Plugin(name[0]) pkgs.getAvailablePackages() if mode == "release": rpkg = pkgs.getLatestCompatibleRelease(version) else: rpkg = pkgs.getLatestCompatibleNightly(version) if rpkg is not None: rpkgPath = utils.downloadByRpkg(rpkg) install_file([rpkgPath], version, exit_on_error=exit_on_error) else: utils.fail("Could not find any compatible %s for %s" % (mode, name), exit_on_error=exit_on_error)
def update(): utils.readConf() logging.debug('Updating the index') utils.getRudderKey() # backup the current indexFile if it exists logging.debug("backuping %s in %s"%(utils.INDEX_PATH, utils.INDEX_PATH + ".bkp")) if os.path.isfile(utils.INDEX_PATH): os.rename(utils.INDEX_PATH, utils.INDEX_PATH + ".bkp") try: utils.download(utils.URL + "/" + "rpkg.index") except Exception as e: traceback.print_exc(file=sys.stdout) if os.path.isfile(utils.INDEX_PATH + ".bkp"): logging.debug("restoring %s from %s"%(utils.INDEX_PATH, utils.INDEX_PATH + ".bkp")) os.rename(utils.INDEX_PATH + ".bkp", utils.INDEX_PATH) utils.fail(e)
def install_file(package_files): for package_file in package_files: logging.info("Installing " + package_file) # First, check if file exists if not os.path.isfile(package_file): utils.fail("Error: Package file " + package_file + " does not exist") metadata = utils.rpkg_metadata(package_file) exist = utils.package_check(metadata) # As dependencies are only displayed messages for now, # wait until the end to make them visible. # This should be moved before actual installation once implemented. if not utils.install_dependencies(metadata): exit(1) if exist: logging.info("The package is already installed, I will upgrade it.") script_dir = utils.extract_scripts(metadata, package_file) utils.run_script("preinst", script_dir, exist) utils.install(metadata, package_file, exist) utils.run_script("postinst", script_dir, exist) if metadata['type'] == 'plugin' and 'jar-files' in metadata: for j in metadata['jar-files']: utils.jar_status(j, True)