def check_dependencies(self): from os_check import OSCheck os_family = OSCheck.get_os_family() os_version = OSCheck.get_os_major_version() is_rpm = not OSCheck.is_ubuntu_family() property_prefix = RPM_DEPENDENCIES_PROPERTY if is_rpm else DEB_DEPENDENCIES_PROPERTY cp = ConfigParser.SafeConfigParser() with open(OS_PACKAGE_DEPENDENCIES) as fp: cp.readfp(FakePropertiesHeader(fp)) properties = dict(cp.items(FakePropertiesHeader.FAKE_SECTION_NAME)) packages_string = None postfixes = [ os_family + str(ver) for ver in range(int(os_version), 0, -1) + [''] ] + [''] for postfix in postfixes: property_name = property_prefix + postfix if property_name in properties: packages_string = properties[property_name] break if packages_string is None: err_msg = "No os dependencies found. " if self.skip_dependencies: logger.warn(err_msg) else: raise Exception(err_msg) packages_string = re.sub('Requires\s*:', '', packages_string) packages_string = re.sub('\\\\n', '', packages_string) packages_string = re.sub('\s', '', packages_string) packages_string = re.sub('[()]', '', packages_string) if self.skip_dependencies: var = raw_input( "Please confirm you have the following packages installed {0} (y/n): " .format(packages_string)) if var.lower() != "y" and var.lower() != "yes": raise Exception("User canceled the installation.") return pacakges = packages_string.split(',') for package in pacakges: split_parts = re.split('[><=]', package) package_name = split_parts[0] Utils.install_package(package_name)
def check_dependencies(self): from os_check import OSCheck os_family = OSCheck.get_os_family() os_version = OSCheck.get_os_major_version() is_rpm = not OSCheck.is_ubuntu_family() property_prefix = RPM_DEPENDENCIES_PROPERTY if is_rpm else DEB_DEPENDENCIES_PROPERTY cp = ConfigParser.SafeConfigParser() with open(OS_PACKAGE_DEPENDENCIES) as fp: cp.readfp(FakePropertiesHeader(fp)) properties = dict(cp.items(FakePropertiesHeader.FAKE_SECTION_NAME)) packages_string = None postfixes = [os_family+str(ver) for ver in range(int(os_version),0,-1)+['']]+[''] for postfix in postfixes: property_name = property_prefix + postfix if property_name in properties: packages_string = properties[property_name] break if packages_string is None: err_msg = "No os dependencies found. " if self.skip_dependencies: logger.warn(err_msg) else: raise Exception(err_msg) packages_string = re.sub('Requires\s*:','',packages_string) packages_string = re.sub('\\\\n','',packages_string) packages_string = re.sub('\s','',packages_string) packages_string = re.sub('[()]','',packages_string) if self.skip_dependencies: var = raw_input("Please confirm you have the following packages installed {0} (y/n): ".format(packages_string)) if var.lower() != "y" and var.lower() != "yes": raise Exception("User canceled the installation.") return pacakges = packages_string.split(',') for package in pacakges: split_parts = re.split('[><=]', package) package_name = split_parts[0] Utils.install_package(package_name)
def resolve_address(address): """ Resolves address to proper one in special cases, for example 0.0.0.0 to 127.0.0.1 on windows os. :param address: address to resolve :return: resulting address """ if OSCheck.is_windows_family(): if address == '0.0.0.0': return '127.0.0.1' return address
def install_package(name): from os_check import OSCheck logger.info("Checking for existance of {0} dependency package".format(name)) is_rpm = not OSCheck.is_ubuntu_family() if is_rpm: is_installed_cmd = ['rpm', '-q'] + [name] install_cmd = ['sudo', 'yum', '-y', 'install'] + [name] else: is_installed_cmd = ['dpkg', '-s'] + [name] install_cmd = ['sudo', 'apt-get', '-y', 'install'] + [name] try: Utils.os_call(is_installed_cmd, logoutput=False) logger.info("Package {0} is already installed. Skipping installation.".format(name)) except OsCallFailure: logger.info("Package {0} is not installed. Installing it...".format(name)) Utils.os_call(install_cmd)