client/rhel/rhn-client-tools/src/bin/rhnreg_ks.py | 11 + client/rhel/rhn-client-tools/src/up2date_client/rhnreg.py | 69 ++++++++++ client/rhel/rhn-client-tools/src/up2date_client/rhnregGui.py | 60 ++++++++ client/rhel/rhn-client-tools/src/up2date_client/rhnreg_constants.py | 6 client/rhel/rhn-client-tools/src/up2date_client/tui.py | 45 +++++- client/rhel/yum-rhn-plugin/rhnplugin.conf | 2 6 files changed, 185 insertions(+), 8 deletions(-)
New commits: commit 053fa0a19e21bce4eafc99fd7d2d44bd70428c14 Author: Miroslav Suchý msuchy@redhat.com Date: Fri Feb 4 12:11:57 2011 +0100
671032 - disable rhnplugin by default and enable it only after successful registration
diff --git a/client/rhel/rhn-client-tools/src/bin/rhnreg_ks.py b/client/rhel/rhn-client-tools/src/bin/rhnreg_ks.py index d732c9e..e1b6c4d 100755 --- a/client/rhel/rhn-client-tools/src/bin/rhnreg_ks.py +++ b/client/rhel/rhn-client-tools/src/bin/rhnreg_ks.py @@ -170,6 +170,17 @@ class RegisterKsCli(rhncli.RhnCli): if not self.options.norhnsd: rhnreg.startRhnsd()
+ try: + if rhnreg.YumRHNPluginPackagePresent(): + if rhnreg.YumRHNPluginConfPresent(): + if not rhnreg.YumRhnPluginEnabled(): + rhnreg.enableYumRhnPlugin() + else: + rhnreg.createDefaultYumRHNPluginConf() + else: + sys.stderr.write(_("Warning: yum-rhn-plugin is not present, could not enable it.")) + except IOError, e: + sys.stderr.write(_("Warning: Could not open /etc/yum/pluginconf.d/rhnplugin.conf\nyum-rhn-plugin is not enabled.\n") + e.errmsg) RegisterKsCli.__runRhnCheck()
@staticmethod diff --git a/client/rhel/rhn-client-tools/src/up2date_client/rhnreg.py b/client/rhel/rhn-client-tools/src/up2date_client/rhnreg.py index b8e53db..72c4f49 100644 --- a/client/rhel/rhn-client-tools/src/up2date_client/rhnreg.py +++ b/client/rhel/rhn-client-tools/src/up2date_client/rhnreg.py @@ -8,6 +8,8 @@ # Daniel Benamy dbenamy@redhat.com
import os +import re +import rpm import sys
import up2dateUtils @@ -33,6 +35,7 @@ _ = gettext.gettext
# global variables +YUM_PLUGIN_CONF = '/etc/yum/pluginconf.d/rhnplugin.conf' #SYSID_DIR = /tmp SYSID_DIR = "/etc/sysconfig/rhn" REMIND_FILE = "%s/rhn_register_remind" % SYSID_DIR @@ -631,3 +634,69 @@ def spawnRhnCheckForUI(): else: log.log_me("Warning: unable to run rhn_check")
+def enableYumRhnPlugin(): + """ enable yum-rhn-plugin by setting enabled=1 in file + /etc/yum/pluginconf.d/rhnplugin.conf + Can thrown IOError exception. + """ + f = open(YUM_PLUGIN_CONF, 'r') + lines = f.readlines() + f.close() + main_section = False + f = open(YUM_PLUGIN_CONF, 'w') + for line in lines: + if re.match("^[.*]", line): + if re.match("^[main]", line): + main_section = True + else: + main_section = False + if main_section: + line = re.sub('^(\s*)enabled\s*=.+', r'\1enabled = 1', line) + f.write(line) + f.close() + +def YumRhnPluginEnabled(): + """ Returns True if yum-rhn-plugin is enabled + Can thrown IOError exception. + """ + f = open(YUM_PLUGIN_CONF, 'r') + lines = f.readlines() + f.close() + main_section = False + result = False + for line in lines: + if re.match("^[.*]", line): + if re.match("^[main]", line): + main_section = True + else: + main_section = False + if main_section: + m = re.match('^\s*enabled\s*=\s*([0-9])', line) + if m: + if int(m.group(1)): + result = True + else: + result = False + return result + +def createDefaultYumRHNPluginConf(): + """ Create file /etc/yum/pluginconf.d/rhnplugin.conf with default values """ + f = open(YUM_PLUGIN_CONF, 'w') + f.write("""[main] +enabled = 1 +gpgcheck = 1""") + f.close() + +def YumRHNPluginConfPresent(): + """ Returns true if /etc/yum/pluginconf.d/rhnplugin.conf is presented """ + try: + os.stat(YUM_PLUGIN_CONF) + return True + except OSError: + return False + +def YumRHNPluginPackagePresent(): + """ Returns positive number if packaga yum-rhn-plugin is installed, otherwise it return 0 """ + ts = rpm.TransactionSet() + headers = ts.dbMatch('providename', 'yum-rhn-plugin') + return headers.count() diff --git a/client/rhel/rhn-client-tools/src/up2date_client/rhnregGui.py b/client/rhel/rhn-client-tools/src/up2date_client/rhnregGui.py index 7e0c63d..ab06a88 100644 --- a/client/rhel/rhn-client-tools/src/up2date_client/rhnregGui.py +++ b/client/rhel/rhn-client-tools/src/up2date_client/rhnregGui.py @@ -82,7 +82,18 @@ class ReviewLog: def __init__(self): self._text = gtk.TextBuffer() self._boldTag = self._text.create_tag(weight=700) - + + def prependBoldText(self, text): + """Adds a blob of bolded text to the beggining specified section. Adds a newline + after the text. + """ + self.prependText(text) + # Make it bold + startOfText = self._text.get_start_iter() + endOfText = self._text.get_start_iter() + endOfText.forward_chars(len(text) +1 ) + self._text.apply_tag(self._boldTag, startOfText, endOfText) + def addBoldText(self, text): """Adds a blob of bolded text to the specified section. Adds a newline after the text. @@ -94,7 +105,14 @@ class ReviewLog: startOfText.backward_chars(len(text) +1 ) end = self._text.get_end_iter() self._text.apply_tag(self._boldTag, startOfText, end) - + + def prependText(self, text): + """ Insert a blob of text at the beggining of section. Adds a newline + after the text. + """ + start = self._text.get_start_iter() + self._text.insert(start, text + '\n') + def addText(self, text): """Adds a blob of text to the specified section. Adds a newline after the text. @@ -114,7 +132,28 @@ class ReviewLog: keys = ', '.join(keyName) self.addText(rhnreg_constants.ACTIVATION_KEY % (keys)) self.addText('') # adds newline - + + def yum_plugin_warning(self): + """ Add to review screen warning that yum-rhn-plugin is not installed """ + # prepending -> reverse order + self.prependText('') # adds newline + self.prependText(rhnreg_constants.YUM_PLUGIN_WARNING) + self.prependBoldText(_("Warning")) + + def yum_plugin_conf_changed(self): + """ Add to review screen warning that yum-rhn-plugin config file has been changed """ + # prepending -> reverse order + self.prependText('') # adds newline + self.prependText(rhnreg_constants.YUM_PLUGIN_CONF_CHANGED) + self.prependBoldText(_("Notice")) + + def yum_plugin_conf_error(self): + """ Add to review screen warning that yum-rhn-plugin config file can not be open """ + # prepending -> reverse order + self.prependText('') # adds newline + self.prependText(rhnreg_constants.YUM_PLUGIN_CONF_ERROR) + self.prependBoldText(_("Warning")) + def channels(self, subscribedChannels, failedChannels): self.addBoldText(rhnreg_constants.CHANNELS_TITLE) if len(subscribedChannels) > 0: @@ -836,6 +875,21 @@ class CreateProfilePage: # no channels subscribe self.noChannels = 1
+ # enable yum-rhn-plugin + try: + if rhnreg.YumRHNPluginPackagePresent(): + if rhnreg.YumRHNPluginConfPresent(): + if not rhnreg.YumRhnPluginEnabled(): + rhnreg.enableYumRhnPlugin() + reviewLog.yum_plugin_conf_changed() + else: + rhnreg.createDefaultYumRHNPluginConf() + reviewLog.yum_plugin_conf_changed() + else: + reviewLog.yum_plugin_warning() + except IOError, e: + errorWindow(_("Could not open /etc/yum/pluginconf.d/rhnplugin.conf\nyum-rhn-plugin is not enable.\n") + e.errmsg) + reviewLog.yum_plugin_conf_error() rhnreg.spawnRhnCheckForUI() pwin.setProgress(6,6) pwin.hide() diff --git a/client/rhel/rhn-client-tools/src/up2date_client/rhnreg_constants.py b/client/rhel/rhn-client-tools/src/up2date_client/rhnreg_constants.py index c8f97d9..1199af3 100644 --- a/client/rhel/rhn-client-tools/src/up2date_client/rhnreg_constants.py +++ b/client/rhel/rhn-client-tools/src/up2date_client/rhnreg_constants.py @@ -176,6 +176,12 @@ CHANNELS_HOSTED_WARNING = _("Warning: If an installed product on this system " "product. See Kbase article 11313 " "for more details. " "(http://kbase.redhat.com/faq/docs/DOC-11313)") +YUM_PLUGIN_WARNING = _("Warning: yum-rhn-plugin is not present, could not enable it.\n" + "Automatic updates will not work.") +YUM_PLUGIN_CONF_CHANGED = _("Note: yum-rhn-plugin has been enabled.") +YUM_PLUGIN_CONF_ERROR = _("Warning: An error occurred during enabling yum-rhn-plugin.\n" + "yum-rhn-plugin is not enabled.\n" + "Automatic updates will not work.") FAILED_CHANNELS = _("You were unable to be subscribed to the following " "software channels because there were insufficient " "subscriptions available in your account:") diff --git a/client/rhel/rhn-client-tools/src/up2date_client/tui.py b/client/rhel/rhn-client-tools/src/up2date_client/tui.py index 42a6f95..2ff68e3 100644 --- a/client/rhel/rhn-client-tools/src/up2date_client/tui.py +++ b/client/rhel/rhn-client-tools/src/up2date_client/tui.py @@ -45,6 +45,12 @@ def FatalErrorWindow(screen, errmsg): [OK]) screen.finish() sys.exit(1) + +def WarningWindow(screen, errmsg): + snack.ButtonChoiceWindow(screen, WARNING, "%s" % errmsg, + [OK]) + screen.finish() +
def ConfirmQuitWindow(screen): button = snack.ButtonChoiceWindow(screen, CONFIRM_QUIT, @@ -905,7 +911,23 @@ class SendingWindow: except up2dateErrors.InsuffMgmntEntsError, e: FatalErrorWindow(self.screen, e)
- rhnreg.spawnRhnCheckForUI() + # enable yum-rhn-plugin + try: + if rhnreg.YumRHNPluginPackagePresent(): + if rhnreg.YumRHNPluginConfPresent(): + if not rhnreg.YumRhnPluginEnabled(): + rhnreg.enableYumRhnPlugin() + self.tui.yum_plugin_conf_changed = 1 + else: + rhnreg.createDefaultYumRHNPluginConf() + self.tui.yum_plugin_conf_changed = 1 + else: + self.tui.yum_plugin_present = 0 + except IOError, e: + WarningWindow(self.screen, _("Could not open /etc/yum/pluginconf.d/rhnplugin.conf\nyum-rhn-plugin is not enabled.\n") + e.errmsg) + self.tui.yum_plugin_conf_error = 1 + + rhnreg.spawnRhnCheckForUI() self.setScale(4, 4)
# Pop the pwin (Progress bar window) @@ -969,9 +991,17 @@ class ReviewWindow: size = snack._snack.size()
toplevel = snack.GridForm(screen, REVIEW_WINDOW, 1, 2) - + review_window_text = '' + + if not self.tui.yum_plugin_present: + review_window_text += YUM_PLUGIN_WARNING + "\n\n" + if self.tui.yum_plugin_conf_error: + review_window_text += YUM_PLUGIN_CONF_ERROR + "\n\n" + if self.tui.yum_plugin_conf_changed: + review_window_text += YUM_PLUGIN_CONF_CHANGED + "\n\n" + # Build up the review_window_text based on the data in self.reg_info - review_window_text = REVIEW_WINDOW_PROMPT + "\n\n" + review_window_text += REVIEW_WINDOW_PROMPT + "\n\n"
# Create and add the text for what channels the system was # subscribed to. @@ -1039,7 +1069,11 @@ class ReviewWindow: button = self.bb.buttonPressed(result)
if result == "F12": - return "next" + button = "next" + if not self.tui.yum_plugin_present: + button = "exit" + if self.tui.yum_plugin_conf_error: + button = "exit"
return button
@@ -1125,6 +1159,9 @@ class Tui: self.includePackages = 0 self.packageList = [] self.selectedPackages = [] + self.yum_plugin_present = 1 + self.yum_plugin_conf_error = 0 + self.yum_plugin_conf_changed = 0
def run(self): log.log_debug("Running %s" % self.__class__.__name__) diff --git a/client/rhel/yum-rhn-plugin/rhnplugin.conf b/client/rhel/yum-rhn-plugin/rhnplugin.conf index d50adca..076aa38 100644 --- a/client/rhel/yum-rhn-plugin/rhnplugin.conf +++ b/client/rhel/yum-rhn-plugin/rhnplugin.conf @@ -1,5 +1,5 @@ [main] -enabled = 1 +enabled = 0 gpgcheck = 1
# You can specify options per channel, e.g.:
spacewalk-commits@lists.fedorahosted.org