def main(): if os.geteuid() != 0: exit("Comitup requires root privileges") args = parse_args() log = deflog() log.info("Starting comitup") (conf, data) = load_data() if args.check: if wificheck.run_checks(): sys.exit(1) else: sys.exit(0) else: wificheck.run_checks(verbose=False) webmgr.init_webmgr(conf.web_service) iptmgr.init_iptmgr() statemgr.init_state_mgr( conf, data, [ webmgr.state_callback, iptmgr.state_callback, cdns.state_callback, ], ) loop = MainLoop() loop.run()
def pydbus_server(): loop = MainLoop() bus = pydbus.SessionBus() try: bus.get('pydbus.unittest',timeout=1) except: with bus.publish("pydbus.unittest", PyDbusUnitTestService(loop)): loop.run()
class RoficationDbusService: def __init__(self, queue: NotificationQueue) -> None: # preserve D-Bus object reference self._object = RoficationDbusObject(queue) # create GLib mainloop, this is needed to make D-Bus work and takes care of catching signals. self._loop = MainLoop() def run(self) -> None: self._loop.run()
def ObjListUpdater(self): self.system_bus = pydbus.SystemBus() self.system_bus.subscribe(sender='org.bluez', signal='PropertiesChanged', signal_fired=self.Update_obj_list) loop = MainLoop() timeout_add(100, self.checkTerminate, loop) loop.run()
def main(): global log if os.geteuid() != 0: exit("Comitup requires root privileges") args = parse_args() (conf, data) = config.load_data() log = deflog(args.verbose or conf.getboolean("verbose")) log.info("Starting comitup") if args.info: for (key, val) in statemgr.get_info(conf, data).items(): print("{}: {}".format(key, val)) sys.exit(0) if args.check: if wificheck.run_checks(): sys.exit(1) else: sys.exit(0) else: wificheck.run_checks(verbose=False) check_environment(log) webmgr.init_webmgr(conf.web_service) iptmgr.init_iptmgr() statemgr.init_state_mgr( conf, data, [ webmgr.state_callback, iptmgr.state_callback, cdns.state_callback, ], ) nuke.init_nuke() signal.signal(signal.SIGTERM, handle_term) loop = MainLoop() try: loop.run() except Exception: log.error("Terminal exception encountered") raise finally: cleanup()
def main(): handler = logging.StreamHandler(stream=None) log.addHandler(handler) log.setLevel(logging.DEBUG) log.info('starting') init_state_mgr('comitup.local', 'comitup-1111.local') states.set_state('HOTSPOT', timeout=5) loop = MainLoop() loop.run()
def main(): handler = logging.StreamHandler(stream=None) log.addHandler(handler) log.setLevel(logging.DEBUG) log.info("starting") init_state_mgr("comitup.local", "comitup-1111.local") states.set_state("HOTSPOT", timeout=5) loop = MainLoop() loop.run()
def main(): handler = logging.StreamHandler(stream=None) log.addHandler(handler) log.setLevel(logging.DEBUG) log.info('starting') init_nmmon() def up(): print("wifi up") def down(): print("wifi down") enable(modemgr.get_ap_device(), up, down) loop = MainLoop() loop.run()
def main(): handler = logging.StreamHandler(stream=None) log.addHandler(handler) log.setLevel(logging.DEBUG) log.info('starting') init_nmmon() def up(): print("wifi up") def down(): print("wifi down") set_device_callbacks('HOTSPOT', up, down) loop = MainLoop() loop.run()
def main(): if os.geteuid() != 0: exit("Comitup requires root privileges") args = parse_args() log = deflog() log.info("Starting comitup") (conf, data) = config.load_data() if args.info: for (key, val) in statemgr.get_info(conf, data).items(): print("{}: {}".format(key, val)) sys.exit(0) if args.check: if wificheck.run_checks(): sys.exit(1) else: sys.exit(0) else: wificheck.run_checks(verbose=False) check_environment(log) webmgr.init_webmgr(conf.web_service) iptmgr.init_iptmgr() statemgr.init_state_mgr( conf, data, [ webmgr.state_callback, iptmgr.state_callback, cdns.state_callback, ], ) loop = MainLoop() loop.run()
set_hosts(*hosts) for callback in callbacks: add_state_callback(callback) hotspot_name = dns_to_conn(hosts[0]) assure_hotspot(hotspot_name, modemgr.get_ap_device()) def add_state_callback(callback): global state_callbacks state_callbacks.append(callback) if __name__ == '__main__': handler = logging.StreamHandler(stream=None) log.addHandler(handler) log.setLevel(logging.DEBUG) log.info("Starting") init_states('comitup.local', 'comitup-1111.local') set_state('HOTSPOT') # set_state('CONNECTING', candidate_connections()) loop = MainLoop() loop.run()
def main(self): main_loop = MainLoop() self.connect('ipc_shutdown', lambda self: main_loop.quit()) main_loop.run()
class BatteryMonitor: ''' Class for Battery Monitoring ''' def __init__(self, batn, design): self.bus = SystemBus() self.loop = MainLoop() self.bat = self.upower = None self.use_design_capacity = design self.bat_path = f'/org/freedesktop/UPower/devices/battery_BAT{batn}' def run(self): ''' Run the event loop ''' self.upower = self.bus.get('org.freedesktop.UPower', '/org/freedesktop/UPower') if self.bat_path in self.upower.EnumerateDevices(): self.add_battery(self.bat_path) else: self.upower.onDeviceAdded = self.add_battery # Handle SIGTERM and SIGINT signal endloop = lambda signum, fname: self.loop.quit() signal.signal(signal.SIGINT, endloop) signal.signal(signal.SIGTERM, endloop) self.loop.run() return 0 def add_battery(self, dev_path): ''' Add the battery when the battery exists ''' if dev_path == self.bat_path: self.upower.onDeviceRemoved = self.remove_battery if self.upower.onDeviceAdded is not None: self.upower.onDeviceAdded = None self.bat = self.bus.get('org.freedesktop.UPower', self.bat_path) self.bat.onPropertiesChanged = self.update_battery self.update_battery() def remove_battery(self, dev_path): ''' Remove the battery when the battery not exists ''' if dev_path == self.bat_path: self.upower.onDeviceAdded = self.add_battery self.upower.onDeviceRemoved = None self.bat.onPropertiesChanged = None self.bat = None self.update_battery() def update_battery(self, ifname=None, changed_props=None, invalid_props=None): ''' Print the updated battery info ''' del ifname, invalid_props if (changed_props is None) or (('Energy' in changed_props) or ('State' in changed_props)): text = '' css_class = '' if self.bat is not None: bat_state = BAT_STATE[self.bat.State] bat_energy_empty = self.bat.EnergyEmpty bat_energy_full = self.bat.EnergyFullDesign if \ self.use_design_capacity else self.bat.EnergyFull # Calculate the battery capacity percentage bat_capacity = 100 * (self.bat.Energy - bat_energy_empty) \ / (bat_energy_full - bat_energy_empty) # Find the battery capacity label for key, value in BAT_LEVEL.items(): if bat_capacity <= key: bat_level = value break if bat_state['class'] == BAT_STATE[2]['class']: if bat_capacity <= BAT_STATE[2]['crit']['level']: css_class = BAT_STATE[2]['crit']['class'] elif bat_capacity <= BAT_STATE[2]['warn']['level']: css_class = BAT_STATE[2]['warn']['class'] if css_class == '': css_class = bat_state['class'] text = f"{bat_state['label']}{bat_level}{bat_capacity:.2f}%" print(f'{{"text": "{text}", "class": "{css_class}"}}', flush=True)
class Daemon(ManagesProcesses): INTERFACE_NAME = "pro.wizardsoftheweb.pyrofibus.daemon" dbus = """ <node> <interface name='{}'> <method name='is_running'> <arg type='b' name='response' direction='out'/> </method> <method name='start'> </method> <method name='stop'> </method> <method name='load_apps'> <arg type='i' name='response' direction='out'/> </method> </interface> </node> """.format(INTERFACE_NAME) _is_running = False def __init__(self, bus=None, loop=None, *args, **kwargs): super(Daemon, self).__init__(*args, **kwargs) self.initialize_bus(bus, loop) def initialize_bus(self, bus=None, loop=None): if bus is None: self.bus = SessionBus() else: self.bus = bus if loop is None: self.loop = MainLoop() else: self.loop = loop self.bus.publish(self.INTERFACE_NAME, self) def start(self): if not self._is_running: try: self._is_running = True self.loop.run() except KeyboardInterrupt: self.loop.quit() self._is_running = False def is_running(self): return self._is_running def stop(self): self.loop.quit() self._is_running = False def load_apps(self): old_length = len(self.managed_processes) new_scripts = self.check_for_new_scripts() self.load_new_scripts(new_scripts) new_length = len(self.managed_processes) return new_length - old_length @classmethod def bootstrap(cls): daemon = cls() daemon.start()