def run_event_loop(): bus = SystemBus() logger.debug('Publishing interface %s on DBus', constants.DEPUTY_DBUS_NAME) config = get_config() bus.publish(constants.DEPUTY_DBUS_NAME, HadesDeputyService(bus, config)) loop = GLib.MainLoop() loop.run()
def start(self, median_path, config_path, db_path): # Always start in standby self.set_state(State.STANDBY) # Start up camera self.snapper = Snapper(logger) # Start up solver self.solver = Solver(logger) self.solver.startup(median_path, config_path, db_path) # Start solver thread self.s_thread.start() logger.info("Started solver thread.") # Start up D-Bus server bus = SystemBus() loop = GLib.MainLoop() bus.publish(self.interface_name, self) try: logger.info("Starting D-Bus loop.") loop.run() except KeyboardInterrupt as e: loop.quit() logger.info("Ended D-Bus loop.") self.end()
def start(self, median_path, config_path, db_path, sample_dir=None): if (DEBUG_ENABLED): global STACK_LAYERS print(f"{STACK_LAYERS * ' '}Inside Server.start") STACK_LAYERS = STACK_LAYERS + 1 # Start up star tracker self.st.startup(median_path, config_path, db_path, sample_dir=sample_dir) time.sleep(20) self.st_thread.start() logger.info("Started worker thread") # Start up D-Bus server bus = SystemBus() loop = GLib.MainLoop() bus.publish(self.interface_name, self) try: logger.info("Starting D-Bus loop...") loop.run() except KeyboardInterrupt as e: loop.quit() logger.info("Ended D-Bus loop") self.end() if (DEBUG_ENABLED): STACK_LAYERS = STACK_LAYERS - 1 print(f"{STACK_LAYERS * ' '}End Server.start")
def run_event_loop(): bus = SystemBus() logger.debug('Publishing interface %s on DBus', constants.DEPUTY_DBUS_NAME) config = get_config() bus.publish(constants.DEPUTY_DBUS_NAME, HadesDeputyService(bus, config)) loop = GLib.MainLoop() loop.run()
def main(): """The main for the oresat linux updater daemon""" ret = 0 pid_file = "/run/oresat-linux-updaterd.pid" parser = ArgumentParser() parser.add_argument("-d", "--daemon", action="store_true", help="daemonize the process") parser.add_argument("-v", "--verbose", action="store_true", help="enable debug log messaging") parser.add_argument("-w", "--work-dir", dest="work_dir", default=WORK_DIR, help="override the working directory") parser.add_argument("-c", "--cache-dir", dest="cache_dir", default=CACHE_DIR, help="override the update archive cache directory") args = parser.parse_args() if args.daemon: _daemonize(pid_file) log_handler = SysLogHandler(address="/dev/log") else: log_handler = logging.StreamHandler(sys.stderr) # turn on logging for debug messages if args.verbose: level = logging.DEBUG else: level = logging.INFO logging.basicConfig(level=level, handlers=[log_handler]) log = logging.getLogger('oresat-linux-updater') # make updater updater = DBusServer(args.work_dir, args.cache_dir, log) # set up dbus wrapper bus = SystemBus() bus.publish(DBUS_INTERFACE_NAME, updater) loop = GLib.MainLoop() try: updater.run() loop.run() except KeyboardInterrupt: updater.quit() loop.quit() except Exception as exc: # this should not happen log.critical(exc) updater.quit() loop.quit() ret = 1 if args.daemon: os.remove(pid_file) # clean up daemon return ret
def publish(self): """Make the dbus interface available.""" bus = SystemBus() try: bus.publish(BUS_NAME, self) except RuntimeError as error: logger.error('Is the service is already running? %s', str(error)) sys.exit(1)
def main(): """ Main init """ # Init dbus service dbusloop = GLib.MainLoop() dbus_session = SystemBus() # Init git watcher first so we can get pull (external) running status mygitwatcher = GitWatcher(pathdir, name='Git Watcher Daemon', daemon=True) # Init gitmanager object through GitDbus class mygitmanager = GitDbus(interval=args.pull, pathdir=pathdir) # Get running kernel mygitmanager.get_running_kernel() # Update all attributes # Recompute enable mygitmanager.pull['recompute'] = True mygitmanager.check_pull( init_run=True) # We need this to print logger.info only one time mygitmanager.get_installed_kernel() mygitmanager.get_all_kernel() mygitmanager.get_available_update('kernel') mygitmanager.get_branch('all') mygitmanager.get_available_update('branch') # Adding objects to manager mygit = {} mygit['manager'] = mygitmanager mygit['watcher'] = mygitwatcher # Adding dbus publisher dbus_session.publish('net.gikeud.Manager.Git', mygitmanager) # Init thread daemon_thread = MainDaemon(mygit, name='Main Daemon Thread', daemon=True) # Start all threads and dbus thread mygit['watcher'].start() daemon_thread.start() dbusloop.run() daemon_thread.join() mygit['watcher'].join()
def run(): bus = SystemBus() r = bus.publish('org.fanatec.CSLElite', CSLElite(), ('Pedals', CSLElitePedals()), ('Wheel', CSLEliteWheel())) try: loop = GLib.MainLoop() loop.run() except (KeyboardInterrupt, SystemExit): print("Exiting") except Exception as e: raise e finally: r.unpublish()
def Start(self): bus = SystemBus() # publish our own Bluez 5 Profile1 interface on the system DBus bus.publish('lapets.bluetooth.serial', self) # get a proxy object for org.bluez at path /org/bluez # using the interface org.bluez.ProfileManager1 profile_mgr = bus.get('org.bluez', '/org/bluez')['.ProfileManager1'] # tell Bluez that our interface implements the SPP protocol spp_obj_path = '/lapets/bluetooth/serial' spp_uuid = '00001101-0000-1000-8000-00805f9b34fb' spp_options = { 'Name': GLib.Variant('s', 'BT Serial Port'), 'Role': GLib.Variant('s', 'server'), 'Channel': GLib.Variant('i', 6) } try: profile_mgr.RegisterProfile(spp_obj_path, spp_uuid, spp_options) except GLib.Error as e: # unapologetic C-style profanity switch = { 36: lambda err: print( "Service profile already exists!\n(GLib says: %s)" % str( err)) } if e.code in switch: switch[e.code](e) else: raise print('Awaiting connection...') loop = GLib.MainLoop() loop.run()
def readif(fn): with open('/usr/share/dbus-1/interfaces/' + fn, 'rb') as f: # for some reason Gio can't seem to handle XML entities declared inline return f.read().decode('utf-8') \ .replace('&ERROR_CLAIM_DEVICE;', 'net.reactivated.Fprint.Error.ClaimDevice') \ .replace('&ERROR_ALREADY_IN_USE;', 'net.reactivated.Fprint.Error.AlreadyInUse') \ .replace('&ERROR_INTERNAL;', 'net.reactivated.Fprint.Error.Internal') \ .replace('&ERROR_PERMISSION_DENIED;', 'net.reactivated.Fprint.Error.PermissionDenied') \ .replace('&ERROR_NO_ENROLLED_PRINTS;', 'net.reactivated.Fprint.Error.NoEnrolledPrints') \ .replace('&ERROR_NO_ACTION_IN_PROGRESS;', 'net.reactivated.Fprint.Error.NoActionInProgress') \ .replace('&ERROR_INVALID_FINGERNAME;', 'net.reactivated.Fprint.Error.InvalidFingername') \ .replace('&ERROR_NO_SUCH_DEVICE;', 'net.reactivated.Fprint.Error.NoSuchDevice') Device.dbus = [readif('net.reactivated.Fprint.Device.xml')] Manager.dbus = [readif('net.reactivated.Fprint.Manager.xml')] bus = SystemBus() bus.publish('net.reactivated.Fprint', ('/net/reactivated/Fprint/Manager', Manager()), ('/net/reactivated/Fprint/Device/0', Device())) open97() usb.trace_enabled = True tls.trace_enabled = True loop.run() print("Normal exit")
print("From Client 1: This is message {}".format(message_count)) message_count += 1 return def timer(): "Emit a random integer each call." random_integer = random.randint(0, 100) print("Random integer emitted: {}".format(random_integer)) emit.integer_signal(random_integer) return True if __name__ == "__main__": emit = DBusService_XML() bus.publish(BUS, emit) GLib.timeout_add_seconds(interval=INTERVAL, function=timer) loop.run() ''' This is the system-local file after it has had a hole punched in it... $ cd /etc/dbus-1/ $ ls session.d system.d system-local.conf $ cat system-local.conf <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> <busconfig> <policy context="default">
<method name='EchoString'> <arg type='s' name='question' direction='in'/> <arg type='s' name='response' direction='out'/> </method> <method name='Quit'/> </interface> </node> """ def EchoString(self, s): """returns whatever is passed to it""" logging.debug("%s: EchoString %s" % (self.__class__.__name__, s)) return s def Quit(self): """removes the object from the DBUS connection and exits""" logging.debug("%s: Quit" % self.__class__.__name__) GLib.timeout_add_seconds(1, loop.quit) def initialize(self): """initialize boss before publishing""" logging.debug("%s: intialize started" % self.__class__.__name__) time.sleep(random.randrange(4)) logging.debug("%s: intialize finished" % self.__class__.__name__) bus = SystemBus() module = Storage() module.initialize() bus.publish("org.freedesktop.Anaconda.Module.Storage", module) loop.run()
def main(): """ Main """ # Ok so first parse argvs myargsparser = DaemonParserHandler(pathdir, __version__) args = myargsparser.parsing() # Then configure logging if sys.stdout.isatty(): from syuppo.logger import LogLevelFormatter # configure the root logger logger = logging.getLogger() # Rename root logger logger.root.name = f'{__name__}' console_handler = logging.StreamHandler() console_handler.setFormatter(LogLevelFormatter()) logger.addHandler(console_handler) # Default to info logger.setLevel(logging.INFO) # Working with xfce4-terminal and konsole if set to '%w' # TODO For a better approch ? see [1] # [1]: https://gitweb.gentoo.org/proj/portage.git/tree/lib/portage/output.py?id=03d4c33f48eb5e98c9fdc8bf49ee239489229b8e print(f'\33]0;{prog_name} - version: {__version__}\a', end='', flush=True) else: # configure the root logger logger = logging.getLogger() # Rename root logger logger.root.name = f'{__name__}' # Add debug handler only if debug is enable handlers = {} if args.debug and not args.quiet: # Ok so it's 5MB each, rotate 3 times = 15MB TEST debug_handler = logging.handlers.RotatingFileHandler( pathdir['debuglog'], maxBytes=5242880, backupCount=3) debug_formatter = logging.Formatter('%(asctime)s %(name)s' ' %(message)s') debug_handler.setFormatter(debug_formatter) # For a better understanding get # all level message for debug log debug_handler.addFilter(LogLevelFilter(50)) debug_handler.setLevel(10) handlers['debug'] = debug_handler # Other level goes to Syslog syslog_handler = logging.handlers.SysLogHandler(address='/dev/log', facility='daemon') syslog_formatter = logging.Formatter(f'{prog_name} %(levelname)s' ' %(message)s') syslog_handler.setFormatter(syslog_formatter) syslog_handler.setLevel(20) handlers['syslog'] = syslog_handler # Add handlers for handler in handlers.values(): logger.addHandler(handler) # Set log level logger.setLevel(logging.INFO) # Then, pre-check if not sys.stdout.isatty(): display_init_tty = f"Log are located to {pathdir['debuglog']}" # Check for --dryrun if args.dryrun: logger.error("Running --dryrun from /etc/init.d/" " is NOT supported.") logger.error("Exiting with status 1.") sys.exit(1) elif sys.stdout.isatty(): from getpass import getuser display_init_tty = '' logger.info('Interactive mode detected, all logs go to terminal.') # Just check if user == 'syuppod' running_user = getuser() if not running_user == 'syuppod': logger.error("Running program from terminal require to run as" f" syuppod user (current: {running_user}).") logger.error("Exiting with status '1'.") sys.exit(1) # Check if directories exists if not args.dryrun: # Check basedir and logdir directories for directory in 'basedir', 'logdir': if not pathlib.Path(pathdir[directory]).is_dir(): # Ok so exit because we cannot manage this: # Program have to been run as syuppod # BUT creating directories have to be run as root... logger.error(f"Missing directory: '{pathdir[directory]}'.") logger.error("Exiting with status '1'.") sys.exit(1) else: logger.warning("Dryrun is enabled, skipping all write process.") # Setup level logging (default = INFO) if args.debug and args.quiet: logger.info("Both debug and quiet opts have been enabled," " falling back to log level info.") elif args.debug: logger.setLevel(logging.DEBUG) logger.info(f"Debug is enabled. {display_init_tty}") logger.debug("Messages are from this form " "'::module::class::method:: msg'.") elif args.quiet: logger.setLevel(logging.ERROR) if args.nodbus: logger.warning("Dbus binding is DISABLED.") else: # Init dbus service dbusloop = GLib.MainLoop() dbus_session = SystemBus() # Init manager manager = PortageDbus(interval=args.sync, pathdir=pathdir, dryrun=args.dryrun, vdebug=args.vdebug) # Init Dynamic Daemon dynamic_daemon = DynamicDaemon(pathdir, manager, name='Dynamic Daemon Thread', daemon=True) # Check sync # Don't need to lock here manager.check_sync(init=True, recompute=True) # Get last portage package # Better first call here because this won't be call # before DynamicDaemon detected close_write manager.available_portage_update(init=True) # Same here: Check if global update have been run manager.get_last_world_update() dbus_daemon = False if not args.nodbus: dbus_daemon = dbusloop failed_access = re.compile(r'^.*AccessDenied.*is.not.allowed.to' r'.own.the.service.*due.to.security' r'.policies.in.the.configuration.file.*$') busconfig = False if not args.nodbus: busconfig = True # Adding dbus publisher try: dbus_session.publish('net.syuppod.Manager.Portage', manager) except GLib.GError as error: error = str(error) if failed_access.match(error): logger.error(f"{error}") logger.error(f"Try to copy configuration file: '{dbus_conf}'" " to '/usr/share/dbus-1/system.d/'" " and restart the daemon.") else: logger.error(f"Unexcept error: {error}") logger.error("Dbus bindings have been DISABLED !") busconfig = False # Init daemon thread regular_daemon = RegularDaemon(manager, dbus_daemon, dynamic_daemon, name='Regular Daemon Thread', daemon=True) logger.info('Start up completed.') # Start all threads and dbus thread dynamic_daemon.start() regular_daemon.start() if busconfig: logger.debug('Running dbus loop using Glib.MainLoop().') dbusloop.run() # Exiting gracefully # Glib.MainLoop is shut down in MainDaemonThread regular_daemon.join() logger.debug('Sending exit request to Dynamic Daemon thread.') start_time = timing_exit() dynamic_daemon.exit = True # Wait for the event dynamic_daemon.exiting.wait() end_time = timing_exit() logger.debug("Dynamic Daemon thread have been shut down in" f" {end_time - start_time} second(s).") dynamic_daemon.join() # Every thing done logger.info('...exiting, ...bye-bye.') sys.exit(0)
<method name='EchoString'> <arg type='s' name='question' direction='in'/> <arg type='s' name='response' direction='out'/> </method> <method name='Quit'/> </interface> </node> """ def EchoString(self, s): """returns whatever is passed to it""" logging.debug("%s: EchoString %s" % (self.__class__.__name__, s)) return s def Quit(self): """removes the object from the DBUS connection and exits""" logging.debug("%s: Quit" % self.__class__.__name__) GLib.timeout_add_seconds(1, loop.quit) def initialize(self): """initialize boss before publishing""" logging.debug("%s: intialize started" % self.__class__.__name__) time.sleep(random.randrange(4)) logging.debug("%s: intialize finished" % self.__class__.__name__) bus = SystemBus() module = Pony() module.initialize() bus.publish("org.freedesktop.Anaconda.Addon.Pony", module) loop.run()
self.last_speed_set[target] = new_speed[target] self.kraken_device.set_fixed_speed( target, new_speed[target]) def on_timer(self): try: self.update_speed() except Exception as error: raise SystemError(error) return True if __name__ == '__main__': elevate() configMgr = KrakenControllerConfig() configMgr.readConfig() configMgr.writeConfig() dbus_iface = KrakenControllerDBUS(configMgr) controller = KrakenController(dbus_iface, configMgr) if configMgr.config['enable_dbus']: bus = SystemBus() bus.publish("net.mjjw.KrakenController", dbus_iface) GLib.timeout_add(controller.CHECK_INTERVAL * 1000, lambda: controller.on_timer()) loop = GLib.MainLoop() loop.run()
class Service: """ <node> <interface name='soundcraft.utils.notepad'> <property name='version' type='s' access='read' /> <property name='devices' type='ao' access='read'> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/> </property> <signal name='Added'> <arg name='path' type='o'/> </signal> <signal name='Removed'> <arg name='path' type='o'/> </signal> <method name='Shutdown'/> </interface> </node> """ InterfaceName = "soundcraft.utils.notepad" PropertiesChanged = signal() Added = signal() Removed = signal() def __init__(self): self.object = None self.bus = SystemBus() self.udev = GUdev.Client(subsystems=["usb/usb_device"]) self.udev.connect("uevent", self.uevent) self.loop = GLib.MainLoop() self.busname = self.bus.publish(BUSNAME, self) def run(self): self.tryRegister() if not self.hasDevice(): print(f"Waiting for one to arrive...") self.loop.run() @property def version(self): return soundcraft.__version__ @property def devices(self): if self.hasDevice(): return [self.object._path] return [] def Shutdown(self): print("Shutting down") self.unregister() self.loop.quit() def objPath(self, idx): return f"/soundcraft/utils/notepad/{idx}" def tryRegister(self): if self.hasDevice(): print( f"There is already a {self.object._wrapped._dev.name} on the bus at {self.object._path}" ) return dev = soundcraft.notepad.autodetect() if dev is None: print(f"No recognised device was found") return # Reset any stored state dev.resetState() path = self.objPath(0) wrapped = NotepadDbus(dev) self.object = self.bus.register_object(path, wrapped, None) self.object._wrapped = wrapped self.object._path = path print( f"Presenting {self.object._wrapped._dev.name} on the system bus as {path}" ) self.Added(path) self.PropertiesChanged(self.InterfaceName, {"devices": self.devices}, []) def hasDevice(self): return self.object is not None def unregister(self): if not self.hasDevice(): return path = self.object._path print( f"Removed {self.object._wrapped._dev.name} AKA {path} from the system bus" ) self.object.unregister() self.object = None self.PropertiesChanged(self.InterfaceName, {"devices": self.devices}, []) self.Removed(path) def uevent(self, observer, action, device): if action == "add": idVendor = device.get_property("ID_VENDOR_ID") idProduct = device.get_property("ID_PRODUCT_ID") if idVendor == "05fc": print( f"Checking new Soundcraft device ({idVendor}:{idProduct})..." ) self.tryRegister() if not self.hasDevice(): print( f"Contact the developer for help adding support for your advice" ) elif action == "remove" and self.hasDevice(): # UDEV adds leading 0s to decimal numbers. They're not octal. Why?? busnum = int(device.get_property("BUSNUM").lstrip("0")) devnum = int(device.get_property("DEVNUM").lstrip("0")) objectdev = self.object._wrapped._dev.dev if busnum == objectdev.bus and devnum == objectdev.address: self.unregister()
<method name='EchoString'> <arg type='s' name='question' direction='in'/> <arg type='s' name='response' direction='out'/> </method> <method name='Quit'/> </interface> </node> """ def EchoString(self, s): """returns whatever is passed to it""" logging.debug("%s: EchoString %s" % (self.__class__.__name__, s)) return s def Quit(self): """removes the object from the DBUS connection and exits""" logging.debug("%s: Quit" % self.__class__.__name__) GLib.timeout_add_seconds(1, loop.quit) def initialize(self): """initialize boss before publishing""" logging.debug("%s: intialize started" % self.__class__.__name__) time.sleep(random.randrange(4)) logging.debug("%s: intialize finished" % self.__class__.__name__) bus = SystemBus() module = Monitor() module.initialize() bus.publish("org.freedesktop.Anaconda.Addon.Monitor", module) loop.run()
async def emit_random_number(): "Emit a message every second with random integer between 0 and 100." while True: x = random.randrange(100) message = "The random integer for this second is {}".format(x) print("Server:", message) emit.app_signal(message) await asyncio.sleep(1) if __name__=="__main__": print("Server starting") # Setup server to emit signals over the DBus emit = Server_XML() bus.publish(iface_name, emit) # Add tasks loop.create_task(emit_random_number()) loop.run_forever() ''' Example of running the server... $ python3 server_test.py Server starting Server: The random integer for this second is 45 Server: The random integer for this second is 11 Server: The random integer for this second is 19 Example: Using gdbus to check server program is emitting OK...
def run_server(self, processor): loop = GLib.MainLoop() bus = SystemBus() bus.publish(DBUS_NAME, Service(processor)) loop.run()
def __init__(self): self.token = "" self.server_url = "" def GetJwtToken(self): return self.token, self.server_url def FetchJwtToken(self): return True JwtTokenStateChange = signal() def MockSetJwtToken(self, token, server_url): self.token = token self.server_url = server_url return True def MockSetJwtTokenAndEmitSignal(self, token, server_url): self.token = token self.server_url = server_url self.JwtTokenStateChange(self.token, self.server_url) return True loop = GLib.MainLoop() bus = SystemBus() service = IoMenderAuthenticationIface() bus.publish("io.mender.AuthenticationManager", service) print("Mock for D-Bus interface io.mender.Authentication1 ready") loop.run()
def __init__(self): pass def receive_signal(self, value): """adds a drive to the list to ensure its toggle value and other information can be maintained""" self.signalReceived(value) def quit(self): """removes this object from the DBUS connection and exits""" loop.quit() bus = SystemBus() loop = GLib.MainLoop() option = "" if len(sys.argv) > 1: option = sys.argv[1] if option == "start": try: bus.publish("us.rbasn.systemd.test", SystemdTestDaemon()) loop.run() except GLib.Error as e: print(str(e)) else: try: bus.get("us.rbasn.systemd.test").quit() except GLib.Error as e: loop.quit()
def main(api_endpoint, credentials, project_id, device_model_id, device_id, device_config, lang, verbose, input_audio_file, output_audio_file, audio_sample_rate, audio_sample_width, audio_iter_size, audio_block_size, audio_flush_size, grpc_deadline, once, *args, **kwargs): """Samples for the Google Assistant API. Examples: Run the sample with microphone input and speaker output: $ python -m googlesamples.assistant Run the sample with file input and speaker output: $ python -m googlesamples.assistant -i <input file> Run the sample with file input and output: $ python -m googlesamples.assistant -i <input file> -o <output file> """ # Setup logging. logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO) # Load OAuth 2.0 credentials. try: with open(credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) http_request = google.auth.transport.requests.Request() credentials.refresh(http_request) except Exception as e: logging.error('Error loading credentials: %s', e) logging.error('Run google-oauthlib-tool to initialize ' 'new OAuth 2.0 credentials.') sys.exit(-1) # D-Bus preparation cv_trigger = Condition(Lock()) eventq = Queue() dbus_obj = DBusSignals() loop = GLib.MainLoop() system_bus = SystemBus() def dbus_handler(sender, object, iface, signal, params): # logging.info(sender) # logging.info(object) # logging.info(signal) # logging.info(params) logging.debug('Received D-Bus signal: {}'.format(signal)) if signal == 'trigger': cv_trigger.acquire() cv_trigger.notify() cv_trigger.release() pub = system_bus.publish("io.respeaker.respeakerd", dbus_obj) sub = system_bus.subscribe(iface='respeakerd.signal', signal_fired=dbus_handler) def exit_dbus(): sub.unsubscribe() pub.unpublish() # Create an authorized gRPC channel. grpc_channel = google.auth.transport.grpc.secure_authorized_channel( credentials, http_request, api_endpoint) logging.info('Connecting to %s', api_endpoint) # Configure audio source and sink. audio_device = None if input_audio_file: audio_source = audio_helpers.WaveSource( open(input_audio_file, 'rb'), sample_rate=audio_sample_rate, sample_width=audio_sample_width) else: audio_source = audio_device = (audio_device or audio_helpers.SoundDeviceStream( sample_rate=audio_sample_rate, sample_width=audio_sample_width, block_size=audio_block_size, flush_size=audio_flush_size)) if output_audio_file: audio_sink = audio_helpers.WaveSink(open(output_audio_file, 'wb'), sample_rate=audio_sample_rate, sample_width=audio_sample_width) else: audio_sink = audio_device = (audio_device or audio_helpers.SoundDeviceStream( sample_rate=audio_sample_rate, sample_width=audio_sample_width, block_size=audio_block_size, flush_size=audio_flush_size)) # Create conversation stream with the given audio source and sink. conversation_stream = audio_helpers.ConversationStream( source=audio_source, sink=audio_sink, iter_size=audio_iter_size, sample_width=audio_sample_width, ) if not device_id or not device_model_id: try: with open(device_config) as f: device = json.load(f) device_id = device['id'] device_model_id = device['model_id'] logging.info("Using device model %s and device id %s", device_model_id, device_id) except Exception as e: logging.warning('Device config not found: %s' % e) logging.info('Registering device') if not device_model_id: logging.error('Option --device-model-id required ' 'when registering a device instance.') exit_dbus() sys.exit(-1) if not project_id: logging.error('Option --project-id required ' 'when registering a device instance.') exit_dbus() sys.exit(-1) device_base_url = ('https://%s/v1alpha2/projects/%s/devices' % (api_endpoint, project_id)) device_id = str(uuid.uuid1()) payload = { 'id': device_id, 'model_id': device_model_id, 'client_type': 'SDK_SERVICE' } session = google.auth.transport.requests.AuthorizedSession( credentials) r = session.post(device_base_url, data=json.dumps(payload)) if r.status_code != 200: logging.error('Failed to register device: %s', r.text) exit_dbus() sys.exit(-1) logging.info('Device registered: %s', device_id) pathlib.Path(os.path.dirname(device_config)).mkdir(exist_ok=True) with open(device_config, 'w') as f: json.dump(payload, f) device_handler = device_helpers.DeviceRequestHandler(device_id) @device_handler.command('action.devices.commands.OnOff') def onoff(on): if on: logging.info('Turning device on') else: logging.info('Turning device off') # If file arguments are supplied: # exit after the first turn of the conversation. if input_audio_file or output_audio_file: with SampleAssistant(lang, device_model_id, device_id, conversation_stream, grpc_channel, grpc_deadline, device_handler, eventq) as assistant: dbus_obj.ready() assistant.assist() exit_dbus() return # else it's a long term run def assistant_thread(conversation_stream_): with SampleAssistant(lang, device_model_id, device_id, conversation_stream_, grpc_channel, grpc_deadline, device_handler, eventq) as assistant: dbus_obj.ready() # If no file arguments supplied: # keep recording voice requests using the microphone # and playing back assistant response using the speaker. # When the once flag is set, don't wait for a trigger. Otherwise, wait. wait_for_user_trigger = not once # capture device should always be opened when not playing conversation_stream_.start_recording() while True: if wait_for_user_trigger: logging.info("speak hotword to wake up") cv_trigger.acquire() cv_trigger.wait() cv_trigger.release() logging.info("wake up!") continue_conversation = False try: continue_conversation = assistant.assist() except PortAudioError as e: logging.warn('PortAudio Error: {}'.format(str(e))) eventq.put('on_idle') # wait for user trigger if there is no follow-up turn in # the conversation. wait_for_user_trigger = not continue_conversation # If we only want one conversation, break. if once and (not continue_conversation): break exit_dbus() logging.debug('Exit from the assistant thread...') loop.quit() def event_process_thread(): while True: event = eventq.get() if event == 'on_listen': dbus_obj.on_listen() elif event == 'on_think': dbus_obj.on_think() elif event == 'on_speak': dbus_obj.on_speak() elif event == 'on_idle': dbus_obj.on_idle() time.sleep(0.5) def on_exit(sig): exit_dbus() loop.quit() logging.info("Quit...") setup_signals( signals=[sys_signal.SIGINT, sys_signal.SIGTERM, sys_signal.SIGHUP], handler=on_exit) # make conversation_stream writable inside thread thrd1 = Thread(target=assistant_thread, args=(conversation_stream, )) thrd2 = Thread(target=event_process_thread) thrd1.daemon = True thrd2.daemon = True thrd1.start() thrd2.start() logging.info("Glib mainloop start running...") loop.run() dbus_obj.on_idle()
async def emit_random_number(): "Emit a message every second with random integer between 0 and 100." while True: x = random.randrange(100) message = "The random integer for this second is {}".format(x) print("Server:", message) emit.app_signal(message) await asyncio.sleep(1) if __name__ == "__main__": print("Server starting") # Setup server to emit signals over the DBus emit = Server_XML() bus.publish(iface_name, emit) # Add tasks loop.create_task(emit_random_number()) loop.run_forever() ''' Example of running the server... $ python3 server_test.py Server starting Server: The random integer for this second is 45 Server: The random integer for this second is 11 Server: The random integer for this second is 19 Example: Using gdbus to check server program is emitting OK... $ gdbus monitor --system --dest org.example.ca.server
logger.addHandler(stream_handler) def setup_gettext(): # This allows to translate all py texts (not the glade ones) gettext.textdomain(APP_NAME) gettext.bindtextdomain(APP_NAME, LOCALE_DIR) locale_code, encoding = locale.getdefaultlocale() lang = gettext.translation(APP_NAME, LOCALE_DIR, locale_code, None, True) lang.install() # With this we can use _("string") to translate gettext.install(APP_NAME, localedir=LOCALE_DIR, codeset=None, names=locale_code) if __name__ == '__main__': setup_gettext() argv_options, argv_args = parse_argv() setup_logging(argv_options) mainloop = GLib.MainLoop() bus = SystemBus() logging.debug(_("Connected to the system bus")) bus.publish("com.antergos.welcome", service.DBusService(mainloop)) mainloop.run()
#time.sleep(random.randrange(1,4)) logging.debug("%s: intialize finished" % self.__class__.__name__) logging.debug(80 * "#") # User does not have a binary # Payload service does not have permissions (.conf file) # Network service does not exist (doesn't have .service file) #anaconda_modules = [] #anaconda_modules = ["Timezone", "Storage"] anaconda_modules = ["Timezone", "Storage", "Payload", "Network", "User"] boss = Boss(modules=anaconda_modules) boss.initialize() bus.publish("org.freedesktop.Anaconda.Boss", boss) def start(): boss.EchoString("I am alive") return False def start_modules_and_addons_sync(): boss.StartModules() #boss.StartModulesSync() return False GLib.timeout_add_seconds(1, start_modules_and_addons_sync) loop.run()
<method name='EchoString'> <arg type='s' name='question' direction='in'/> <arg type='s' name='response' direction='out'/> </method> <method name='Quit'/> </interface> </node> """ def EchoString(self, s): """returns whatever is passed to it""" logging.debug("%s: EchoString %s" % (self.__class__.__name__, s)) return s def Quit(self): """removes the object from the DBUS connection and exits""" logging.debug("%s: Quit" % self.__class__.__name__) GLib.timeout_add_seconds(1, loop.quit) def initialize(self): """initialize boss before publishing""" logging.debug("%s: intialize started" % self.__class__.__name__) time.sleep(random.randrange(4)) logging.debug("%s: intialize finished" % self.__class__.__name__) bus = SystemBus() module = Timezone() module.initialize() bus.publish("org.freedesktop.Anaconda.Module.Timezone", module) loop.run()
logger.addHandler(stream_handler) def setup_gettext(): # This allows to translate all py texts (not the glade ones) gettext.textdomain(APP_NAME) gettext.bindtextdomain(APP_NAME, LOCALE_DIR) locale_code, encoding = locale.getdefaultlocale() lang = gettext.translation(APP_NAME, LOCALE_DIR, locale_code, None, True) lang.install() # With this we can use _("string") to translate gettext.install(APP_NAME, localedir=LOCALE_DIR, codeset=None, names=locale_code) if __name__ == '__main__': setup_gettext() argv_options, argv_args = parse_argv() setup_logging(argv_options) mainloop = GLib.MainLoop() bus = SystemBus() logging.debug(_("Connected to the system bus")) bus.publish("com.condres.welcome", service.DBusService(mainloop)) mainloop.run()
stream_handler.setLevel(log_level) stream_handler.setFormatter(formatter) logger.addHandler(stream_handler) def setup_gettext(): # This allows to translate all py texts (not the glade ones) gettext.textdomain(APP_NAME) gettext.bindtextdomain(APP_NAME, LOCALE_DIR) locale_code, encoding = locale.getdefaultlocale() lang = gettext.translation(APP_NAME, LOCALE_DIR, locale_code, None, True) lang.install() # With this we can use _("string") to translate gettext.install(APP_NAME, localedir=LOCALE_DIR, codeset=None, names=locale_code) if __name__ == '__main__': setup_gettext() argv_options, argv_args = parse_argv() setup_logging(argv_options) mainloop = GLib.MainLoop() bus = SystemBus() logging.debug(_("Connected to the system bus")) bus.publish("com.antergos.welcome", service.DBusService(mainloop)) mainloop.run()
def run_server(self, processor): bus = SystemBus() service = bus.publish(DBUS_NAME, Service(processor)) self.loop.run() service.unpublish()
class DebianDevelChanges(supybot.callbacks.Plugin): threaded = True def __init__(self, irc): super().__init__(irc) self.irc = irc self.topic_lock = threading.Lock() self.mainloop = None self.mainloop_thread = None mainloop = GObject.MainLoop() if not mainloop.is_running(): log.info('Starting Glib main loop') mainloop_thread = threading.Thread(target=mainloop.run, name='Glib maing loop') mainloop_thread.start() self.mainloop_thread = mainloop_thread self.mainloop = mainloop self.requests_session = requests.Session() self.requests_session.verify = True self.queued_topics = {} self.last_n_messages = [] # data sources pseudo_packages.pp = PseudoPackages(self.requests_session) self.pseudo_packages = pseudo_packages.pp self.stable_rc_bugs = StableRCBugs(self.requests_session) self.testing_rc_bugs = TestingRCBugs(self.requests_session) self.new_queue = NewQueue(self.requests_session) self.dinstall = Dinstall(self.requests_session) self.rm_queue = RmQueue(self.requests_session) self.apt_archive = AptArchive( self.registryValue('apt_configuration_directory'), self.registryValue('apt_cache_directory')) self.data_sources = ( self.pseudo_packages, self.stable_rc_bugs, self.testing_rc_bugs, self.new_queue, self.dinstall, self.rm_queue, self.apt_archive ) # Schedule datasource updates def wrapper(source): def implementation(): try: source.update() except Exception as e: log.exception('Failed to update {}: {}'.format(source.NAME, e)) self._topic_callback() return implementation for source in self.data_sources: # schedule periodic events schedule.addPeriodicEvent(wrapper(source), source.INTERVAL, source.NAME, now=False) # and run them now once schedule.addEvent(wrapper(source), time.time() + 1) log.info('Starting D-Bus service') self.dbus_service = BTSDBusService(self._email_callback) self.dbus_bus = SystemBus() self.dbus_bus.publish(self.dbus_service.interface_name, self.dbus_service) self.dbus_service.start() def die(self): log.info('Stopping D-Bus service') self.dbus_service.stop() if self.mainloop is not None: log.info('Stopping Glib main loop') self.mainloop.quit() self.mainloop_thread.join(timeout=1.0) if self.mainloop_thread.is_alive(): log.warn('Glib main loop thread is still alive.') self.mainloop = None self.mainloop_thread = None for source in self.data_sources: try: schedule.removePeriodicEvent(source.NAME) except KeyError: pass super().die() def _email_callback(self, fileobj): try: emailmsg = parse_mail(fileobj) msg = get_message(emailmsg, new_queue=self.new_queue) if not msg: return txt = colourise(msg.for_irc()) # Simple flood/duplicate detection if txt in self.last_n_messages: return self.last_n_messages.insert(0, txt) self.last_n_messages = self.last_n_messages[:20] maintainer_info = None if hasattr(msg, 'maintainer'): maintainer_info = (split_address(msg.maintainer), ) else: maintainer_info = [] for package in msg.package.split(','): package = package.strip() try: maintainer_info.append(self.apt_archive.get_maintainer(package)) except NewDataSource.DataError as e: log.info("Failed to query maintainer for {}.".format(package)) for channel in self.irc.state.channels: package_regex = self.registryValue( 'package_regex', channel, ) or 'a^' # match nothing by default package_match = re.search(package_regex, msg.package) maintainer_match = False maintainer_regex = self.registryValue( 'maintainer_regex', channel) if maintainer_regex and maintainer_info is not None and len(maintainer_info) >= 0: for mi in maintainer_info: maintainer_match = re.search(maintainer_regex, mi['email']) if maintainer_match: break if not package_match and not maintainer_match: continue distribution_regex = self.registryValue( 'distribution_regex', channel, ) if distribution_regex: if not hasattr(msg, 'distribution'): # If this channel has a distribution regex, don't # bother continuing unless the message actually has a # distribution. This filters security messages, etc. continue if not re.search(distribution_regex, msg.distribution): # Distribution doesn't match regex; don't send this # message. continue send_privmsg = self.registryValue('send_privmsg', channel) # Send NOTICE per default and if 'send_privmsg' is set for the # channel, send PRIVMSG instead. if send_privmsg: ircmsg = supybot.ircmsgs.privmsg(channel, txt) else: ircmsg = supybot.ircmsgs.notice(channel, txt) self.irc.queueMsg(ircmsg) except Exception as e: log.exception('Uncaught exception: %s ' % e) def _topic_callback(self): sections = { self.testing_rc_bugs.get_number_bugs: 'RC bug count', self.stable_rc_bugs.get_number_bugs: 'stable RC bug count', self.new_queue.get_size: 'NEW queue', self.new_queue.get_backports_size: 'backports NEW queue', self.rm_queue.get_size: 'RM queue', self.dinstall.get_status: 'dinstall' } channels = set() with self.topic_lock: values = {} for callback, prefix in sections.items(): new_value = callback() if new_value is not None: values[prefix] = new_value for channel in self.irc.state.channels: new_topic = topic = self.irc.state.getTopic(channel) for prefix, value in values.items(): new_topic = rewrite_topic(new_topic, prefix, value) if topic != new_topic: self.queued_topics[channel] = new_topic if channel not in channels: log.info("Queueing change of topic in #%s to '%s'" % (channel, new_topic)) channels.add(channel) for channel in channels: event_name = '{}_topic'.format(channel) try: schedule.removeEvent(event_name) except KeyError: pass def update_topic(channel=channel): self._update_topic(channel) schedule.addEvent(update_topic, time.time() + 60, event_name) def _update_topic(self, channel): with self.topic_lock: try: new_topic = self.queued_topics[channel] log.info("Changing topic in #%s to '%s'" % (channel, new_topic)) self.irc.queueMsg(supybot.ircmsgs.topic(channel, new_topic)) except KeyError: pass def rc(self, irc, msg, args): """Link to UDD RC bug overview.""" num_bugs = self.testing_rc_bugs.get_number_bugs() if type(num_bugs) is int: irc.reply( "There are %d release-critical bugs in the testing distribution. " "See https://udd.debian.org/bugs.cgi?release=buster¬main=ign&merged=ign&rc=1" % num_bugs) else: irc.reply("No data at this time.") rc = wrap(rc) bugs = wrap(rc) def update(self, irc, msg, args): """Trigger an update.""" if not ircdb.checkCapability(msg.prefix, 'owner'): irc.reply("You are not authorised to run this command.") return for source in self.data_sources: source.update() irc.reply("Updated %s." % source.NAME) self._topic_callback() update = wrap(update) def madison(self, irc, msg, args, package): """List packages.""" try: lines = madison(package) if not lines: irc.reply('Did not get a response -- is "%s" a valid package?' % package) return field_styles = ('package', 'version', 'distribution', 'section') for line in lines: out = [] fields = line.strip().split('|', len(field_styles)) for style, data in zip(field_styles, fields): out.append('[%s]%s' % (style, data)) irc.reply(colourise('[reset]|'.join(out)), prefixNick=False) except Exception as e: irc.reply("Error: %s" % e.message) madison = wrap(madison, ['text']) def get_pool_url(self, package): if package.startswith('lib'): return (package[:4], package) else: return (package[:1], package) def _maintainer(self, irc, msg, args, items): """Get maintainer for package.""" for package in items: info = self.apt_archive.get_maintainer(package) if info: display_name = format_email_address("%s <%s>" % (info['name'], info['email']), max_domain=18) login = info['email'] if login.endswith('@debian.org'): login = login.replace('@debian.org', '') msg = "[desc]Maintainer for[reset] [package]%s[reset] [desc]is[reset] [by]%s[reset]: " % (package, display_name) msg += "[url]https://qa.debian.org/developer.php?login=%s[/url]" % login else: msg = 'Unknown source package "%s"' % package irc.reply(colourise(msg), prefixNick=False) maintainer = wrap(_maintainer, [many('anything')]) maint = wrap(_maintainer, [many('anything')]) who_maintains = wrap(_maintainer, [many('anything')]) def _qa(self, irc, msg, args, items): """Get link to QA page.""" for package in items: url = "https://packages.qa.debian.org/%s/%s.html" % self.get_pool_url(package) msg = "[desc]QA page for[reset] [package]%s[reset]: [url]%s[/url]" % (package, url) irc.reply(colourise(msg), prefixNick=False) qa = wrap(_qa, [many('anything')]) overview = wrap(_qa, [many('anything')]) package = wrap(_qa, [many('anything')]) pkg = wrap(_qa, [many('anything')]) srcpkg = wrap(_qa, [many('anything')]) def _changelog(self, irc, msg, args, items): """Get link to changelog.""" for package in items: url = "https://packages.debian.org/changelogs/pool/main/%s/%s/current/changelog" % self.get_pool_url(package) msg = "[desc]debian/changelog for[reset] [package]%s[reset]: [url]%s[/url]" % (package, url) irc.reply(colourise(msg), prefixNick=False) changelog = wrap(_changelog, [many('anything')]) changes = wrap(_changelog, [many('anything')]) def _copyright(self, irc, msg, args, items): """Link to copyright files.""" for package in items: url = "https://packages.debian.org/changelogs/pool/main/%s/%s/current/copyright" % self.get_pool_url(package) msg = "[desc]debian/copyright for[reset] [package]%s[reset]: [url]%s[/url]" % (package, url) irc.reply(colourise(msg), prefixNick=False) copyright = wrap(_copyright, [many('anything')]) def _buggraph(self, irc, msg, args, items): """Link to bug graph.""" for package in items: msg = "[desc]Bug graph for[reset] [package]%s[reset]: [url]https://qa.debian.org/data/bts/graphs/%s/%s.png[/url]" % \ (package, package[0], package) irc.reply(colourise(msg), prefixNick=False) buggraph = wrap(_buggraph, [many('anything')]) bug_graph = wrap(_buggraph, [many('anything')]) def _buildd(self, irc, msg, args, items): """Link to buildd page.""" for package in items: msg = "[desc]buildd status for[reset] [package]%s[reset]: [url]https://buildd.debian.org/pkg.cgi?pkg=%s[/url]" % \ (package, package) irc.reply(colourise(msg), prefixNick=False) buildd = wrap(_buildd, [many('anything')]) def _popcon(self, irc, msg, args, package): """Get popcon data.""" try: msg = popcon(package, self.requests_session) if msg: irc.reply(colourise(msg.for_irc()), prefixNick=False) except Exception as e: irc.reply("Error: unable to obtain popcon data for %s" % package) popcon = wrap(_popcon, ['text']) def _testing(self, irc, msg, args, items): """Check testing migration status.""" for package in items: msg = "[desc]Testing migration status for[reset] [package]%s[reset]: [url]https://qa.debian.org/excuses.php?package=%s[/url]" % \ (package, package) irc.reply(colourise(msg), prefixNick=False) testing = wrap(_testing, [many('anything')]) migration = wrap(_testing, [many('anything')]) def _new(self, irc, msg, args): """Link to NEW queue.""" line = "[desc]NEW queue is[reset]: [url]%s[/url]. [desc]Current size is:[reset] %d" % \ ("https://ftp-master.debian.org/new.html", self.new_queue.get_size()) irc.reply(colourise(line)) new = wrap(_new) new_queue = wrap(_new) newqueue = wrap(_new)
<arg name="request" type="s" direction="in"/> <arg name="response" type="s" direction="out"/> </method> <signal name="UpdateInfo"> <arg type="s" name="info"/> </signal> </interface> </node> """ UpdateInfo = signal() def Get(self, s): print("com.ssangyong.AutomotiveProxy.LocationManager " + "Get : " + s) return "Location Manager - Get" def Set(self, s): print("com.ssangyong.AutomotiveProxy.LocationManager " + "Set : " + s) return "Location Manager - Set" def AddListener(self, s): print("com.ssangyong.AutomotiveProxy.LocationManager " + "AddListener : " + s) return "Location Manager - AddLister" bus = SystemBus() bus.publish("com.ssangyong.AutomotiveProxy.LocationManager", LocationService()) location = bus.get("com.ssangyong.AutomotiveProxy.LocationManager") location.onUpdateInfo = LocationService.AddListener loop.run()
<method name='EchoString'> <arg type='s' name='question' direction='in'/> <arg type='s' name='response' direction='out'/> </method> <method name='Quit'/> </interface> </node> """ def EchoString(self, s): """returns whatever is passed to it""" logging.debug("%s: EchoString %s" % (self.__class__.__name__, s)) return s def Quit(self): """removes the object from the DBUS connection and exits""" logging.debug("%s: Quit" % self.__class__.__name__) GLib.timeout_add_seconds(1, loop.quit) def initialize(self): """initialize boss before publishing""" logging.debug("%s: intialize started" % self.__class__.__name__) time.sleep(random.randrange(4)) logging.debug("%s: intialize finished" % self.__class__.__name__) bus = SystemBus() module = Timezone() module.initialize() bus.publish("org.freedesktop.Anaconda.Module.Timezone", module) loop.run()
class DebianDevelChanges(supybot.callbacks.Plugin): threaded = True def __init__(self, irc): super().__init__(irc) self.irc = irc self.topic_lock = threading.Lock() self.mainloop = None self.mainloop_thread = None mainloop = GObject.MainLoop() if not mainloop.is_running(): log.info('Starting Glib main loop') mainloop_thread = threading.Thread(target=mainloop.run, name='Glib maing loop') mainloop_thread.start() self.mainloop_thread = mainloop_thread self.mainloop = mainloop log.info('Starting D-Bus service') self.dbus_service = BTSDBusService(self._email_callback) self.dbus_bus = SystemBus() self.dbus_bus.publish(self.dbus_service.interface_name, self.dbus_service) self.dbus_service.start() self.requests_session = requests.Session() self.requests_session.verify = True self.queued_topics = {} self.last_n_messages = [] # data sources self.stable_rc_bugs = StableRCBugs(self.requests_session) self.testing_rc_bugs = TestingRCBugs(self.requests_session) self.new_queue = NewQueue(self.requests_session) self.dinstall = Dinstall(self.requests_session) self.rm_queue = RmQueue(self.requests_session) self.apt_archive = AptArchive( self.registryValue('apt_configuration_directory'), self.registryValue('apt_cache_directory')) self.data_sources = (self.stable_rc_bugs, self.testing_rc_bugs, self.new_queue, self.dinstall, self.rm_queue, self.apt_archive) # Schedule datasource updates def wrapper(source): def implementation(): try: source.update() except Exception as e: log.exception('Failed to update {}: {}'.format( source.NAME, e)) self._topic_callback() return implementation for source in self.data_sources: # schedule periodic events schedule.addPeriodicEvent(wrapper(source), source.INTERVAL, source.NAME, now=False) # and run them now once schedule.addEvent(wrapper(source), time.time() + 1) def die(self): log.info('Stopping D-Bus service') self.dbus_service.stop() if self.mainloop is not None: log.info('Stopping Glib main loop') self.mainloop.quit() self.mainloop_thread.join(timeout=1.0) if self.mainloop_thread.is_alive(): log.warn('Glib main loop thread is still alive.') self.mainloop = None self.mainloop_thread = None for source in self.data_sources: try: schedule.removePeriodicEvent(source.NAME) except KeyError: pass super().die() def _email_callback(self, fileobj): try: emailmsg = parse_mail(fileobj) msg = get_message(emailmsg, new_queue=self.new_queue) if not msg: return txt = colourise(msg.for_irc()) # Simple flood/duplicate detection if txt in self.last_n_messages: return self.last_n_messages.insert(0, txt) self.last_n_messages = self.last_n_messages[:20] maintainer_info = None if hasattr(msg, 'maintainer'): maintainer_info = (split_address(msg.maintainer), ) else: maintainer_info = [] for package in msg.package.split(','): package = package.strip() try: maintainer_info.append( self.apt_archive.get_maintainer(package)) except NewDataSource.DataError as e: log.info("Failed to query maintainer for {}.".format( package)) for channel in self.irc.state.channels: package_regex = self.registryValue( 'package_regex', channel, ) or 'a^' # match nothing by default package_match = re.search(package_regex, msg.package) maintainer_match = False maintainer_regex = self.registryValue('maintainer_regex', channel) if maintainer_regex and maintainer_info is not None and len( maintainer_info) >= 0: for mi in maintainer_info: maintainer_match = re.search(maintainer_regex, mi['email']) if maintainer_match: break if not package_match and not maintainer_match: continue distribution_regex = self.registryValue( 'distribution_regex', channel, ) if distribution_regex: if not hasattr(msg, 'distribution'): # If this channel has a distribution regex, don't # bother continuing unless the message actually has a # distribution. This filters security messages, etc. continue if not re.search(distribution_regex, msg.distribution): # Distribution doesn't match regex; don't send this # message. continue send_privmsg = self.registryValue('send_privmsg', channel) # Send NOTICE per default and if 'send_privmsg' is set for the # channel, send PRIVMSG instead. if send_privmsg: ircmsg = supybot.ircmsgs.privmsg(channel, txt) else: ircmsg = supybot.ircmsgs.notice(channel, txt) self.irc.queueMsg(ircmsg) except Exception as e: log.exception('Uncaught exception: %s ' % e) def _topic_callback(self): sections = { self.testing_rc_bugs.get_number_bugs: 'RC bug count', self.stable_rc_bugs.get_number_bugs: 'Stable RC bug count', self.new_queue.get_size: 'NEW queue', self.rm_queue.get_size: 'RM queue', self.dinstall.get_status: 'dinstall' } channels = set() with self.topic_lock: values = {} for callback, prefix in sections.items(): values[prefix] = callback() for channel in self.irc.state.channels: new_topic = topic = self.irc.state.getTopic(channel) for callback, prefix in sections.items(): if values[prefix]: new_topic = rewrite_topic(new_topic, prefix, values[prefix]) if topic != new_topic: self.queued_topics[channel] = new_topic if channel not in channels: log.info("Queueing change of topic in #%s to '%s'" % (channel, new_topic)) channels.add(channel) for channel in channels: event_name = '{}_topic'.format(channel) try: schedule.removeEvent(event_name) except KeyError: pass def update_topic(channel=channel): self._update_topic(channel) schedule.addEvent(update_topic, time.time() + 60, event_name) def _update_topic(self, channel): with self.topic_lock: try: new_topic = self.queued_topics[channel] log.info("Changing topic in #%s to '%s'" % (channel, new_topic)) self.irc.queueMsg(supybot.ircmsgs.topic(channel, new_topic)) except KeyError: pass def rc(self, irc, msg, args): """Link to UDD RC bug overview.""" num_bugs = self.testing_rc_bugs.get_number_bugs() if type(num_bugs) is int: irc.reply( "There are %d release-critical bugs in the testing distribution. " "See https://udd.debian.org/bugs.cgi?release=buster¬main=ign&merged=ign&rc=1" % num_bugs) else: irc.reply("No data at this time.") rc = wrap(rc) bugs = wrap(rc) def update(self, irc, msg, args): """Trigger an update.""" if not ircdb.checkCapability(msg.prefix, 'owner'): irc.reply("You are not authorised to run this command.") return for source in self.data_sources: source.update() irc.reply("Updated %s." % source.NAME) self._topic_callback() update = wrap(update) def madison(self, irc, msg, args, package): """List packages.""" try: lines = madison(package) if not lines: irc.reply( 'Did not get a response -- is "%s" a valid package?' % package) return field_styles = ('package', 'version', 'distribution', 'section') for line in lines: out = [] fields = line.strip().split('|', len(field_styles)) for style, data in zip(field_styles, fields): out.append('[%s]%s' % (style, data)) irc.reply(colourise('[reset]|'.join(out)), prefixNick=False) except Exception as e: irc.reply("Error: %s" % e.message) madison = wrap(madison, ['text']) def get_pool_url(self, package): if package.startswith('lib'): return (package[:4], package) else: return (package[:1], package) def _maintainer(self, irc, msg, args, items): """Get maintainer for package.""" for package in items: info = self.apt_archive.get_maintainer(package) if info: display_name = format_email_address( "%s <%s>" % (info['name'], info['email']), max_domain=18) login = info['email'] if login.endswith('@debian.org'): login = login.replace('@debian.org', '') msg = "[desc]Maintainer for[reset] [package]%s[reset] [desc]is[reset] [by]%s[reset]: " % ( package, display_name) msg += "[url]https://qa.debian.org/developer.php?login=%s[/url]" % login else: msg = 'Unknown source package "%s"' % package irc.reply(colourise(msg), prefixNick=False) maintainer = wrap(_maintainer, [many('anything')]) maint = wrap(_maintainer, [many('anything')]) who_maintains = wrap(_maintainer, [many('anything')]) def _qa(self, irc, msg, args, items): """Get link to QA page.""" for package in items: url = "https://packages.qa.debian.org/%s/%s.html" % self.get_pool_url( package) msg = "[desc]QA page for[reset] [package]%s[reset]: [url]%s[/url]" % ( package, url) irc.reply(colourise(msg), prefixNick=False) qa = wrap(_qa, [many('anything')]) overview = wrap(_qa, [many('anything')]) package = wrap(_qa, [many('anything')]) pkg = wrap(_qa, [many('anything')]) srcpkg = wrap(_qa, [many('anything')]) def _changelog(self, irc, msg, args, items): """Get link to changelog.""" for package in items: url = "https://packages.debian.org/changelogs/pool/main/%s/%s/current/changelog" % self.get_pool_url( package) msg = "[desc]debian/changelog for[reset] [package]%s[reset]: [url]%s[/url]" % ( package, url) irc.reply(colourise(msg), prefixNick=False) changelog = wrap(_changelog, [many('anything')]) changes = wrap(_changelog, [many('anything')]) def _copyright(self, irc, msg, args, items): """Link to copyright files.""" for package in items: url = "https://packages.debian.org/changelogs/pool/main/%s/%s/current/copyright" % self.get_pool_url( package) msg = "[desc]debian/copyright for[reset] [package]%s[reset]: [url]%s[/url]" % ( package, url) irc.reply(colourise(msg), prefixNick=False) copyright = wrap(_copyright, [many('anything')]) def _buggraph(self, irc, msg, args, items): """Link to bug graph.""" for package in items: msg = "[desc]Bug graph for[reset] [package]%s[reset]: [url]https://qa.debian.org/data/bts/graphs/%s/%s.png[/url]" % \ (package, package[0], package) irc.reply(colourise(msg), prefixNick=False) buggraph = wrap(_buggraph, [many('anything')]) bug_graph = wrap(_buggraph, [many('anything')]) def _buildd(self, irc, msg, args, items): """Link to buildd page.""" for package in items: msg = "[desc]buildd status for[reset] [package]%s[reset]: [url]https://buildd.debian.org/pkg.cgi?pkg=%s[/url]" % \ (package, package) irc.reply(colourise(msg), prefixNick=False) buildd = wrap(_buildd, [many('anything')]) def _popcon(self, irc, msg, args, package): """Get popcon data.""" try: msg = popcon(package, self.requests_session) if msg: irc.reply(colourise(msg.for_irc()), prefixNick=False) except Exception as e: irc.reply("Error: unable to obtain popcon data for %s" % package) popcon = wrap(_popcon, ['text']) def _testing(self, irc, msg, args, items): """Check testing migration status.""" for package in items: msg = "[desc]Testing migration status for[reset] [package]%s[reset]: [url]https://qa.debian.org/excuses.php?package=%s[/url]" % \ (package, package) irc.reply(colourise(msg), prefixNick=False) testing = wrap(_testing, [many('anything')]) migration = wrap(_testing, [many('anything')]) def _dehs(self, irc, msg, args, items): """Link to DEHS.""" for package in items: msg = "[desc]Debian External Health Status for[reset] [package]%s[reset]: [url]https://dehs.alioth.debian.org/report.php?package=%s[/url]" % \ (package, urllib.parse.quote(package)) irc.reply(colourise(msg), prefixNick=False) dehs = wrap(_dehs, [many('anything')]) health = wrap(_dehs, [many('anything')]) def _new(self, irc, msg, args): """Link to NEW queue.""" line = "[desc]NEW queue is[reset]: [url]%s[/url]. [desc]Current size is:[reset] %d" % \ ("https://ftp-master.debian.org/new.html", self.new_queue.get_size()) irc.reply(colourise(line)) new = wrap(_new) new_queue = wrap(_new) newqueue = wrap(_new)
<method name='EchoString'> <arg type='s' name='question' direction='in'/> <arg type='s' name='response' direction='out'/> </method> <method name='Quit'/> </interface> </node> """ def EchoString(self, s): """returns whatever is passed to it""" logging.debug("%s: EchoString %s" % (self.__class__.__name__, s)) return s def Quit(self): """removes the object from the DBUS connection and exits""" logging.debug("%s: Quit" % self.__class__.__name__) GLib.timeout_add_seconds(1, loop.quit) def initialize(self): """initialize boss before publishing""" logging.debug("%s: intialize started" % self.__class__.__name__) time.sleep(random.randrange(4)) logging.debug("%s: intialize finished" % self.__class__.__name__) bus = SystemBus() module = Payload() module.initialize() bus.publish("org.freedesktop.Anaconda.Module.Payload", module) loop.run()