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 import sys
35 import os
36 import socket
37
38 from optparse import Option
39 from optparse import OptionParser
40
41 from OpenSSL import SSL
42 from OpenSSL import crypto
43
44 from rhn import rpclib
45 from rhn.i18n import sstr
46
47 try:
48 import xmlrpclib
49 except ImportError:
50 import xmlrpc.client as xmlrpclib
51
52 import gettext
53 t = gettext.translation('rhn-client-tools', fallback=True)
54
55 if not hasattr(t, 'ugettext'):
56 t.ugettext = t.gettext
57 _ = t.ugettext
58
59 from up2date_client import config
60 from up2date_client import up2dateAuth
61 from up2date_client import up2dateErrors
62 from up2date_client import up2dateLog
63 from up2date_client import up2dateUtils
64 from up2date_client import pkgUtils
65
66 _optionsTable = [
67 Option("-v", "--verbose", action="count", default=0,
68 help=_("Show additional output")),
69 Option("--proxy", action="store",
70 help=_("Specify an http proxy to use")),
71 Option("--proxyUser", action="store",
72 help=_("Specify a username to use with an authenticated http proxy")),
73 Option("--proxyPassword", action="store",
74 help=_("Specify a password to use with an authenticated http proxy")),
75 ]
78
87
89
90 sys.excepthook = exceptionHandler
91
92 try:
93 self.initialize()
94 sys.exit(self.main() or 0)
95 except KeyboardInterrupt:
96 sys.stderr.write(sstr(_("\nAborted.\n")))
97 sys.exit(1)
98 except OSError:
99 sys.stderr.write(sstr(_("An unexpected OS error occurred: %s\n") % sys.exc_info()[1]))
100 sys.exit(1)
101 except rpclib.MalformedURIError:
102 e = sys.exc_info()[1]
103 if e is None or len(str(e)) == 0:
104 sys.stderr.write(sstr(_("A connection was attempted with a malformed URI.\n")))
105 else:
106 sys.stderr.write(sstr(_("A connection was attempted with a malformed URI: %s.\n") % e))
107 except IOError:
108 sys.stderr.write(sstr(_("There was some sort of I/O error: %s\n") % sys.exc_info()[1]))
109 sys.exit(1)
110 except SSL.Error:
111 sys.stderr.write(sstr(_("There was an SSL error: %s\n") % sys.exc_info()[1]))
112 sys.stderr.write(sstr(_("A common cause of this error is the system time being incorrect. " \
113 "Verify that the time on this system is correct.\n")))
114 sys.exit(1)
115 except (SSL.SysCallError, socket.error):
116 sys.stderr.write(sstr("OpenSSL.SSL.SysCallError: %s\n" % str(sys.exc_info()[1])))
117 sys.exit(2)
118 except crypto.Error:
119 sys.stderr.write(sstr(_("There was a SSL crypto error: %s\n") % sys.exc_info()[1]))
120 except SystemExit:
121 raise
122 except up2dateErrors.AuthenticationError:
123 sys.stderr.write(sstr(_("There was an authentication error: %s\n") % sys.exc_info()[1]))
124 sys.exit(1)
125 except up2dateErrors.RpmError:
126 sys.stderr.write(sstr("%s\n" % sys.exc_info()[1]))
127 sys.exit(1)
128 except xmlrpclib.ProtocolError:
129 sys.stderr.write(sstr("XMLRPC ProtocolError: %s\n" % str(sys.exc_info()[1])))
130 sys.exit(3)
131
144
146 raise NotImplementedError
147
162
164 if self.hasGui:
165 try:
166 from up2date_client import gui
167 gui.errorWindow(message)
168 except:
169 print(_("Unable to open gui. Try `up2date --nox`"))
170 print(message)
171 else:
172 print(message)
173
175 """Update potential proxy configuration.
176 Note: this will _not_ save the info to up2date's configuration file
177 A separate call to config.initUp2dateConfig.save() is needed.
178 """
179 cfg = config.initUp2dateConfig()
180
181 if self.options.proxy:
182 cfg.set("httpProxy", self.options.proxy)
183 cfg.set("enableProxy", 1)
184 if self.options.proxyUser:
185 cfg.set("proxyUser", self.options.proxyUser)
186 cfg.set("enableProxyAuth", 1)
187 if self.options.proxyPassword:
188 cfg.set("proxyPassword", self.options.proxyPassword)
189 cfg.set("enableProxyAuth", 1)
190
197
199 if self.hasGui:
200 try:
201 from up2date_client import gui
202 gui.errorWindow(errMsg)
203 except:
204 print(_("Unable to open gui. Try `up2date --nox`"))
205 print(errMsg)
206 else:
207 print(errMsg)
208
209 @staticmethod
211 versionString = _("%%prog (Spacewalk Client Tools) %s\n"
212 "Copyright (C) 1999--2014 Red Hat, Inc.\n"
213 "Licensed under the terms of the GPLv2.") % up2dateUtils.version()
214 return versionString
215
216 @staticmethod
223
235