23from builtins
import str
24from builtins
import input
32 _code_location =
'/usr/share/smolt/client'
33 if sys.path[-1] == _code_location:
35 sys.path.append(_code_location)
43 from optparse
import OptionParser
44 parser = OptionParser(version = smolt.clientVersion)
46 parser.add_option(
'-d',
'--debug',
49 action =
'store_true',
50 help =
_(
'enable debug information'))
51 parser.add_option(
'--config',
52 dest =
'the_only_config_file',
55 help =
_(
'specify the location of the (only) config file to use'))
56 parser.add_option(
'-s',
'--server',
58 default = smolt.smoonURL,
60 help =
_(
'specify the URL of the server (default "%default")'))
61 parser.add_option(
'--username',
65 help =
_(
'(optional) Fedora Account System registration'))
66 parser.add_option(
'--password',
70 help =
_(
'password, will prompt if not specified'))
71 parser.add_option(
'-p',
'--printOnly',
74 action =
'store_true',
75 help =
_(
'print information only, do not send'))
76 parser.add_option(
'-a',
'--autoSend',
79 action =
'store_true',
80 help =
_(
'don\'t prompt to send, just send'))
81 parser.add_option(
'-r',
'--retry',
84 action =
'store_true',
85 help =
_(
'continue to send until success'))
86 parser.add_option(
'-u',
'--useragent',
'--user_agent',
88 default = smolt.user_agent,
89 metavar =
'USERAGENT',
90 help =
_(
'specify HTTP user agent (default "%default")'))
91 parser.add_option(
'-t',
'--timeout',
94 default = smolt.timeout,
95 help =
_(
'specify HTTP timeout in seconds (default %default seconds)'))
96 parser.add_option(
'-c',
'--checkin',
99 action =
'store_true',
100 help =
_(
'do an automated checkin as when run from cron (implies --autoSend)'))
101 parser.add_option(
'-S',
'--scanOnly',
102 dest =
'send_profile',
104 action =
'store_false',
105 help =
_(
'only scan this machine for known hardware errata, do not send profile.'))
106 parser.add_option(
'--submitOnly',
107 dest =
'scan_remote',
109 action =
'store_false',
110 help =
_(
'do not scan this machine for know hardware errata, only submit profile.'))
111 parser.add_option(
'--uuidFile',
113 default = smolt.hw_uuid_file,
114 help =
_(
'specify which uuid to use, useful for debugging and testing mostly.'))
120 parser.add_option(
'-n',
'--newPublicUUID',
123 action =
'store_true',
124 help =
_(
'Request a new public UUID'))
125 parser.add_option(
'--http-proxy',
128 help =
_(
'HTTP proxy'))
130 (opts, args) = parser.parse_args()
142 from smolt
import to_ascii
144 def inner_indent(text):
145 return (
'\n' + 5 *
' ').join(text.split(
'\n'))
148 'label_intro':
_(
'Smolt has collected four types of information:'),
149 'label_question':
_(
'Do you want to ..'),
150 'label_question_view':
_(
'(v)iew details on collected information?'),
151 'label_question_send':
_(
'(s)end this information to the Smolt server?'),
152 'label_question_quit':
_(
'(q)uit Smolt?'),
153 'label_general':
_(
'General'),
154 'label_devices':
_(
'Devices'),
155 'label_fs_related':
_(
'File system-related'),
156 'label_distro_specific':
_(
'Distribution-specific'),
158 'general':inner_indent(
to_ascii(profile.get_general_info_excerpt())),
159 'devices':inner_indent(
to_ascii(profile.get_devices_info_excerpt())),
160 'file_system':inner_indent(
to_ascii(profile.get_file_system_info_excerpt())),
161 'distro':inner_indent(
to_ascii(profile.get_distro_info_excerpt())),
168=====================================================
180%(label_distro_specific)s
183=====================================================
185%(label_question_view)s
186%(label_question_send)s
187%(label_question_quit)s
191def present_and_require_confirmation(profile):
193 from tempfile
import NamedTemporaryFile
197 from smolt
import error
206 choice = input(
_(
'Your choice (s)end (v)iew (q)uit: ')).strip()
207 except KeyboardInterrupt:
210 if choice
in (
_(
's|y|yes')).split(
'|'):
213 elif choice
in (
_(
'q|n|no')).split(
'|'):
215 elif choice
in (
_(
'v')).split(
'|'):
216 f = NamedTemporaryFile(suffix=b
'')
217 for line
in profile.getProfile():
219 f.write(
bytes(line +
'\n',
'latin1'))
220 except UnicodeEncodeError:
223 os.chmod(f.name, 0o400)
225 pager_command = os.environ[
'PAGER']
227 if os.path.exists(
'/usr/bin/less'):
228 pager_command =
'/usr/bin/less'
229 elif os.path.exists(
'/bin/less'):
230 pager_command =
'/bin/less'
233 pager_command =
'more'
235 subprocess.call([pager_command, f.name])
237 os.system(
' '.join([pager_command, f.name]))
246 (error_code, pub_uuid, admin) = profile.send(uuiddb, uuid, user_agent=opts.user_agent,
247 smoonURL=opts.smoonURL,
248 timeout=opts.timeout,
250 batch=opts.cron_mode)
251 return (error_code, pub_uuid, admin)
257 from smolt
import error
261 (error_code, pub_uuid, admin) =
do_send_profile(uuiddb, uuid, profile, opts, proxies)
264 error(
_(
'Retry Enabled - Retrying'))
267 (error_code, pub_uuid, admin) =
do_send_profile(uuiddb, uuid, profile, opts, proxies)
269 print(
_(
'Could not send - Exiting'))
272 return (error_code, pub_uuid, admin)
280 pubUrl = smolt.get_profile_link(opts.smoonURL, pub_uuid)
282 print(
_(
'To share your profile: \n\t%s (public)') % pubUrl)
284 print(
_(
'\tAdmin Password: %s') % admin)
288 if opts.httpproxy
is None:
291 proxies = {
'http':opts.httpproxy}
301 profile = smolt.create_profile(gate, uuid)
303 sys.stderr.write(
_(
'%s\n' % e))
312 if not opts.password:
313 password = getpass.getpass(
'\n' +
_(
'Password:') +
' ')
315 password = opts.password
317 if profile.register(userName=opts.userName, password=password, user_agent=opts.user_agent, smoonURL=opts.smoonURL, timeout=opts.timeout):
318 print(
_(
'Registration Failed, Try again'))
323 from scan
import scan, rating
325 scan(profile, opts.smoonURL, gate)
327 rating(profile, opts.smoonURL, gate)
329 print(
"Could not get rating!")
336 print(
_(
'No Public UUID found! Please re-run with -n to generate a new public uuid'))
342 from smolt
import error, ServerError
345 pub_uuid = profile.regenerate_pub_uuid(uuiddb, uuid, user_agent=opts.user_agent,
346 smoonURL=opts.smoonURL,
347 timeout=opts.timeout)
348 except ServerError
as e:
349 error(
_(
'Error contacting server: %s') % str(e))
352 print(
_(
'Success! Your new public UUID is: %s' % pub_uuid))
362 for line
in profile.getProfile():
363 if not line.startswith(
'#'):
371 if not opts.autoSend:
374 (error_code, pub_uuid, admin) =
send_profile(uuiddb, uuid, profile, opts, proxies)
379 if opts.scan_remote
and not opts.cron_mode:
384 elif not opts.cron_mode:
392 from gate
import create_default_gate, create_gate_from_file
393 from uuiddb
import create_default_uuiddb
397 if opts.the_only_config_file
is None:
402 smolt.DEBUG = opts.DEBUG
403 smolt.hw_uuid_file = opts.uuidFile
409 uuid = smolt.read_uuid()
411 elif not opts.send_profile:
413 elif opts.printOnly
and not opts.autoSend:
417 uuid = smolt.read_uuid()
421if __name__ ==
'__main__':
def create_gate_from_file(filename)
def create_default_gate()
def scan(profile, smoonURL, gate)
def rating(profile, smoonURL, gate)
def send_profile(uuiddb, uuid, profile, opts, proxies)
def main_scan_only(profile, opts, gate)
def register_with_fedora_account_system(opts, profile)
def do_scan_remote(profile, opts, gate)
def read_profile(gate, uuid)
def make_display_excerpts(profile)
def main_print_only(profile)
def dump_excerpts(excerpts)
def do_send_profile(uuiddb, uuid, profile, opts, proxies)
def main_request_new_public_uuid(uuiddb, uuid, profile, opts)
def ensure_code_reachability()
def mention_profile_web_view(opts, pub_uuid, admin)
def present_and_require_confirmation(profile)
def mention_missing_uuid()
def main_send_profile(uuiddb, uuid, profile, opts, gate)
def to_ascii(o, current_encoding='utf-8')
def create_default_uuiddb()