Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load the product configuration files #117

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion initial_setup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import traceback
import atexit

from initial_setup.product import eula_available
from initial_setup.product import eula_available, get_product_name
from initial_setup import initial_setup_log

from pyanaconda.core.dbus import DBus
Expand Down Expand Up @@ -103,7 +103,13 @@ def __init__(self, gui_mode):
raise InitialSetupError

# load configuration files
from pyanaconda.core.configuration.base import ConfigurationError
from pyanaconda.core.configuration.anaconda import conf
try:
conf.set_from_product(get_product_name())
except ConfigurationError as e:
log.warning(str(e))

conf.set_from_files(["/etc/initial-setup/conf.d/"])

if self.gui_mode:
Expand Down
4 changes: 2 additions & 2 deletions initial_setup/gui/gui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pyanaconda.ui.gui import QuitDialog, GraphicalUserInterface
from initial_setup.product import product_title, is_final
from initial_setup.product import get_product_title, is_final
from initial_setup.common import get_quit_message
from .hubs import InitialSetupMainHub
import os
Expand All @@ -17,7 +17,7 @@ class InitialSetupGraphicalUserInterface(GraphicalUserInterface):
screenshots_directory = "/tmp/initial-setup-screenshots"

def __init__(self):
GraphicalUserInterface.__init__(self, None, None, product_title, is_final,
GraphicalUserInterface.__init__(self, None, None, get_product_title, is_final(),
quitDialog=InitialSetupQuitDialog)
self.mainWindow.set_title("")

Expand Down
4 changes: 2 additions & 2 deletions initial_setup/gui/hubs/initial_setup_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ def _createBox(self):

# override spokes' distribution strings set by the pyanaconda module
for spoke in self._spokes.values():
spoke.window.set_property("distribution",
product.product_title().upper())
title = product.get_product_title().upper()
spoke.window.set_property("distribution", title)
73 changes: 15 additions & 58 deletions initial_setup/product.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,33 @@
"""Module providing information about the installed product."""
import logging

from pyanaconda.localization import find_best_locale_match
from pyanaconda.core.constants import DEFAULT_LANG
import os
import glob

RELEASE_STRING_FILE = "/etc/os-release"
LICENSE_FILE_GLOB = "/usr/share/redhat-release*/EULA*"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could find only /usr/share/redhat-release/EULA on the installed system.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, as far as I can tell this is the only file used these days, so should be correct. :)

from pyanaconda.core.configuration.anaconda import conf
from pyanaconda.core.util import get_os_release_value

log = logging.getLogger("initial-setup")


def product_title():
"""
Get product title.

:return: product title
:rtype: str
def get_product_name():
"""Get a product name

:return: a product name
"""
return get_os_release_value("NAME") or ""

try:
with open(RELEASE_STRING_FILE, "r") as fobj:
for line in fobj:
(key, _eq, value) = line.strip().partition("=")
if not key or not _eq or not value:
continue
if key == "PRETTY_NAME":
return value.strip('"')
except IOError:
log.exception("failed to check the release string file")

return ""
def get_product_title():
"""Get product title.

:return: a product title
"""
return get_os_release_value("PRETTY_NAME") or ""


def is_final():
"""
Whether it is a final release of the product or not.
"""Whether it is a final release of the product or not.

:rtype: bool

"""

# doesn't really matter for the Initial Setup
return True

Expand All @@ -53,39 +38,11 @@ def get_license_file_name():
:return: filename of the license file or None if no license file found
:rtype: str or None
"""

all_eulas = glob.glob(LICENSE_FILE_GLOB)
non_localized_eulas = []
langs = set()
for eula in all_eulas:
if "EULA_" in eula:
# license file for a specific locale
lang = eula.rsplit("EULA_", 1)[1]
if lang:
langs.add(lang)
else:
non_localized_eulas.append(eula)

best_lang = find_best_locale_match(os.environ["LANG"], langs)
if not best_lang:
# nothing found for the current language, try the default one
best_lang = find_best_locale_match(DEFAULT_LANG, langs)

if not best_lang:
# nothing found even for the default language, use non-localized or None
if non_localized_eulas:
best_eula = non_localized_eulas[0]
else:
return None
else:
# use first of the best-matching EULA files (there should be only one)
best_eula = glob.glob(LICENSE_FILE_GLOB + ("_%s" % best_lang))[0]

return best_eula
return conf.license.eula or None


def eula_available():
""" Report if it looks like there is an EULA available on the system.
"""Report if it looks like there is an EULA available on the system.

:return: True if an EULA seems to be available, False otherwise
:rtype: bool
Expand Down
2 changes: 1 addition & 1 deletion initial_setup/tui/hubs/initial_setup_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class InitialSetupMainHub(TUIHub):
categories = ["user", "localization"]

prod_title = product.product_title()
prod_title = product.get_product_title()
if prod_title:
title = N_("Initial setup of %(product)s") % {"product": prod_title}
else:
Expand Down
4 changes: 2 additions & 2 deletions initial_setup/tui/tui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pyanaconda.ui.tui import TextUserInterface
from pyanaconda import threading

from initial_setup.product import product_title, is_final
from initial_setup.product import get_product_title, is_final
from initial_setup.common import list_usable_consoles_for_tui, get_quit_message
from .hubs import InitialSetupMainHub

Expand Down Expand Up @@ -253,7 +253,7 @@ class InitialSetupTextUserInterface(TextUserInterface):
ENVIRONMENT = "firstboot"

def __init__(self):
TextUserInterface.__init__(self, None, None, product_title, is_final,
TextUserInterface.__init__(self, None, None, get_product_title, is_final(),
quitMessage=QUIT_MESSAGE)

# redirect stdin and stdout to custom pipes
Expand Down