def main(): ensure_code_reachability() from i18n import _ import smolt from gate import create_default_gate, create_gate_from_file from uuiddb import create_default_uuiddb (opts, args) = command_line() if opts.the_only_config_file is None: gate = create_default_gate() else: gate = create_gate_from_file(opts.the_only_config_file) smolt.DEBUG = opts.DEBUG smolt.hw_uuid_file = opts.uuidFile profile = read_profile(gate, smolt.read_uuid()) if opts.new_pub: uuiddb = create_default_uuiddb() uuid = smolt.read_uuid() main_request_new_public_uuid(uuiddb, uuid, profile, opts) elif not opts.send_profile: main_scan_only(profile, opts) elif opts.printOnly and not opts.autoSend: main_print_only(profile) else: uuiddb = create_default_uuiddb() uuid = smolt.read_uuid() main_send_profile(uuiddb, uuid, profile, opts, gate)
def main(): sys.path.append('/usr/share/smolt/client') from i18n import _ import smolt from smolt import error, debug, get_profile_link, PubUUIDError from uuiddb import create_default_uuiddb def serverMessage(page): for line in page.split("\n"): if 'ServerMessage:' in line: error(_('Server Message: "%s"') % line.split('ServerMessage: ')[1]) if 'Critical' in line: sys.exit(3) parser = OptionParser(version = smolt.smoltProtocol) parser.add_option('-d', '--debug', dest = 'DEBUG', default = False, action = 'store_true', help = _('enable debug information')) parser.add_option('-s', '--server', dest = 'smoonURL', default = smolt.smoonURL, metavar = 'smoonURL', help = _('specify the URL of the server (default "%default")')) parser.add_option('-p', '--printOnly', dest = 'printOnly', default = False, action = 'store_true', help = _('print information only, do not send')) parser.add_option('-u', '--useragent', dest = 'user_agent', default = smolt.user_agent, metavar = 'USERAGENT', help = _('specify HTTP user agent (default "%default")')) parser.add_option('-t', '--timeout', dest = 'timeout', type = 'float', default = smolt.timeout, help = _('specify HTTP timeout in seconds (default %default seconds)')) parser.add_option('--uuidFile', dest = 'uuidFile', default = smolt.hw_uuid_file, help = _('specify which uuid to use, useful for debugging and testing mostly.')) (opts, args) = parser.parse_args() smolt.DEBUG = opts.DEBUG smolt.hw_uuid_file = opts.uuidFile grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent, timeout=opts.timeout) uuid = smolt.read_uuid() delHostString = 'uuid=%s' % uuid # Try retrieving current pub_uuid (from cache or remotely if necessary) pub_uuid = None try: pub_uuid = smolt.read_pub_uuid(create_default_uuiddb(), uuid, silent=True) except PubUUIDError: pass try: o=grabber.urlopen(urljoin(opts.smoonURL + '/', '/client/delete'), data=delHostString, http_headers=( ('Content-length', '%i' % len(delHostString)), ('Content-type', 'application/x-www-form-urlencoded'))) except urlgrabber.grabber.URLGrabError, e: sys.stderr.write(_('Error contacting Server:')) sys.stderr.write(str(e)) sys.stderr.write('\n') sys.exit(1)