Package up2date_client :: Module rhnregGui
[hide private]
[frames] | no frames]

Source Code for Module up2date_client.rhnregGui

   1  # 
   2  # Copyright (c) 1999--2016 Red Hat, Inc. 
   3  # 
   4  # This software is licensed to you under the GNU General Public License, 
   5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
   6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
   7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
   8  # along with this software; if not, see 
   9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
  10  # 
  11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
  12  # granted to use or replicate Red Hat trademarks that are incorporated 
  13  # in this software or its documentation. 
  14  # 
  15  # In addition, as a special exception, the copyright holders give 
  16  # permission to link the code of portions of this program with the 
  17  # OpenSSL library under certain conditions as described in each 
  18  # individual source file, and distribute linked combinations 
  19  # including the two. 
  20  # You must obey the GNU General Public License in all respects 
  21  # for all of the code used other than OpenSSL.  If you modify 
  22  # file(s) with this exception, you may extend this exception to your 
  23  # version of the file(s), but you are not obligated to do so.  If you 
  24  # do not wish to do so, delete this exception statement from your 
  25  # version.  If you delete this exception statement from all source 
  26  # files in the program, then also delete it here. 
  27   
  28   
  29   
  30  # this is a module containing classes for the registration related windows in 
  31  # gui.py. The code is split up so we can reuse it in the firstboot modules 
  32  """ 
  33  Explanation of the RHN registration gui and how it is used from both 
  34  rhn_register and firstboot (from alikins): 
  35  Most of the "work" happens in rhnregGui.py. Thats where the 
  36  logic for the screens is. 
  37  gui.py has Gui which is the big monster class (using druid) that makes up the 
  38  main gui wizard for up2date/rhn_register. Gui implements showing the pages for 
  39  up2date/rhn_register. For up2date/rhnreg, it has methods that load the classes 
  40  from rhnregGui (by multiple inheritance...), but it's not too bad, it's all 
  41  mixin stuff, nothing wacky, no overridden methods or anything. 
  42  firstboot/* does more or less the same thing, but with a different style of 
  43  wrapper just to present the firstboot style api's. (Each "page" in firstboot is 
  44  a module with a class that inherits FirstBootGuiWindow.) 
  45  """ 
  46   
  47  import sys 
  48  import os 
  49  import gettext 
  50  t = gettext.translation('rhn-client-tools', fallback=True) 
  51  # Python 3 translations don't have a ugettext method 
  52  if not hasattr(t, 'ugettext'): 
  53      t.ugettext = t.gettext 
  54  _ = t.ugettext 
  55   
  56  from up2date_client import rhnreg 
  57  from up2date_client.rhnreg import ActivationResult 
  58  from up2date_client import up2dateErrors 
  59  from up2date_client import hardware 
  60  from up2date_client import messageWindow 
  61  from up2date_client import progress 
  62  from up2date_client import pkgUtils 
  63  from up2date_client import up2dateAuth 
  64  from up2date_client import up2dateUtils 
  65  from up2date_client import config 
  66  import OpenSSL 
  67  from up2date_client import up2dateLog 
  68  from rhn import rpclib 
  69  from rhn.connections import idn_puny_to_unicode 
  70  from up2date_client import rhnreg_constants 
  71  from up2date_client.pmPlugin import PM_PLUGIN_NAME, PM_PLUGIN_CONF 
  72  from up2date_client.gtk_compat import gtk, gobject 
  73   
  74  try: # python2 
  75      import urlparse 
  76  except ImportError: # python3 
  77      import urllib.parse as urlparse 
  78   
  79  cfg = config.initUp2dateConfig() 
  80  log = up2dateLog.initLog() 
  81   
  82  gladefile = "/usr/share/rhn/up2date_client/rh_register.glade" 
  83   
  84  # we need to carry these values between screen, so stash at module scope 
  85  username = None 
  86  password = None 
  87  productInfo = None 
  88  hw_activation_code = None 
  89  serverType = None 
  90  chosen_channel = None 
  91   
  92  # _hasBaseChannelAndUpdates gets set by the code in create profile which 
  93  # registers the system and used by hasBaseChannelAndUpdates() 
  94  _hasBaseChannelAndUpdates = False 
  95  _autoActivatedNumbers = False # used by autoActivateNumbersOnce() 
  96   
97 -class ReviewLog:
98 - def __init__(self):
99 self._text = gtk.TextBuffer() 100 self._boldTag = self._text.create_tag(weight=700)
101
102 - def prependBoldText(self, text):
103 """Adds a blob of bolded text to the beggining specified section. Adds a newline 104 after the text. 105 """ 106 self.prependText(text) 107 # Make it bold 108 startOfText = self._text.get_start_iter() 109 endOfText = self._text.get_start_iter() 110 endOfText.forward_chars(len(text) +1 ) 111 self._text.apply_tag(self._boldTag, startOfText, endOfText)
112
113 - def addBoldText(self, text):
114 """Adds a blob of bolded text to the specified section. Adds a newline 115 after the text. 116 117 """ 118 self.addText(text) 119 # Make it bold 120 startOfText = self._text.get_end_iter() 121 startOfText.backward_chars(len(text) +1 ) 122 end = self._text.get_end_iter() 123 self._text.apply_tag(self._boldTag, startOfText, end)
124
125 - def prependText(self, text):
126 """ Insert a blob of text at the beggining of section. Adds a newline 127 after the text. 128 """ 129 start = self._text.get_start_iter() 130 self._text.insert(start, text + '\n')
131
132 - def addText(self, text):
133 """Adds a blob of text to the specified section. Adds a newline after 134 the text. 135 136 """ 137 end = self._text.get_end_iter() 138 self._text.insert(end, text + '\n')
139
140 - def addBulletedText(self, text):
141 self.addText(u'\u2022' + ' ' + text)
142
143 - def getTextBuffer(self):
144 return self._text
145
146 - def usedUniversalActivationKey(self, keyName):
147 self.addBoldText(_("Notice")) 148 keys = ', '.join(keyName) 149 self.addText(rhnreg_constants.ACTIVATION_KEY % (keys)) 150 self.addText('') # adds newline
151
152 - def pm_plugin_warning(self):
153 """ Add to review screen warning that plugin is not installed """ 154 # prepending -> reverse order 155 self.prependText('') # adds newline 156 self.prependText(rhnreg_constants.PM_PLUGIN_WARNING) 157 self.prependBoldText(_("Warning"))
158
159 - def pm_plugin_conf_changed(self):
160 """ Add to review screen warning that plugin config file has been changed """ 161 # prepending -> reverse order 162 self.prependText('') # adds newline 163 self.prependText(rhnreg_constants.PM_PLUGIN_CONF_CHANGED) 164 self.prependBoldText(_("Notice"))
165
166 - def pm_plugin_conf_error(self):
167 """ Add to review screen warning that plugin config file can not be open """ 168 # prepending -> reverse order 169 self.prependText('') # adds newline 170 self.prependText(rhnreg_constants.PM_PLUGIN_CONF_ERROR) 171 self.prependBoldText(_("Warning"))
172
173 - def channels(self, subscribedChannels, failedChannels):
174 self.addBoldText(rhnreg_constants.CHANNELS_TITLE) 175 if len(subscribedChannels) > 0: 176 self.addText(rhnreg_constants.OK_CHANNELS) 177 for channel in subscribedChannels: 178 self.addBulletedText(channel) 179 180 self.addText(rhnreg_constants.CHANNELS_SAT_WARNING) 181 else: 182 self.addText(rhnreg_constants.NO_BASE_CHANNEL) 183 if len(failedChannels) > 0: 184 self.addText(rhnreg_constants.FAILED_CHANNELS) 185 for channel in failedChannels: 186 self.addBulletedText(channel) 187 self.addText('') # adds newline
188
189 - def systemSlots(self, slots, failedSlots):
190 self.addBoldText(rhnreg_constants.SLOTS_TITLE) 191 self.addText(rhnreg_constants.OK_SLOTS) 192 if len(slots) > 0: 193 for slot in slots: 194 self.addBulletedText(slot) 195 else: 196 self.addText(rhnreg_constants.NO_SYS_ENTITLEMENT) 197 if len(failedSlots) > 0: 198 self.addText(rhnreg_constants.FAILED_SLOTS) 199 for slot in failedSlots: 200 self.addBulletedText(slot) 201 self.addText('') # adds newline
202 203 reviewLog = ReviewLog() 204 205
206 -class StartPage:
207 """There is a section of this page which asks if the user wants to register, 208 which will only be shown in firstboot. This is specified by the arg to the 209 constructor. 210 211 """
212 - def __init__(self, firstboot=False):
213 self.startXml = gtk.glade.XML(gladefile, "startWindowVbox", 214 domain="rhn-client-tools") 215 self.startXml.signal_autoconnect({ 216 "onWhyRegisterButtonClicked" : self.startPageWhyRegisterButton, 217 "onMoreInfoButtonClicked" : self.startPageMoreInfoButton, 218 }) 219 self.registerNowButton = self.startXml.get_widget("registerNowButton") 220 if not firstboot: 221 startWindowVbox = self.startXml.get_widget("startWindowVbox") 222 chooseToRegisterVbox = self.startXml.get_widget('chooseToRegisterVbox') 223 startWindowVbox.remove(chooseToRegisterVbox)
224
225 - def startPageVbox(self):
226 return self.startXml.get_widget("startWindowVbox")
227
228 - def startPageWhyRegisterButton(self, button):
230
231 - def startPageMoreInfoButton(self, button):
233
234 - def startPageRegisterNow(self):
235 """Returns True if the user has selected to register now. False if 236 they've selected to register later. 237 """ 238 return self.registerNowButton.get_active()
239 240
241 -class ChooseServerPage:
242 - def __init__(self):
243 self.chooseServerXml = gtk.glade.XML(gladefile, 244 "chooseServerWindowVbox", 245 domain="rhn-client-tools") 246 self.chooseServerXml.signal_autoconnect ({ 247 "onAdvancedNetworkConfigurationButtonClicked" : self.showNetworkConfigDialog 248 }) 249 self.customServerEntry = self.chooseServerXml.get_widget('satelliteServerEntry') 250 251 self.customServerBox = self.chooseServerXml.get_widget('customServerTable')
252
253 - def chooseServerPagePrepare(self):
254 self.server = config.getServerlURL()[0] 255 log.log_debug("server is %s" % self.server) 256 self.customServerEntry.set_text(self.server)
257
258 - def chooseServerPageVbox(self):
259 return self.chooseServerXml.get_widget("chooseServerWindowVbox")
260
261 - def showNetworkConfigDialog(self, button):
263
264 - def chooseServerPageApply(self):
265 """Returns True if an error happened so we shouldn't advance to the next 266 screen, but it was already dealt with. False if everything is peachy. 267 Can raise an SSLCertificateVerifyFailedError. 268 """ 269 status = callAndFilterExceptions( 270 self._chooseServerPageApply, 271 [up2dateErrors.SSLCertificateVerifyFailedError, up2dateErrors.SSLCertificateFileNotFound], 272 _("There was an error while applying your choice.") 273 ) 274 if status is False: 275 return False 276 else: 277 return True
278
279 - def _chooseServerPageApply(self):
280 """Returns True if an error happened so we shouldn't advance to the next 281 screen, but it was already dealt with. False if everything is peachy. 282 Can probably raise all sorts of exceptions, but I wish it only raised 283 SSLCertificateVerifyFailedError. 284 """ 285 global serverType 286 up2dateConfig = config.initUp2dateConfig() 287 customServer = self.customServerEntry.get_text() 288 try: 289 customServer = rhnreg.makeNiceServerUrl(customServer) 290 except up2dateErrors.InvalidProtocolError: 291 errorWindow(_('You specified an invalid protocol. Only ' 292 'https and http are allowed.')) 293 return True 294 295 # If they changed the value, write it back to the config file. 296 if customServer != self.server: 297 config.setServerURL(customServer) 298 self.server = customServer 299 if not cfg['sslCACert']: 300 up2dateConfig.set('sslCACert', 301 '/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT') 302 303 serverType = rhnreg.getServerType() 304 305 NEED_SERVER_MESSAGE = _("You will not be able to successfully register " 306 "this system without contacting a Spacewalk server.") 307 308 # Try to contact the server to see if we have a good cert 309 try: 310 setBusyCursor() 311 # get the caps info before we show the activastion page which needs the 312 # caps. _but_ we need to do this after we configure the network... 313 rhnreg.getCaps() 314 setArrowCursor() 315 except up2dateErrors.SSLCertificateVerifyFailedError: 316 setArrowCursor() 317 raise 318 except up2dateErrors.SSLCertificateFileNotFound: 319 setArrowCursor() 320 raise 321 except up2dateErrors.CommunicationError: 322 setArrowCursor() 323 log.log_exception(*sys.exc_info()) 324 protocol, host, path, parameters, query, fragmentIdentifier = urlparse.urlparse(config.getServerlURL()[0]) 325 dialog = messageWindow.BulletedOkDialog(_("Cannot contact selected server")) 326 dialog.add_text(_("We could not contact the Satellite or Proxy " 327 "at '%s.'") % host) 328 dialog.add_bullet(_("Double-check the location - is '%s' " 329 "correct? If not, you can correct it and " 330 "try again.") % host) 331 dialog.add_bullet(_("Make sure the network connection on this " 332 "system is operational.")) 333 dialog.add_text(NEED_SERVER_MESSAGE) 334 dialog.run() 335 return True 336 except up2dateErrors.RhnServerException: 337 setArrowCursor() 338 log.log_exception(*sys.exc_info()) 339 dialog = messageWindow.BulletedOkDialog() 340 341 dialog.add_text(_("There was an error communicating with Spacewalk server.")) 342 dialog.add_bullet(_("The server may be in outage mode. You may have to try " 343 "connecting later.")) 344 dialog.add_bullet(_("You may be running a client that is incompatible with " 345 "the server.")) 346 347 dialog.add_text(NEED_SERVER_MESSAGE) 348 dialog.run() 349 return True 350 351 return False
352 353
354 -class LoginPage:
355 - def __init__(self):
356 # Derived classes must implement a function called goToPageAfterLogin 357 # which the create account dialog will use. 358 assert hasattr(self, "goToPageAfterLogin"), \ 359 "LoginPage must be derived from, by a class that implements goToPageAfterLogin." 360 self.loginXml = gtk.glade.XML(gladefile, 361 "initialLoginWindowVbox", domain="rhn-client-tools") 362 self.loginXml.signal_autoconnect ({ 363 "onLoginUserEntryActivate" : self.loginPageAccountInfoActivate, 364 "onLoginPasswordEntryActivate" : self.loginPageAccountInfoActivate, 365 }) 366 instructionsLabel = self.loginXml.get_widget('instructionsLabel') 367 self.loginPageHostedLabelText = instructionsLabel.get_label()
368
369 - def loginPagePrepare(self):
370 """Changes the screen slightly for satellite. 371 """ 372 assert serverType in ['satellite'] 373 instructionsLabel = self.loginXml.get_widget('instructionsLabel') 374 tipIconSatellite = self.loginXml.get_widget('tipIconSatellite') 375 server = config.getServerlURL()[0] 376 protocol, host, path, parameters, query, fragmentIdentifier = urlparse.urlparse(server) 377 satelliteText = _("Please enter your account information for the <b>%s</b> Spacewalk server:") % ("\n" + host) 378 instructionsLabel.set_label(satelliteText)
379 #forgotInfoSatellite.show() 380 #tipIconSatellite.show() 381
382 - def loginPageVbox(self):
383 return self.loginXml.get_widget("initialLoginWindowVbox")
384
385 - def loginPageAccountInfoActivate(self, entry):
386 """Handles activation (hitting enter) in the username and password fields. 387 388 If a password was entered or the focus is already in the password field, 389 tries to advance the screen if possible. If focus in elsewhere and 390 nothing is in the password field, puts the focus in there. 391 392 """ 393 passwordEntry = self.loginXml.get_widget("loginPasswordEntry") 394 if entry == passwordEntry or len(passwordEntry.get_text()) > 0: 395 # Automatically advance on enter if possible 396 if hasattr(self, "onLoginPageNext"): 397 self.onLoginPageNext(None, None) 398 else: 399 passwordEntry.grab_focus()
400
401 - def loginPageVerify(self):
402 """Returns True if there's an error with the user input, False 403 otherwise. 404 """ 405 self.loginPw = self.loginXml.get_widget("loginPasswordEntry") 406 self.loginUname = self.loginXml.get_widget("loginUserEntry") 407 408 global username, password 409 username = self.loginUname.get_text() 410 password = self.loginPw.get_text() 411 412 # validate / check user name 413 if self.loginUname.get_text() == "": 414 # we assume someone else creates this method... 415 setArrowCursor() 416 errorWindow(_("You must enter a login.")) 417 self.loginUname.grab_focus() 418 return True 419 420 if self.loginPw.get_text() == "": 421 setArrowCursor() 422 errorWindow(_("You must enter a password.")) 423 self.loginPw.grab_focus() 424 return True 425 426 return False
427
428 - def loginPageApply(self):
429 """Returns True if an error happened (the user will have gotten an error 430 message) or False if everything was ok. 431 """ 432 status = callAndFilterExceptions( 433 self._loginPageApply, 434 [], 435 _("There was an error while logging in.") 436 ) 437 if status is False: 438 return False 439 else: 440 return True
441
442 - def _loginPageApply(self):
443 """Returns False if everything's ok, True if there was a problem.""" 444 try: 445 setBusyCursor() 446 self.alreadyRegistered = 1 447 self.alreadyRegistered = rhnreg.reserveUser(self.loginUname.get_text(), 448 self.loginPw.get_text()) 449 except up2dateErrors.ValidationError: 450 e = sys.exc_info()[1] 451 setArrowCursor() 452 self.alreadyRegistered = 0 453 log.log_me("An exception was raised causing login to fail. This is " 454 "usually correct. Exception information:") 455 log.log_exception(*sys.exc_info()) 456 errorWindow(e.errmsg) 457 return True 458 except up2dateErrors.CommunicationError: 459 e = sys.exc_info()[1] 460 setArrowCursor() 461 print(e.errmsg) 462 self.fatalError(_("There was an error communicating with the registration server. The message was:\n") + e.errmsg) 463 return True # fatalError in firstboot will return to here 464 465 setArrowCursor() 466 return False
467 468
469 -class ReviewSubscriptionPage:
470 - def __init__(self):
471 self.reviewSubscriptionXml = gtk.glade.XML(gladefile, 472 "reviewSubscriptionWindowVbox", 473 domain="rhn-client-tools") 474 self.reviewTextView = \ 475 self.reviewSubscriptionXml.get_widget("reviewTextView")
476
478 self.reviewTextView.set_buffer(reviewLog.getTextBuffer())
479
480 - def reviewSubscriptionPageVbox(self):
481 return self.reviewSubscriptionXml.get_widget("reviewSubscriptionWindowVbox")
482 483
484 -class ConfirmAllUpdatesDialog:
485 - def __init__(self):
486 self.xml = gtk.glade.XML(gladefile, "confirmAllUpdatesDialog", 487 domain="rhn-client-tools") 488 self.dialog = self.xml.get_widget("confirmAllUpdatesDialog") 489 490 self.rc = self.dialog.run() 491 if self.rc != 1: 492 self.rc = 0 493 self.dialog.destroy()
494 495
496 -class ChooseChannelPage:
497 - def __init__(self):
498 self.chooseChannelXml = gtk.glade.XML(gladefile, 499 "chooseChannelWindowVbox", 500 domain = "rhn-client-tools") 501 self.chooseChannelList = self.chooseChannelXml.get_widget("chooseChannelList") 502 self.chooseChannelList.appears_as_list = True 503 self.limited_updates_button = self.chooseChannelXml.get_widget("limited_updates_button") 504 self.all_updates_button = self.chooseChannelXml.get_widget("all_updates_button") 505 self.chose_all_updates = False 506 self.chose_default_channel = True
507
508 - def chooseChannelPageVbox(self):
509 return self.chooseChannelXml.get_widget("chooseChannelWindowVbox")
510
511 - def channel_changed_cb(self, combobox):
512 self.limited_updates_button.set_active(True)
513
514 - def chooseChannelPagePrepare(self):
515 516 global username, password 517 518 # The self.eus_channels was populated in chooseChannelShouldBeShown 519 520 self.channels = self.eus_channels['channels'] 521 self.receiving_updates = self.eus_channels['receiving_updates'] 522 523 list_entry = gtk.ListStore(gobject.TYPE_STRING) 524 self.chooseChannelList.set_model(list_entry) 525 cell = gtk.CellRendererText() 526 self.chooseChannelList.pack_start(cell, False) 527 528 self.chooseChannelList.connect('changed', self.channel_changed_cb) 529 530 if hasattr(self.chooseChannelList, 'remove_text'): 531 self.chooseChannelList.remove_text(0) 532 else: 533 self.chooseChannelList.remove(0) 534 535 for label, name in self.channels.items(): 536 if label in self.receiving_updates: 537 self.channels[label] = name + ' *' 538 539 channel_values = list(self.channels.values()) 540 channel_values.sort() 541 for name in channel_values: 542 self.chooseChannelList.append_text(name) 543 544 self.chooseChannelList.set_active(0) 545 self.all_updates_button.set_active(True) 546 547 setArrowCursor()
548
549 - def chooseChannelPageApply(self):
550 if self.limited_updates_button.get_active(): 551 global chosen_channel 552 self.chose_all_updates = False 553 # Save the label of the chosen channel 554 for key, value in self.channels.items(): 555 if value == self.chooseChannelList.get_active_text(): 556 chosen_channel = key 557 558 if chosen_channel != self.eus_channels['default_channel']: 559 self.chose_default_channel = False 560 else: 561 self.chose_default_channel = True 562 563 return True 564 else: 565 self.chose_all_updates = True
566
567 - def chooseChannelShouldBeShown(self):
568 ''' 569 Returns True if the choose channel window should be shown, else 570 returns False. 571 ''' 572 # does the server support eus? 573 if rhnreg.server_supports_eus(): 574 575 global username, password 576 577 self.eus_channels = rhnreg.getAvailableChannels(username, password) 578 579 if len(self.eus_channels['channels']) > 0: 580 return True 581 else: 582 return False
583 584
585 -class CreateProfilePage:
586 - def __init__(self):
587 self.createProfileXml = gtk.glade.XML(gladefile, 588 "createProfileWindowVbox", 589 domain="rhn-client-tools") 590 self.createProfileXml.signal_autoconnect({ 591 "onViewHardwareButtonClicked" : self.createProfilePageShowHardwareDialog, 592 "onViewPackageListButtonClicked" : self.createProfilePageShowPackageDialog 593 }) 594 self.initProfile = None # TODO Is this still needed? 595 self.activationNoPackages = None # used by fb 596 self.noChannels = None # used by fb 597 self.serviceNotEnabled = None # used by fb
598
599 - def createProfilePagePrepare(self):
600 callAndFilterExceptions( 601 self._createProfilePagePrepare, 602 [], 603 _("There was an error while assembling information for the profile.") 604 )
605
606 - def _createProfilePagePrepare(self):
607 # There was a comment by these calls that said "part of fix for #144704" 608 # I don't understand how the code fixed that bug. It might be that 609 # they had originally been run at screen initialization which would 610 # break stuff and it was changed to only run them when the user got 611 # to this screen. 612 self.getHardware() 613 self.populateProfile()
614
615 - def createProfilePageVbox(self):
616 return self.createProfileXml.get_widget("createProfileWindowVbox")
617 618 # we cant do this on module load because there might be a valid interface 619 # but zero connectivity
620 - def getHardware(self):
621 try: 622 self.hardware = hardware.Hardware() 623 except: 624 print(_("Error running hardware profile"))
625
626 - def populateProfile(self):
627 try: 628 if not self.initProfile: 629 profileName = None 630 hostname = None 631 ipaddr = None 632 ip6addr = None 633 if self.hardware: 634 for hw in self.hardware: 635 if 'class' in hw: 636 if hw['class'] == 'NETINFO': 637 hostname = hw.get('hostname') 638 ipaddr = hw.get('ipaddr') 639 ip6addr = hw.get('ip6addr') 640 # the check against "unknown" is a bit lame, but it's 641 # the minimal change to fix #144704 642 if hostname and (hostname != "unknown"): 643 profileName = hostname 644 elif ipaddr: 645 profileName = ipaddr 646 elif ip6addr: 647 profileName = ip6addr 648 649 if profileName: 650 self.createProfileXml.get_widget("systemNameEntry").set_text(profileName) 651 else: 652 profileName = "unknown" 653 self.initProfile = True 654 except: 655 unexpectedError(_("There was an error while populating the profile."), sys.exc_info()) 656 setArrowCursor()
657
658 - def createProfilePageShowHardwareDialog(self, button):
660
661 - def createProfilePageShowPackageDialog(self, button):
663
664 - def createProfilePageVerify(self):
665 """Returns True if an error happened (the user will have gotten an error 666 message) or False if everything was ok. 667 668 """ 669 systemNameEntry = self.createProfileXml.get_widget("systemNameEntry") 670 sendHardwareButton = self.createProfileXml.get_widget("sendHardwareButton") 671 sendPackageListButton = self.createProfileXml.get_widget("sendPackageListButton") 672 self.sendHardware = sendHardwareButton.get_active() 673 self.sendPackages = sendPackageListButton.get_active() 674 if systemNameEntry.get_text() == "": 675 errorWindow(_("You must choose a name for this profile.")) 676 systemNameEntry.grab_focus() 677 return True 678 if not self.sendPackages: 679 self.activationNoPackages = 1 680 return False
681
682 - def createProfilePageApply(self):
683 """Returns True if an error happened (the user will have gotten an error 684 message) or False if everything was ok. 685 """ 686 status = callAndFilterExceptions( 687 self._createProfilePageApply, 688 [], 689 _("There was an error while creating the profile.") 690 ) 691 if status is False: 692 return False 693 else: 694 return True
695
696 - def _createProfilePageApply(self):
697 """Returns False if everything's ok or True if something's wrong.""" 698 setBusyCursor() 699 pwin = progress.Progress() 700 pwin.setLabel(_("Registering system and sending profile information. Please wait.")) 701 self.systemId = None 702 global username, password, hw_activation_code, \ 703 _hasBaseChannelAndUpdates, chosen_channel 704 other = {} 705 if hw_activation_code: 706 other['registration_number'] = hw_activation_code 707 if chosen_channel is not None: 708 other['channel'] = chosen_channel 709 710 (virt_uuid, virt_type) = rhnreg.get_virt_info() 711 if not virt_uuid is None: 712 other['virt_uuid'] = virt_uuid 713 other['virt_type'] = virt_type 714 715 profileName = self.createProfileXml.get_widget("systemNameEntry").get_text() 716 717 pwin.setProgress(1, 6) 718 719 pwin.setStatusLabel(_("Registering System")) 720 try: 721 reg_info = rhnreg.registerSystem2(username, password, profileName, other=other) 722 log.log_me("Registered system.") 723 self.systemId = reg_info.getSystemId() 724 _hasBaseChannelAndUpdates = reg_info.hasBaseAndUpdates() 725 if reg_info.getUniversalActivationKey(): 726 reviewLog.usedUniversalActivationKey( 727 reg_info.getUniversalActivationKey()) 728 reviewLog.channels(reg_info.getChannels(), reg_info.getFailedChannels()) 729 reviewLog.systemSlots(reg_info.getSystemSlotDescriptions(), 730 reg_info.getFailedSystemSlotDescriptions()) 731 except up2dateErrors.CommunicationError: 732 e = sys.exc_info()[1] 733 pwin.hide() 734 self.fatalError(_("Problem registering system:\n") + e.errmsg) 735 return True # fatalError in firstboot will return to here 736 except up2dateErrors.RhnUuidUniquenessError: 737 e = sys.exc_info()[1] 738 pwin.hide() 739 self.fatalError(_("Problem registering system:\n") + e.errmsg) 740 return True # fatalError in firstboot will return to here 741 except up2dateErrors.InsuffMgmntEntsError: 742 e = sys.exc_info()[1] 743 pwin.hide() 744 self.fatalError(_("Problem registering system:\n") + e.errmsg) 745 except up2dateErrors.RegistrationDeniedError: 746 e = sys.exc_info()[1] 747 pwin.hide() 748 self.fatalError(_("Problem registering system:\n") + e.errmsg) 749 except up2dateErrors.InvalidProductRegistrationError: 750 pwin.hide() 751 errorWindow(_("The installation number [ %s ] provided is not a valid installation number. Please go back to the previous screen and fix it." % 752 other['registration_number'])) 753 return True 754 except up2dateErrors.ActivationKeyUsageLimitError: 755 pwin.hide() 756 self.fatalError(rhnreg_constants.ACT_KEY_USAGE_LIMIT_ERROR) 757 return True # fatalError in firstboot will return to here 758 except: 759 setArrowCursor() 760 pwin.hide() 761 errorWindow(_("Problem registering system.")) 762 log.log_exception(*sys.exc_info()) 763 return True 764 pwin.setProgress(2,6) 765 766 # write the system id out. 767 if self.systemId: 768 if not rhnreg.writeSystemId(self.systemId): 769 setArrowCursor() 770 pwin.hide() 771 errorWindow(_("Problem writing out system id to disk.")) 772 return True 773 log.log_me("Wrote system id to disk.") 774 else: 775 setArrowCursor() 776 pwin.hide() 777 errorWindow(_("There was a problem registering this system.")) 778 return True 779 global productInfo # Contains the user's info (name, e-mail, etc) 780 if cfg['supportsUpdateContactInfo']: 781 ret = self.__updateContactInfo(productInfo, username, password, pwin) 782 else: 783 ret = self.__registerProduct(productInfo, pwin) 784 if ret: 785 return ret 786 pwin.setProgress(3, 6) 787 788 # maybe upload hardware profile 789 if self.sendHardware: 790 pwin.setStatusLabel(_("Sending hardware information")) 791 try: 792 rhnreg.sendHardware(self.systemId, self.hardware) 793 log.log_me("Sent hardware profile.") 794 except: 795 pwin.setStatusLabel(_("Problem sending hardware information.")) 796 import time 797 time.sleep(1) 798 pwin.setProgress(4, 6) 799 800 if self.sendPackages: 801 getArch = 0 802 if cfg['supportsExtendedPackageProfile']: 803 getArch = 1 804 packageList = pkgUtils.getInstalledPackageList(progressCallback = lambda amount, 805 total: gtk.main_iteration_do(False), 806 getArch=getArch) 807 ## selection = [] 808 # FIXME 809 selectedPackages = packageList 810 ## for row in range(self.regPackageArea.n_rows): 811 ## rowData = self.regPackageArea.get_row_data(row) 812 ## if rowData[0] == 1: 813 ## selection.append(rowData[1]) 814 ## print("gh270") 815 ## selectedPackages = [] 816 ## for pkg in packageList: 817 ## if pkg[0] in selection: 818 ## selectedPackages.append(pkg) 819 pwin.setStatusLabel(_("Sending package information")) 820 try: 821 rhnreg.sendPackages(self.systemId, selectedPackages) 822 log.log_me("Sent package list.") 823 except: 824 pwin.setStatusLabel(_("Problem sending package information.")) 825 import time 826 time.sleep(1) 827 828 # Send virtualization information to the server. 829 rhnreg.sendVirtInfo(self.systemId) 830 831 li = None 832 try: 833 li = up2dateAuth.updateLoginInfo() 834 except up2dateErrors.InsuffMgmntEntsError: 835 self.serviceNotEnabled = 1 836 self.fatalError(str(sys.exc_info()[1]), wrap=0) 837 except up2dateErrors.RhnServerException: 838 self.fatalError(str(sys.exc_info()[1]), wrap=0) 839 return True # fatalError in firstboot will return to here 840 841 if li: 842 # see if we have any active channels 843 if li['X-RHN-Auth-Channels'] == []: 844 # no channels subscribe 845 self.noChannels = 1 846 847 # enable yum-rhn-plugin / dnf-plugin-spacewalk 848 try: 849 present, conf_changed = rhnreg.pluginEnable() 850 if not present: 851 reviewLog.pm_plugin_warning() 852 if conf_changed: 853 reviewLog.pm_plugin_conf_changed() 854 except IOError: 855 e = sys.exc_info()[1] 856 errorWindow(_("Could not open %s\n%s is not enabled.\n") % (PM_PLUGIN_CONF, PM_PLUGIN_NAME) + e.errmsg) 857 reviewLog.pm_plugin_conf_error() 858 rhnreg.spawnRhnCheckForUI() 859 pwin.setProgress(6,6) 860 pwin.hide() 861 862 setArrowCursor() 863 return False
864 865
866 - def __updateContactInfo(self, productInfo, uname, password, pwin):
867 return False
868
869 - def __registerProduct(self, productInfo, pwin):
870 return False
871 872
873 -class ProvideCertificatePage:
874 - def __init__(self):
875 self.provideCertificateXml = gtk.glade.XML(gladefile, 876 "provideCertificateWindowVbox", 877 domain="rhn-client-tools") 878 879 self.orig_cert_label_template = self.provideCertificateXml.get_widget("SecurityCertLabel").get_text()
880
881 - def provideCertificatePageVbox(self):
882 return self.provideCertificateXml.get_widget("provideCertificateWindowVbox")
883
884 - def setUrlInWidget(self):
885 """ 886 sets the security cert label's server url at runtime 887 """ 888 securityCertlabel = self.provideCertificateXml.get_widget("SecurityCertLabel") 889 securityCertlabel.set_text(self.orig_cert_label_template % config.getServerlURL()[0] )
890
892 """If the 'I have a cert' radio button is selected, this function will 893 copy the cert to /usr/share/rhn. It will name it 894 RHN-ORG-TRUSTED-SSL-CERT. It will 895 change the owner to root and the perms to 644. If a file with 896 that name already exists it will add a '.save<lowest available integer>' to 897 the end of the old file's name. It will update the config file to point 898 to the new cert. 899 Returns: 900 0- cert was installed 901 1- the user doesn't want to provide a cert right now 902 2- an error occurred and the user was notified 903 3- the cert was installed ok, but the server doesn't support needed 904 calls 905 Doesn't raise any exceptions. 906 """ 907 status = callAndFilterExceptions( 908 self._provideCertificatePageApply, 909 [], 910 _("There was an error while installing the certificate.") 911 ) 912 if status == 0 or status == 1 or status == 3: 913 return status 914 else: 915 return 2
916
918 """Does what the comment for provideCertificatePageApply says, but might 919 raise various exceptions. 920 921 """ 922 CERT_INSTALLED = 0 923 NOT_INSTALLING_CERT = 1 924 ERROR_WAS_HANDLED = 2 925 SERVER_TOO_OLD = 3 926 927 assert serverType in ['satellite'] 928 try: 929 provideCertButton = self.provideCertificateXml.get_widget("provideCertificateButton") 930 provideCert = provideCertButton.get_active() 931 if not provideCert: 932 return NOT_INSTALLING_CERT 933 fileChooser = self.provideCertificateXml.get_widget("certificateChooserButton") 934 certFile = fileChooser.get_filename() 935 if certFile is None: 936 errorWindow(_("You must select a certificate.")) 937 return ERROR_WAS_HANDLED 938 up2dateConfig = config.initUp2dateConfig() 939 destinationName = '/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT' 940 if certFile != destinationName: 941 if os.path.exists(certFile): 942 destinationName = certFile 943 up2dateConfig.set('sslCACert', destinationName) 944 up2dateConfig.save() 945 # Take the new cert for a spin 946 try: 947 rhnreg.getCaps() 948 except up2dateErrors.SSLCertificateVerifyFailedError: 949 server_url = config.getServerlURL()[0] 950 #TODO: we could point the user to grab the cert from /pub if its sat 951 952 #bz439383 - Handle error message for expired certificate 953 f = open(certFile, "r") 954 buf = f.read() 955 f.close() 956 tempCert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, buf) 957 if tempCert.has_expired(): 958 errorWindow(rhnreg_constants.SSL_CERT_EXPIRED) 959 else: 960 errorWindow(rhnreg_constants.SSL_CERT_ERROR_MSG % (certFile, server_url)) 961 962 return ERROR_WAS_HANDLED 963 except OpenSSL.SSL.Error: 964 # TODO Modify rhnlib to raise a unique exception for the not a 965 # cert file case. 966 errorWindow(_("There was an SSL error. This could be because the file you picked was not a certificate file.")) 967 return ERROR_WAS_HANDLED 968 969 return CERT_INSTALLED 970 971 except IOError: 972 e = sys.exc_info()[1] 973 # TODO Provide better messages 974 message = _("Something went wrong while installing the new certificate:\n") 975 message = message + e.strerror 976 errorWindow(message) 977 return ERROR_WAS_HANDLED
978 979
980 -class FinishPage:
981 """The finish screen. This can show two different versions: successful and 982 unsuccessful. 983 984 """
985 - def __init__(self):
986 self.failedFinishXml = gtk.glade.XML(gladefile, 987 "failedFinishWindowVbox", 988 domain="rhn-client-tools") 989 self.successfulFinishXml = gtk.glade.XML(gladefile, 990 "successfulFinishWindowVbox", 991 domain="rhn-client-tools") 992 # This is an intermediate vbox that this class provides to it's users. 993 # On prepare, the right version of the screen will be put into it. 994 self.finishContainerVbox = gtk.VBox() 995 # The vboxes that contain the two versions of the screen: 996 self.failedFinishVbox = \ 997 self.failedFinishXml.get_widget("failedFinishWindowVbox") 998 self.successfulFinishVbox = \ 999 self.successfulFinishXml.get_widget("successfulFinishWindowVbox") 1000 # Put one in now (either one) to make the prepare code simpler 1001 self.finishContainerVbox.pack_start(self.failedFinishVbox, 1002 expand=True, fill=True, padding=0)
1003
1004 - def finishPageVbox(self):
1005 return self.finishContainerVbox
1006
1007 - def finishPagePrepare(self):
1008 containerChildren = self.finishContainerVbox.get_children() 1009 assert len(containerChildren) == 1 1010 self.finishContainerVbox.remove(containerChildren[0]) 1011 if hasBaseChannelAndUpdates(): 1012 self.finishContainerVbox.pack_start(self.successfulFinishVbox, True, True, 0) 1013 else: 1014 self.finishContainerVbox.pack_start(self.failedFinishVbox, True, True, 0)
1015 1016
1017 -class AlreadyRegisteredDialog:
1018 - def __init__(self):
1019 """Returns when dialog closes. Dialog.rc will be set to 1 if the user 1020 clicked continue, or 0 if they clicked cancel or close the dialog. 1021 1022 """ 1023 self.xml = gtk.glade.XML(gladefile, "alreadyRegisteredDialog", 1024 domain="rhn-client-tools") 1025 self.dialog = self.xml.get_widget("alreadyRegisteredDialog") 1026 1027 server = _('unknown') 1028 oldUsername = _('unknown') 1029 systemId = _('unknown') 1030 try: 1031 # If the serverURL config value is a list, we have no way of knowing 1032 # for sure which one the machine registered against, 1033 # so default to the 1034 # first element. 1035 server = config.getServerlURL()[0] 1036 1037 if server.endswith('/XMLRPC'): 1038 server = server[:-7] # don't display trailing /XMLRPC 1039 systemIdXml = rpclib.xmlrpclib.loads(up2dateAuth.getSystemId()) 1040 oldUsername = systemIdXml[0][0]['username'] 1041 systemId = systemIdXml[0][0]['system_id'] 1042 except: 1043 pass 1044 1045 self.xml.get_widget('serverUrlLabel').set_label(server) 1046 self.xml.get_widget('usernameLabel2').set_label(oldUsername) 1047 self.xml.get_widget('systemIdLabel').set_label(systemId) 1048 1049 self.rc = self.dialog.run() 1050 if self.rc != 1: 1051 self.rc = 0 1052 self.dialog.destroy()
1053
1054 -class AlreadyRegisteredSubscriptionManagerDialog:
1055 """ Window with text: 1056 You are already subscribed using subscription manager. Exit. Continue 1057 """ 1058
1059 - def __init__(self):
1060 """Returns when dialog closes. Dialog.rc will be set to 1 if the user 1061 clicked continue, or 0 if they clicked cancel or close the dialog. 1062 """ 1063 self.xml = gtk.glade.XML(gladefile, "alreadyRegisteredSubscriptionManagerDialog", 1064 domain="rhn-client-tools") 1065 self.dialog = self.xml.get_widget("alreadyRegisteredSubscriptionManagerDialog") 1066 1067 self.rc = self.dialog.run() 1068 if self.rc != 1: 1069 self.rc = 0 1070 self.dialog.destroy()
1071
1072 -class ConfirmQuitDialog:
1073 - def __init__(self, parent):
1074 """Returns when dialog closes. Dialog.rc will be set to 0 if the user 1075 clicked "take me back" or closed the dialog, or 1 if they clicked "i'll 1076 register later". I've they clicked I'll register later, the remind file 1077 will be written to disk. 1078 1079 """ 1080 self.xml = gtk.glade.XML(gladefile, "confirmQuitDialog", 1081 domain="rhn-client-tools") 1082 self.dialog = self.xml.get_widget("confirmQuitDialog") 1083 self.dialog.set_transient_for(parent) 1084 self.rc = self.dialog.run() 1085 if self.rc == gtk.RESPONSE_NONE: 1086 self.rc = 0 1087 if self.rc == 1: 1088 try: 1089 rhnreg.createSystemRegisterRemindFile() 1090 except (OSError, IOError): 1091 log.log_me("Reminder file couldn't be written. Details: %s" % 1092 sys.exc_info()[1]) 1093 self.dialog.destroy()
1094
1095 -class MoreInfoDialog:
1096 - def __init__(self):
1097 self.moreInfoXml = gtk.glade.XML(gladefile, 1098 "moreInfoDialog", domain="rhn-client-tools") 1099 self.dlg = self.moreInfoXml.get_widget("moreInfoDialog") 1100 self.moreInfoXml.signal_autoconnect({ 1101 "onCloseMoreInfoButtonClicked" : self.finish, 1102 })
1103
1104 - def finish(self, button):
1105 self.dlg.hide() 1106 self.rc = 1 # What does this do? Is it needed?
1107
1108 -class WhyRegisterDialog:
1109 - def __init__(self):
1110 self.whyRegisterXml = gtk.glade.XML(gladefile, 1111 "whyRegisterDialog", domain="rhn-client-tools") 1112 self.dlg = self.whyRegisterXml.get_widget("whyRegisterDialog") 1113 self.whyRegisterXml.signal_autoconnect({ 1114 "onBackToRegistrationButtonClicked" : self.finish, 1115 })
1116
1117 - def finish(self, button):
1118 self.dlg.hide() 1119 self.rc = 1 # What does this do? Is it needed?
1120 1121
1122 -class HardwareDialog:
1123 - def __init__(self):
1124 self.hwXml = gtk.glade.XML( 1125 gladefile, 1126 "hardwareDialog", domain="rhn-client-tools") 1127 self.dlg = self.hwXml.get_widget("hardwareDialog") 1128 1129 self.hwXml.get_widget("okButton").connect("clicked", self.finish) 1130 callAndFilterExceptions( 1131 self.populateHardware, 1132 [], 1133 _("There was an error getting the list of hardware.") 1134 )
1135
1136 - def populateHardware(self):
1137 # Read all hardware in 1138 self.hardware = hardware.Hardware() 1139 1140 for hw in self.hardware: 1141 if hw['class'] == 'CPU': 1142 label = self.hwXml.get_widget("cpuLabel") 1143 label.set_text(hw['model']) 1144 label = self.hwXml.get_widget("speedLabel") 1145 label.set_text(_("%d MHz") % hw['speed']) 1146 elif hw['class'] == 'MEMORY': 1147 label = self.hwXml.get_widget("ramLabel") 1148 try: 1149 label.set_text(_("%s MB") % hw['ram']) 1150 except: 1151 pass 1152 elif hw['class'] == 'NETINFO': 1153 label = self.hwXml.get_widget("hostnameLabel") 1154 try: 1155 label.set_text(idn_puny_to_unicode(hw['hostname'])) 1156 except: 1157 pass 1158 label = self.hwXml.get_widget("ipLabel") 1159 try: 1160 label.set_text(hw['ipaddr']) 1161 except: 1162 pass 1163 1164 1165 label = self.hwXml.get_widget("versionLabel") 1166 try: 1167 distversion = up2dateUtils.getVersion() 1168 except up2dateErrors.RpmError: 1169 e = sys.exc_info()[1] 1170 # TODO Do something similar during registration if the same 1171 # situation can happen. Even better, factor out the code to get the 1172 # hardware. 1173 errorWindow(e.errmsg) 1174 distversion = 'unknown' 1175 label.set_text(distversion)
1176
1177 - def finish(self, button):
1178 self.dlg.hide() 1179 self.rc = 1
1180 1181
1182 -class PackageDialog:
1183 - def __init__(self):
1184 self.swXml = gtk.glade.XML( 1185 gladefile, 1186 "packageDialog", domain="rhn-client-tools") 1187 self.dlg = self.swXml.get_widget("packageDialog") 1188 1189 self.swXml.get_widget("okButton2").connect("clicked", self.finish) 1190 1191 callAndFilterExceptions( 1192 self.populateDialog, 1193 [], 1194 _("There was an error building the list of packages.") 1195 )
1196
1197 - def populateDialog(self):
1198 # name-version-release, arch 1199 self.packageStore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) 1200 for package in self.getPackageList(): 1201 nvr = "%s-%s-%s" % (package['name'], package['version'], package['release']) 1202 arch = package['arch'] 1203 self.packageStore.append((nvr, arch)) 1204 self.packageTreeView = self.swXml.get_widget("packageTreeView") 1205 self.packageTreeView.set_model(self.packageStore) 1206 1207 self.packageTreeView.set_rules_hint(True) 1208 1209 col = gtk.TreeViewColumn(_("Package"), gtk.CellRendererText(), text=0) 1210 col.set_sort_column_id(0) 1211 col.set_sort_order(gtk.SORT_ASCENDING) 1212 self.packageTreeView.append_column(col) 1213 1214 col = gtk.TreeViewColumn(_("Arch"), gtk.CellRendererText(), text=1) 1215 self.packageTreeView.append_column(col) 1216 1217 self.packageStore.set_sort_column_id(0, gtk.SORT_ASCENDING)
1218
1219 - def getPackageList(self):
1220 pwin = progress.Progress() 1221 pwin.setLabel(_("Building a list of RPM packages installed on your system. Please wait.")) 1222 packageDialogPackages = pkgUtils.getInstalledPackageList(progressCallback = pwin.setProgress, getArch=1) 1223 pwin.hide() 1224 return packageDialogPackages
1225
1226 - def finish(self, button):
1227 self.dlg.hide() 1228 self.rc = 1
1229 1230
1231 -class NetworkConfigDialog:
1232 """This is the dialog that allows setting http proxy settings. 1233 1234 It uses the instant apply paradigm or whatever you wanna call it that the 1235 gnome HIG recommends. Whenever a toggle button is flipped or a text entry 1236 changed, the new setting will be saved. 1237 1238 """
1239 - def __init__(self):
1240 self.xml = gtk.glade.XML(gladefile, "networkConfigDialog", 1241 domain="rhn-client-tools") 1242 # Get widgets we'll need to access 1243 self.dlg = self.xml.get_widget("networkConfigDialog") 1244 self.enableProxyButton = self.xml.get_widget("enableProxyButton") 1245 self.enableProxyAuthButton = self.xml.get_widget("enableProxyAuthButton") 1246 self.proxyEntry = self.xml.get_widget("proxyEntry") 1247 self.proxyUserEntry = self.xml.get_widget("proxyUserEntry") 1248 self.proxyPasswordEntry = self.xml.get_widget("proxyPasswordEntry") 1249 try: 1250 self.cfg = config.initUp2dateConfig() 1251 except: 1252 gnome.ui.GnomeErrorDialog(_("There was an error loading your " 1253 "configuration. Make sure that\nyou " 1254 "have read access to /etc/sysconfig/rhn."), 1255 self.dlg) 1256 # Need to load values before connecting signals because when the dialog 1257 # starts up it seems to trigger the signals which overwrites the config 1258 # with the blank values. 1259 self.setInitialValues() 1260 self.enableProxyButton.connect("toggled", self.enableAction) 1261 self.enableProxyAuthButton.connect("toggled", self.enableAction) 1262 self.enableProxyButton.connect("toggled", self.writeValues) 1263 self.enableProxyAuthButton.connect("toggled", self.writeValues) 1264 self.proxyEntry.connect("focus-out-event", self.writeValues) 1265 self.proxyUserEntry.connect("focus-out-event", self.writeValues) 1266 self.proxyPasswordEntry.connect("focus-out-event", self.writeValues) 1267 self.xml.get_widget("closeButton").connect("clicked", self.close) 1268 self.dlg.show()
1269
1270 - def setInitialValues(self):
1271 self.xml.get_widget("enableProxyButton").set_active(self.cfg["enableProxy"]) 1272 self.enableAction(self.xml.get_widget("enableProxyButton")) 1273 self.xml.get_widget("proxyEntry").set_text(self.cfg["httpProxy"]) 1274 self.xml.get_widget("enableProxyAuthButton").set_active(self.cfg["enableProxyAuth"]) 1275 self.enableAction(self.xml.get_widget("enableProxyAuthButton")) 1276 self.xml.get_widget("proxyUserEntry").set_text(str(self.cfg["proxyUser"])) 1277 self.xml.get_widget("proxyPasswordEntry").set_text(str(self.cfg["proxyPassword"]))
1278
1279 - def writeValues(self, widget=None, dummy=None):
1280 self.cfg.set("enableProxy", 1281 int(self.xml.get_widget("enableProxyButton").get_active())) 1282 self.cfg.set("httpProxy", 1283 self.xml.get_widget("proxyEntry").get_text()) 1284 self.cfg.set("enableProxyAuth", 1285 int(self.xml.get_widget("enableProxyAuthButton").get_active())) 1286 self.cfg.set("proxyUser", 1287 str(self.xml.get_widget("proxyUserEntry").get_text())) 1288 self.cfg.set("proxyPassword", 1289 str(self.xml.get_widget("proxyPasswordEntry").get_text())) 1290 try: 1291 self.cfg.save() 1292 except: 1293 gnome.ui.GnomeErrorDialog(_( 1294 "There was an error saving your configuration. "\ 1295 "Make sure that\nyou own %s.") % self.cfg.fileName, 1296 self.dlg)
1297
1298 - def close(self, button):
1299 self.dlg.hide()
1300
1301 - def enableAction(self, button):
1302 if button.get_name() == "enableProxyButton": 1303 self.xml.get_widget("proxyEntry").set_sensitive(button.get_active()) 1304 self.xml.get_widget("proxyEntry").grab_focus() 1305 elif button.get_name() == "enableProxyAuthButton": 1306 self.xml.get_widget("proxyUserEntry").set_sensitive(button.get_active()) 1307 self.xml.get_widget("proxyPasswordEntry").set_sensitive(button.get_active()) 1308 self.xml.get_widget("usernameLabel").set_sensitive(button.get_active()) 1309 self.xml.get_widget("passwordLabel").set_sensitive(button.get_active())
1310 1311
1312 -def errorWindow(message):
1313 messageWindow.ErrorDialog(messageWindow.wrap_text(message))
1314
1315 -def unexpectedError(message, exc_info=None):
1316 """Shows an error dialog with the message and logs that an error happened. 1317 1318 This function is designed to be used in an except block like so: 1319 unexpectedError(_("Your error here."), sys.exc_info()) 1320 1321 """ 1322 setArrowCursor() 1323 logFile = cfg['logFile'] or '/var/log/up2date' 1324 message = message + "\n" + (_("This error shouldn't have happened. If you'd " 1325 "like to help us improve this program, please " 1326 "file a bug at bugzilla.redhat.com. Including " 1327 "the relevant parts of '%s' would be very " 1328 "helpful. Thanks!") % logFile) 1329 errorWindow(message) 1330 if exc_info: 1331 (etype, value, stack_trace) = exc_info 1332 log.log_exception(etype, value, stack_trace) 1333 else: 1334 log.log_me("An unexpected error happened, but exc_info wasn't provided.")
1335
1336 -def callAndFilterExceptions(function, allowedExceptions, 1337 disallowedExceptionMessage, errorHandler=unexpectedError):
1338 """Calls function and limits the exceptions that can be raised to those in 1339 the list provided and SystemExit. If an exception is raised which isn't 1340 allowed, errorHandler will be called and then None will be returned. 1341 errorHandler defaults to the unexpectedError function and will be passed 1342 disallowedExceptionMessage. If it is overridden, the function provided must 1343 take a string and a tuple (see below for details). If no exceptions are 1344 raised, functions's return value is returned. 1345 1346 I need this function because if some of the functions in the Pages raise 1347 unexpected exceptions, the druid might advance when it shouldn't or go to 1348 the wrong page. I think it's shorter and more readable to factor this out 1349 rather than have similar functionality in all those functions. 1350 """ 1351 assert callable(function) 1352 allowedExceptions.append(SystemExit) 1353 try: 1354 return function() 1355 except: 1356 (exceptionType, exception, stackTrace) = sys.exc_info() 1357 if exceptionType in allowedExceptions: 1358 raise 1359 else: 1360 errorHandler(disallowedExceptionMessage, 1361 (exceptionType, exception, stackTrace))
1362
1363 -def hasBaseChannelAndUpdates():
1364 """Returns a bool indicating whether the system has registered, subscribed 1365 to a base channel, and has at least update entitlements. 1366 Uses information from the most recent time the create profile screen was run 1367 through. 1368 1369 """ 1370 global _hasBaseChannelAndUpdates 1371 return _hasBaseChannelAndUpdates
1372 1373
1374 -def setBusyCursor():
1375 """Dummy function that will be overidden by rhn_register's standalone gui 1376 and firstboot in different ways. 1377 1378 """ 1379 pass
1380
1381 -def setArrowCursor():
1382 """Dummy function that will be overidden by rhn_register's standalone gui 1383 and firstboot in different ways. 1384 1385 """ 1386 pass
1387