def test(): """ Main function """ locale_code, encoding = locale.getdefaultlocale() lang = gettext.translation(APP_NAME, LOCALE_DIR, [locale_code], None, True) lang.install() setup_logging() # Get packages needed for detected hardware import hardware.hardware as hardware hardware_install = hardware.HardwareInstall() hardware_pkgs = hardware_install.get_packages() print("Hardware module added these packages : ", hardware_pkgs)
def select_packages(self): """ Get package list from the Internet """ self.packages = [] packages_xml_data = None packages_xml_filename = None if len(self.alternate_package_list) > 0: # Use file passed by parameter (overrides server one) packages_xml_filename = self.alternate_package_list else: # The list of packages is retrieved from an online XML to let us # control the pkgname in case of any modification self.queue_event('info', _("Getting package list...")) try: # url = '{0}packages-{1}.xml'.format(PKGLIST_URL, info.CNCHI_VERSION.rsplit('.')[-2]) url = PKGLIST_URL logging.debug("Getting url %s...", url) req = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'}) packages_xml_data = req.content except RequestException as url_error: # If the installer can't retrieve the remote file Cnchi will use # a local copy, which might be updated or not. data_dir = self.settings.get("data") packages_xml_filename = os.path.join(data_dir, 'packages.xml') msg = "{0}. Can't retrieve remote package list, using the local file instead." msg = msg.format(url_error) if info.CNCHI_RELEASE_STAGE == "production": logging.warning(msg) else: logging.debug(msg) if packages_xml_data != None: logging.debug("Loading xml data from server...") xml_root = eTree.fromstring(packages_xml_data) else: logging.debug("Loading %s", packages_xml_filename) xml_tree = eTree.parse(packages_xml_filename) xml_root = xml_tree.getroot() for editions in xml_root.iter('editions'): for edition in editions.iter('edition'): name = edition.attrib.get("name").lower() # Add common packages to all desktops (including base) if name == "common": for pkg in edition.iter('pkgname'): self.add_package(pkg) # Add common graphical packages if name == "graphic" and self.desktop != "base": for pkg in edition.iter('pkgname'): self.add_package(pkg) # Add specific desktop packages if name == self.desktop: logging.debug("Adding %s desktop packages", self.desktop) for pkg in edition.iter('pkgname'): self.add_package(pkg) # Set KDE language pack if self.desktop == 'kde': pkg_text = "" base_name = 'kde-l10n-' lang_name = self.settings.get("language_name").lower() if lang_name == "english": # There're some English variants available but not all of them. lang_packs = ['en_gb'] locale = self.settings.get('locale').split('.')[0].lower() if locale in lang_packs: pkg_text = base_name + locale else: # All the other language packs use their language code lang_code = self.settings.get('language_code').lower() pkg_text = base_name + lang_code if pkg_text: logging.debug("Selected kde language pack: %s", pkg_text) self.packages.append(pkg_text) try: # Detect which hardware drivers are needed hardware_install = hardware.HardwareInstall( use_proprietary_graphic_drivers=self.settings.get( 'feature_graphic_drivers')) driver_names = hardware_install.get_found_driver_names() if driver_names: logging.debug("Hardware module detected these drivers: %s", driver_names) # Add needed hardware packages to our list hardware_pkgs = hardware_install.get_packages() if hardware_pkgs: logging.debug("Hardware module added these packages: %s", ", ".join(hardware_pkgs)) if 'virtualbox' in hardware_pkgs: self.vbox = True self.packages.extend(hardware_pkgs) # Add conflicting hardware packages to our conflicts list self.conflicts.extend(hardware_install.get_conflicts()) except Exception as ex: template = "Error in hardware module. An exception of type {0} occured. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) logging.error(message) # Add virtualbox-guest-utils-nox if "base" is installed in a vbox vm if self.vbox and self.desktop == "base": self.packages.append("virtualbox-guest-utils-nox") # Add linux-lts-headers if LTS kernel is installed in a vbox vm # only if not already appended if self.vbox and self.settings.get('feature_lts'): if "linux-lts-headers" not in self.packages: self.packages.append("linux-lts-headers") # Add filesystem packages logging.debug("Adding filesystem packages") for child in xml_root.iter("filesystems"): for pkg in child.iter('pkgname'): self.add_package(pkg) # Add ZFS filesystem if self.zfs: logging.debug("Adding zfs packages") for child in xml_root.iter("zfs"): for pkg in child.iter('pkgname'): self.add_package(pkg) # Add chinese fonts lang_code = self.settings.get("language_code") if lang_code in ["zh_TW", "zh_CN"]: logging.debug("Selecting chinese fonts.") for child in xml_root.iter('chinese'): for pkg in child.iter('pkgname'): self.add_package(pkg) # Add bootloader packages if needed if self.settings.get('bootloader_install'): boot_loader = self.settings.get('bootloader') # Search boot_loader in packages.xml bootloader_found = False for child in xml_root.iter('bootloader'): if child.attrib.get('name') == boot_loader: txt = _("Adding '%s' bootloader packages") logging.debug(txt, boot_loader) bootloader_found = True for pkg in child.iter('pkgname'): self.add_package(pkg) if not bootloader_found and boot_loader != 'gummiboot': txt = _("Couldn't find %s bootloader packages!") logging.warning(txt, boot_loader) # Check for user desired features and add them to our installation logging.debug( "Check for user desired features and add them to our installation") self.add_features_packages(xml_root) logging.debug("All features needed packages have been added") # Remove duplicates self.packages = list(set(self.packages)) self.conflicts = list(set(self.conflicts)) # Check the list of packages for empty strings and remove any that we find. self.packages = [pkg for pkg in self.packages if pkg != ''] self.conflicts = [pkg for pkg in self.conflicts if pkg != ''] # Remove any package from self.packages that is already in self.conflicts if self.conflicts: logging.debug("Conflicts list: %s", ", ".join(self.conflicts)) for pkg in self.packages: if pkg in self.conflicts: self.packages.remove(pkg) logging.debug("Packages list: %s", ",".join(self.packages))
log_level = logging.DEBUG logger.setLevel(log_level) # Log format formatter = logging.Formatter( '%(asctime)s - %(filename)s:%(funcName)s() - %(levelname)s: %(message)s' ) # Show log messages to stdout stream_handler = logging.StreamHandler() stream_handler.setLevel(log_level) stream_handler.setFormatter(formatter) logger.addHandler(stream_handler) if __name__ == '__main__': setup_logging() # Get packages needed for detected hardware try: import hardware.hardware as hardware hardware_install = hardware.HardwareInstall() hardware_pkgs = hardware_install.get_packages() print("Hardware module added these packages : ", hardware_pkgs) except ImportError: print("Can't import hardware module.") except Exception as err: print("Unknown error in hardware module. Output: %s" % err)
def select_packages(self): """ Get package list from the Internet """ self.packages = [] if len(self.alternate_package_list) > 0: packages_xml = self.alternate_package_list else: # The list of packages is retrieved from an online XML to let us # control the pkgname in case of any modification self.queue_event('info', _("Getting package list...")) try: url = 'http://install.antergos.com/packages-{0}.xml'.format( info.CNCHI_VERSION.rsplit('.')[-2]) logging.debug("Getting url %s...", url) req = urllib.request.Request( url, headers={'User-Agent': 'Mozilla/5.0'}) packages_xml = urllib.request.urlopen(req, timeout=10) except urllib.error.URLError as url_error: # If the installer can't retrieve the remote file Cnchi will use # a local copy, which might be updated or not. if "production" == info.CNCHI_RELEASE_STAGE: logging.warning( "%s. Can't retrieve remote package list, using the local file instead.", url_error) else: logging.debug( "%s. Can't retrieve remote package list, using the local file instead.", url_error) data_dir = self.settings.get("data") packages_xml = os.path.join(data_dir, 'packages.xml') logging.debug("Loading %s", packages_xml) xml_tree = eTree.parse(packages_xml) xml_root = xml_tree.getroot() lib = desktop_info.LIBS for editions in xml_root.iter('editions'): for edition in editions.iter('edition'): name = edition.attrib.get("name").lower() # Add common packages to all desktops (including base) if name == "common": for pkg in edition.iter('pkgname'): self.packages.append(pkg.text) # Add common graphical packages if name == "graphic" and self.desktop != "base": for pkg in edition.iter('pkgname'): # If package is Desktop Manager, save the name to activate the correct service later if pkg.attrib.get('dm'): self.desktop_manager = pkg.attrib.get('name') plib = pkg.attrib.get('lib') if plib is None or (plib is not None and self.desktop in lib[plib]): self.packages.append(pkg.text) # Add specific desktop packages if name == self.desktop: logging.debug("Adding %s desktop packages", self.desktop) for pkg in edition.iter('pkgname'): # If package is Network Manager, save the name to activate the correct service later if pkg.attrib.get('nm'): self.network_manager = pkg.attrib.get('name') # Stores conflicts packages in self.conflicts self.get_conflicts(pkg.attrib.get('conflicts')) # Finally, adds package name to our packages list self.packages.append(pkg.text) # Set KDE language pack if self.desktop == 'kde': pkg = "" base_name = 'kde-l10n-' lang_name = self.settings.get("language_name").lower() if lang_name == "english": # There're some English variants available but not all of them. lang_packs = ['en_gb'] locale = self.settings.get('locale').split('.')[0].lower() if locale in lang_packs: pkg = base_name + locale else: # All the other language packs use their language code lang_code = self.settings.get('language_code').lower() pkg = base_name + lang_code if len(pkg) > 0: logging.debug("Selected kde language pack: %s", pkg) self.packages.append(pkg) try: # Detect which hardware drivers are needed hardware_install = hardware.HardwareInstall( use_proprietary_graphic_drivers=self.settings.get( 'feature_graphic_drivers')) driver_names = hardware_install.get_found_driver_names() if len(driver_names) > 0: logging.debug("Hardware module detected these drivers: %s", driver_names) # Add needed hardware packages to our list hardware_pkgs = hardware_install.get_packages() if len(hardware_pkgs) > 0: logging.debug("Hardware module added these packages: %s", ", ".join(hardware_pkgs)) if 'virtualbox' in hardware_pkgs: self.vbox = True self.packages.extend(hardware_pkgs) # Add conflicting hardware packages to our conflicts list self.conflicts.extend(hardware_install.get_conflicts()) except Exception as general_error: logging.warning("Unknown error in hardware module. Output: %s", general_error) # Add filesystem packages logging.debug("Adding filesystem packages") for child in xml_root.iter("filesystems"): for pkg in child.iter('pkgname'): self.packages.append(pkg.text) # Add chinese fonts lang_code = self.settings.get("language_code") if lang_code == "zh_TW" or lang_code == "zh_CN": logging.debug("Selecting chinese fonts.") for child in xml_root.iter('chinese'): for pkg in child.iter('pkgname'): self.packages.append(pkg.text) # Add bootloader packages if needed if self.settings.get('bootloader_install'): boot_loader = self.settings.get('bootloader') # Search boot_loader in packages.xml bootloader_found = False for child in xml_root.iter('bootloader'): if child.attrib.get('name') == boot_loader: txt = _("Adding '%s' bootloader packages") logging.debug(txt, boot_loader) bootloader_found = True for pkg in child.iter('pkgname'): self.packages.append(pkg.text) if not bootloader_found and not 'gummiboot' == boot_loader: txt = _("Couldn't find %s bootloader packages!") logging.warning(txt, boot_loader) # Check for user desired features and add them to our installation logging.debug( "Check for user desired features and add them to our installation") self.add_features_packages(xml_root) logging.debug("All features needed packages have been added") # Remove duplicates self.packages = list(set(self.packages)) self.conflicts = list(set(self.conflicts)) # Check the list of packages for empty strings and remove any that we find. self.packages = [pkg for pkg in self.packages if pkg != ''] self.conflicts = [pkg for pkg in self.conflicts if pkg != ''] # Remove any package from self.packages that is already in self.conflicts if len(self.conflicts) > 0: logging.debug("Conflicts list: %s", ", ".join(self.conflicts)) for pkg in self.packages: if pkg in self.conflicts: self.packages.remove(pkg) logging.debug("Packages list: %s", ",".join(self.packages))