Module rhn_register
[hide private]
[frames] | no frames]

Source Code for Module rhn_register

 1  #!/usr/bin/python2 
 2  # 
 3  # Spacewalk / Red Hat Network Classic registration tool 
 4  # Adapted from wrapper.py 
 5  # Copyright (c) 1999--2018 Red Hat, Inc.  Distributed under GPLv2. 
 6  # 
 7  # Authors: 
 8  #       Adrian Likins <alikins@redhat.com> 
 9  #       Preston Brown <pbrown@redhat.com> 
10  #       James Bowes <jbowes@redhat.com> 
11  #       Daniel Benamy <dbenamy@redhat.com> 
12   
13  import sys 
14  import os 
15   
16  import gettext 
17  t = gettext.translation('rhn-client-tools', fallback=True) 
18  # Python 3 translations don't have a ugettext method 
19  if not hasattr(t, 'ugettext'): 
20      t.ugettext = t.gettext 
21  _ = t.ugettext 
22   
23  from up2date_client import up2dateLog 
24  up2dateLog.initLog().set_app_name('rhn_register') 
25  from up2date_client import up2dateAuth 
26  from up2date_client import rhncli 
27  from up2date_client import tui 
28  from up2date_client import up2dateErrors 
29   
30 -class RhnRegister(rhncli.RhnCli):
31 """Runs rhn_register. Can run it in gui or tui mode depending on 32 availablility of gui, DISPLAY environment variable, and --nox switch. 33 34 """
35 - def __init__(self):
36 super(RhnRegister, self).__init__() 37 self.optparser.add_option("--nox", action="store_true", default=False, 38 help=_("Do not attempt to use X"))
39
40 - def _get_ui(self):
41 try: 42 if os.environ["DISPLAY"] != "" and \ 43 not self.options.nox: 44 from up2date_client import gui 45 self.hasGui = True # Used by base class. Yech. 46 return gui 47 except: 48 pass 49 50 return tui
51
52 - def main(self):
53 """RhnCli (the base class) just sets stuff up and then calls this to run 54 the rest of the program. 55 56 """ 57 ui = self._get_ui() 58 ui.main() 59 60 # Check to see if the registration worked. 61 try: 62 if not up2dateAuth.getLoginInfo(): 63 if not self._testRhnLogin(): 64 sys.exit(1) 65 except up2dateErrors.RhnServerException: 66 sys.exit(1) 67 68 # Assuming registration worked, remember to save info (proxy setup,etc) 69 # from rhncli 70 self.saveConfig() 71 sys.exit(0)
72 73 74 if __name__ == "__main__": 75 app = RhnRegister() 76 app.run() 77