def main(args): ''' Run the API server ''' try: options, arguments = getopt.getopt(args[1:], 'O:v') except getopt.error: sys.exit('usage: neubot background_api [-v] [-O setting]') if arguments: sys.exit('usage: neubot background_api [-v] [-O setting]') settings = [] for name, value in options: if name == '-O': settings.append(value) elif name == '-v': LOG.verbose() settings = utils_rc.parse_safe(iterable=settings) if not 'address' in settings: settings['address'] = '127.0.0.1 ::1' if not 'port' in settings: settings['port'] = '9774' start(settings['address'], settings['port']) POLLER.loop()
def main(args): ''' Main function ''' try: options, arguments = getopt.getopt(args[1:], 'D:t:v') except getopt.error: sys.exit('usage: notifier_browser [-v] [-D setting] [-t time] page...') if not arguments: sys.exit('usage: notifier_browser [-v] [-D setting] [-t time] page...') sleeptime = 0 for name, value in options: if name == '-D': CONFIG.register_property(value) elif name == '-t': sleeptime = int(value) elif name == '-v': LOG.verbose() CONFIG.merge_properties() for argument in arguments: if argument == 'privacy': NOTIFIER_BROWSER.notify_bad_privacy() elif argument == 'update': NOTIFIER_BROWSER.notify_update_avail() else: sys.exit('Invalid page. Valid pages are: privacy, update') if sleeptime: logging.debug('notifier_browser: sleep for %d seconds', sleeptime) time.sleep(sleeptime)
def main(): ''' Merge Neubot databases ''' syslog.openlog('merge.py', syslog.LOG_PERROR, syslog.LOG_USER) output = 'database.sqlite3' try: options, arguments = getopt.getopt(sys.argv[1:], 'o:v') except getopt.error: sys.exit('Usage: merge.py [-v] [-o output] file...') if not arguments: sys.exit('Usage: merge.py [-v] [-o output] file...') for name, value in options: if name == '-o': output = value elif value == '-v': LOG.verbose() beginning = {} destination = __sqlite3_connect(output) for argument in arguments: source = __sqlite3_connect(argument) for table in ('speedtest', 'bittorrent'): # Just in case there are overlapping measurements beginning[table] = __lookup_last(destination, table) __copy_table(source, destination, table, beginning[table]) destination.commit()
def main(args): ''' main() function ''' try: options, arguments = getopt.getopt(args[1:], 'vy') except getopt.error: sys.exit('neubot updater_runner [-vy] [version]') if len(arguments) > 1: sys.exit('neubot updater_runner [-vy] [version]') privacy = False for tpl in options: if tpl[0] == '-v': LOG.verbose() elif tpl[0] == '-y': privacy = True # Honor -y and force privacy permissions if privacy: CONFIG.conf.update({'privacy.informed': 1, 'privacy.can_collect': 1, 'privacy.can_publish': 1}) updater = UpdaterRunner('win32', os.path.dirname(ROOTDIR)) if arguments: updater.retrieve_files(arguments[0]) else: # Enable automatic updates if we arrive here CONFIG.conf['win32_updater'] = 1 updater.retrieve_versioninfo() POLLER.loop()
def main(args): daemonize = True blink = False nohide = True try: options, arguments = getopt.getopt(args[1:], "BdnqVv", ["help"]) except getopt.GetoptError: sys.stderr.write(USAGE % args[0]) sys.exit(1) for name, value in options: if name == "-B": blink = True elif name == "-d": daemonize = False elif name == "--help": sys.stdout.write(HELP % args[0]) sys.exit(0) elif name == "-n": nohide = True elif name == "-q": nohide = False elif name == "-V": sys.stderr.write(VERSION + "\n") sys.exit(0) elif name == "-v": LOG.verbose() if len(arguments) >= 3: sys.stderr.write(USAGE % args[0]) sys.exit(1) elif len(arguments) == 2: address = arguments[0] port = arguments[1] elif len(arguments) == 1: address = ADDRESS port = arguments[0] else: address = ADDRESS port = PORT if daemonize: system.change_dir() system.go_background() LOG.redirect() system.drop_privileges(LOG.error) gtk.gdk.threads_init() icon = StatusIcon(address, port, blink, nohide) tracker = StateTrackerThread(icon, address, port) tracker.daemon = True tracker.start() gtk.gdk.threads_enter() gtk.main() gtk.gdk.threads_leave() tracker.interrupt()
def main(args): """ main() function """ logger = logging.getLogger() logger.setLevel(logging.DEBUG) LOG.verbose() ctx = {"uri": args[1]} RunnerDload(ctx) POLLER.loop()
def main(name, descr, args): Eflag = False lflag = False try: options, arguments = getopt.getopt(args[1:], "D:Ef:lVv", ["help"]) except getopt.GetoptError: write_help(sys.stderr, name, descr) sys.exit(1) if arguments: write_help(sys.stderr, name, descr) sys.exit(1) for key, value in options: if key == "-D": # No shortcuts because it grows too confusing CONFIG.register_property(value) elif key == "-E": Eflag = True elif key == "-f": DATABASE.set_path(value) elif key == "--help": write_help(sys.stdout, name, descr) sys.exit(0) elif key == "-l": lflag = True elif key == "-V": sys.stdout.write(VERSION + "\n") sys.exit(0) elif key == "-v": LOG.verbose() DATABASE.connect() CONFIG.merge_database(DATABASE.connection()) if not Eflag: CONFIG.merge_environ() CONFIG.merge_properties() if lflag: CONFIG.print_descriptions(sys.stdout) sys.exit(0)
def main(args): ''' Main() function ''' try: options, arguments = getopt.getopt(args[1:], 'nO:vy') except getopt.error: sys.exit('usage: neubot background_rendezvous [-nvy] [-O setting]') if arguments: sys.exit('usage: neubot background_rendezvous [-nvy] [-O setting]') notest = False fakeprivacy = False settings = [] for name, value in options: if name == '-n': notest = True elif name == '-O': settings.append(value) elif name == '-v': LOG.verbose() elif name == '-y': fakeprivacy = True # Fake privacy settings if fakeprivacy: CONFIG.conf.update({ 'privacy.informed': 1, 'privacy.can_collect': 1, 'privacy.can_publish': 1 }) if notest: CONFIG.conf.update({'enabled': 0}) settings = utils_rc.parse_safe(iterable=settings) if 'interval' in settings: CONFIG.conf['agent.interval'] = settings['interval'] BACKGROUND_RENDEZVOUS.run() POLLER.loop()
def main(args): ''' main() function ''' try: options, arguments = getopt.getopt(args[1:], 'vy') except getopt.error: sys.exit('usage: neubot runner_rendezvous [-vy] uri') if len(arguments) != 1: sys.exit('usage: neubot runner_rendezvous [-vy] uri') for tpl in options: if tpl[0] == '-v': LOG.verbose() elif tpl[0] == '-y': CONFIG.conf.update({ 'privacy.informed': 1, 'privacy.can_collect': 1, 'privacy.can_publish': 1 }) run(arguments[0]) POLLER.loop()
def main(args): ''' Main function ''' try: options, arguments = getopt.getopt(args[1:], 'lO:v') except getopt.error: sys.exit('usage: neubot bittorrent_peer [-lv] [-O setting]') if arguments: sys.exit('usage: neubot bittorrent_peer [-lv] [-O setting]') settings = [ 'address "127.0.0.1 ::1"', 'port 6881', 'version 1' ] listener = False for name, value in options: if name == '-l': listener = True elif name == '-O': settings.append(value) elif name == '-v': LOG.verbose() settings = utils_rc.parse_safe(iterable=settings) config_copy = CONFIG.copy() config.finalize_conf(config_copy) peer = PeerNeubot(POLLER) peer.configure(config_copy) # BLEAH peer.version = int(settings['version']) if not listener: peer.connect((settings['address'], int(settings['port']))) else: peer.listen((settings['address'], int(settings['port']))) POLLER.loop()
if __name__ == "__main__": # Make sure the hackish name substitution works assert(logging.info == _log_info) LOG.start("Testing the in-progress feature") LOG.progress("...") LOG.progress() LOG.complete("success!") logging.info("INFO w/ logging.info") # The following should work because it should not interpolate logging.debug("DEBUG w/ logging.debug", "ciao") logging.warning("WARNING w/ logging.warning") logging.error("ERROR w/ logging.error") LOG.verbose() logging.info("INFO w/ logging.info") logging.debug("DEBUG w/ logging.debug") logging.warning("WARNING w/ logging.warning") logging.error("ERROR w/ logging.error") LOG.error("testing neubot logger -- This is an error message") LOG.warning("testing neubot logger -- This is an warning message") LOG.info("testing neubot logger -- This is an info message") LOG.debug("testing neubot logger -- This is a debug message") print compat.json.dumps(LOG.listify()) try: raise Exception("Testing LOG.exception") except (KeyboardInterrupt, SystemExit):