/
eula.py
117 lines (95 loc) · 4.32 KB
/
eula.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""EULA spoke for the Initial Setup"""
import logging
from pyanaconda.ui.common import FirstbootOnlySpokeMixIn
from pyanaconda.ui.gui.spokes import NormalSpoke
from pykickstart.constants import FIRSTBOOT_RECONFIG
from initial_setup.product import eula_available, get_license_file_name
from initial_setup.common import LicensingCategory
from initial_setup.i18n import _, N_
log = logging.getLogger("initial-setup")
__all__ = ["EULASpoke"]
class EULASpoke(FirstbootOnlySpokeMixIn, NormalSpoke):
"""The EULA spoke"""
builderObjects = ["eulaBuffer", "eulaWindow"]
mainWidgetName = "eulaWindow"
uiFile = "eula.glade"
# The EULA spoke is self-explanatory, so just redirect its
# help button to the Initial Setup Hub help file,
# which covers the overall theory of Initial Setup
# usage.
helpFile = "InitialSetupHub.xml"
icon = "application-certificate-symbolic"
title = N_("_License Information")
category = LicensingCategory
translationDomain = "initial-setup"
def __init__(self, *args, **kwargs):
NormalSpoke.__init__(self, *args, **kwargs)
# workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1673071
self.title = _(self.title)
def initialize(self):
log.debug("initializing the EULA spoke")
NormalSpoke.initialize(self)
self._have_eula = True
self._eula_buffer = self.builder.get_object("eulaBuffer")
self._agree_check_button = self.builder.get_object("agreeCheckButton")
self._agree_label = self._agree_check_button.get_child()
self._agree_text = self._agree_label.get_text()
log.debug("looking for the license file")
license_file = get_license_file_name()
if not license_file:
log.error("no license found")
self._have_eula = False
self._eula_buffer.set_text(_("No license found. Please report this "
"at http://bugzilla.redhat.com"))
return
self._eula_buffer.set_text("")
itr = self._eula_buffer.get_iter_at_offset(0)
log.debug("opening the license file")
with open(license_file, "r") as fobj:
# insert the first line without prefixing with space
try:
first_line = next(fobj)
except StopIteration:
# nothing in the file
return
self._eula_buffer.insert(itr, first_line.strip())
# EULA file is preformatted for the console, we want to let Gtk
# format it (blank lines should be preserved)
for line in fobj:
stripped_line = line.strip()
if stripped_line:
self._eula_buffer.insert(itr, " " + stripped_line)
else:
self._eula_buffer.insert(itr, "\n\n")
def refresh(self):
self._agree_check_button.set_sensitive(self._have_eula)
self._agree_check_button.set_active(self.data.eula.agreed)
def apply(self):
self.data.eula.agreed = self._agree_check_button.get_active()
@property
def completed(self):
return not self._have_eula or self.data.eula.agreed
@property
def status(self):
if not self._have_eula:
return _("No license found")
return _("License accepted") if self.data.eula.agreed else _("License not accepted")
@classmethod
def should_run(cls, environment, data):
# the EULA spoke should only run if both are true:
# - we are running in Initial Setup
# - an EULA is available
if eula_available() and FirstbootOnlySpokeMixIn.should_run(environment, data):
# don't run if we are in reconfig mode and the EULA has already been accepted
if data and data.firstboot.firstboot == FIRSTBOOT_RECONFIG and data.eula.agreed:
log.debug("not running license spoke: reconfig mode & license already accepted")
return False
return True
return False
def on_check_button_toggled(self, checkbutton, *args):
if self._agree_check_button.get_active():
log.debug("license is now accepted")
self._agree_label.set_markup("<b>%s</b>" % self._agree_text)
else:
log.debug("license no longer accepted")
self._agree_label.set_markup(self._agree_text)