23 from __future__
import print_function
24 from builtins
import str
25 from builtins
import input
33 _code_location =
'/usr/share/smolt/client'
34 if sys.path[-1] == _code_location:
36 sys.path.append(_code_location)
44 from optparse
import OptionParser
45 parser = OptionParser(version = smolt.clientVersion)
47 parser.add_option(
'-d',
'--debug',
50 action =
'store_true',
51 help =
_(
'enable debug information'))
52 parser.add_option(
'--config',
53 dest =
'the_only_config_file',
56 help =
_(
'specify the location of the (only) config file to use'))
57 parser.add_option(
'-s',
'--server',
59 default = smolt.smoonURL,
61 help =
_(
'specify the URL of the server (default "%default")'))
62 parser.add_option(
'--username',
66 help =
_(
'(optional) Fedora Account System registration'))
67 parser.add_option(
'--password',
71 help =
_(
'password, will prompt if not specified'))
72 parser.add_option(
'-p',
'--printOnly',
75 action =
'store_true',
76 help =
_(
'print information only, do not send'))
77 parser.add_option(
'-a',
'--autoSend',
80 action =
'store_true',
81 help =
_(
'don\'t prompt to send, just send'))
82 parser.add_option(
'-r',
'--retry',
85 action =
'store_true',
86 help =
_(
'continue to send until success'))
87 parser.add_option(
'-u',
'--useragent',
'--user_agent',
89 default = smolt.user_agent,
90 metavar =
'USERAGENT',
91 help =
_(
'specify HTTP user agent (default "%default")'))
92 parser.add_option(
'-t',
'--timeout',
95 default = smolt.timeout,
96 help =
_(
'specify HTTP timeout in seconds (default %default seconds)'))
97 parser.add_option(
'-c',
'--checkin',
100 action =
'store_true',
101 help =
_(
'do an automated checkin as when run from cron (implies --autoSend)'))
102 parser.add_option(
'-S',
'--scanOnly',
103 dest =
'send_profile',
105 action =
'store_false',
106 help =
_(
'only scan this machine for known hardware errata, do not send profile.'))
107 parser.add_option(
'--submitOnly',
108 dest =
'scan_remote',
110 action =
'store_false',
111 help =
_(
'do not scan this machine for know hardware errata, only submit profile.'))
112 parser.add_option(
'--uuidFile',
114 default = smolt.hw_uuid_file,
115 help =
_(
'specify which uuid to use, useful for debugging and testing mostly.'))
121 parser.add_option(
'-n',
'--newPublicUUID',
124 action =
'store_true',
125 help =
_(
'Request a new public UUID'))
126 parser.add_option(
'--http-proxy',
129 help =
_(
'HTTP proxy'))
131 (opts, args) = parser.parse_args()
143 from smolt
import to_ascii
145 def inner_indent(text):
146 return (
'\n' + 5 *
' ').join(text.split(
'\n'))
149 'label_intro':
_(
'Smolt has collected four types of information:'),
150 'label_question':
_(
'Do you want to ..'),
151 'label_question_view':
_(
'(v)iew details on collected information?'),
152 'label_question_send':
_(
'(s)end this information to the Smolt server?'),
153 'label_question_quit':
_(
'(q)uit Smolt?'),
154 'label_general':
_(
'General'),
155 'label_devices':
_(
'Devices'),
156 'label_fs_related':
_(
'File system-related'),
157 'label_distro_specific':
_(
'Distribution-specific'),
159 'general':inner_indent(
to_ascii(profile.get_general_info_excerpt())),
160 'devices':inner_indent(
to_ascii(profile.get_devices_info_excerpt())),
161 'file_system':inner_indent(
to_ascii(profile.get_file_system_info_excerpt())),
162 'distro':inner_indent(
to_ascii(profile.get_distro_info_excerpt())),
169 =====================================================
181 %(label_distro_specific)s
184 =====================================================
186 %(label_question_view)s
187 %(label_question_send)s
188 %(label_question_quit)s
194 from tempfile
import NamedTemporaryFile
198 from smolt
import error
207 choice = input(
_(
'Your choice (s)end (v)iew (q)uit: ')).strip()
208 except KeyboardInterrupt:
211 if choice
in (
_(
's|y|yes')).split(
'|'):
214 elif choice
in (
_(
'q|n|no')).split(
'|'):
216 elif choice
in (
_(
'v')).split(
'|'):
217 f = NamedTemporaryFile(suffix=b
'')
218 for line
in profile.getProfile():
220 f.write(
bytes(line +
'\n',
'latin1'))
221 except UnicodeEncodeError:
224 os.chmod(f.name, 0o400)
226 pager_command = os.environ[
'PAGER']
228 if os.path.exists(
'/usr/bin/less'):
229 pager_command =
'/usr/bin/less'
230 elif os.path.exists(
'/bin/less'):
231 pager_command =
'/bin/less'
234 pager_command =
'more'
236 subprocess.call([pager_command, f.name])
238 os.system(
' '.join([pager_command, f.name]))
247 (error_code, pub_uuid, admin) = profile.send(uuiddb, uuid, user_agent=opts.user_agent,
248 smoonURL=opts.smoonURL,
249 timeout=opts.timeout,
251 batch=opts.cron_mode)
252 return (error_code, pub_uuid, admin)
258 from smolt
import error
262 (error_code, pub_uuid, admin) =
do_send_profile(uuiddb, uuid, profile, opts, proxies)
265 error(
_(
'Retry Enabled - Retrying'))
268 (error_code, pub_uuid, admin) =
do_send_profile(uuiddb, uuid, profile, opts, proxies)
270 print(
_(
'Could not send - Exiting'))
273 return (error_code, pub_uuid, admin)
281 pubUrl = smolt.get_profile_link(opts.smoonURL, pub_uuid)
283 print(
_(
'To share your profile: \n\t%s (public)') % pubUrl)
285 print(
_(
'\tAdmin Password: %s') % admin)
289 if opts.httpproxy
is None:
292 proxies = {
'http':opts.httpproxy}
302 profile = smolt.create_profile(gate, uuid)
304 sys.stderr.write(
_(
'%s\n' % e))
313 if not opts.password:
314 password = getpass.getpass(
'\n' +
_(
'Password:') +
' ')
316 password = opts.password
318 if profile.register(userName=opts.userName, password=password, user_agent=opts.user_agent, smoonURL=opts.smoonURL, timeout=opts.timeout):
319 print(
_(
'Registration Failed, Try again'))
324 from scan
import scan, rating
326 scan(profile, opts.smoonURL, gate)
328 rating(profile, opts.smoonURL, gate)
330 print(
"Could not get rating!")
337 print(
_(
'No Public UUID found! Please re-run with -n to generate a new public uuid'))
343 from smolt
import error, ServerError
346 pub_uuid = profile.regenerate_pub_uuid(uuiddb, uuid, user_agent=opts.user_agent,
347 smoonURL=opts.smoonURL,
348 timeout=opts.timeout)
349 except ServerError
as e:
350 error(
_(
'Error contacting server: %s') % str(e))
353 print(
_(
'Success! Your new public UUID is: %s' % pub_uuid))
363 for line
in profile.getProfile():
364 if not line.startswith(
'#'):
372 if not opts.autoSend:
375 (error_code, pub_uuid, admin) =
send_profile(uuiddb, uuid, profile, opts, proxies)
380 if opts.scan_remote
and not opts.cron_mode:
385 elif not opts.cron_mode:
393 from gate
import create_default_gate, create_gate_from_file
394 from uuiddb
import create_default_uuiddb
398 if opts.the_only_config_file
is None:
403 smolt.DEBUG = opts.DEBUG
404 smolt.hw_uuid_file = opts.uuidFile
410 uuid = smolt.read_uuid()
412 elif not opts.send_profile:
414 elif opts.printOnly
and not opts.autoSend:
418 uuid = smolt.read_uuid()
422 if __name__ ==
'__main__':