Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Some logging for the Ham notification service. Suppress initial notification events while the notify daemon is starting up and catching up. Blacklist is an ofono thing, but it sits alongside the others on my Ubuntu phone, so I'll just keep it here for now |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | master | trunk |
Files: | files | file ages | folders |
SHA3-256: | 915508d040a86bdc2efc800e3d8054ca |
User & Date: | vandys 2018-11-09 01:41:09 |
Context
2018-11-20
| ||
19:30 | flite pronounces the word "underscore" for every single underscore in the message line... check-in: 0ef40c339b user: vandys tags: master, trunk | |
2018-11-09
| ||
01:41 | Some logging for the Ham notification service. Suppress initial notification events while the notify daemon is starting up and catching up. Blacklist is an ofono thing, but it sits alongside the others on my Ubuntu phone, so I'll just keep it here for now check-in: 915508d040 user: vandys tags: master, trunk | |
2018-09-22
| ||
14:07 | Fix usage check-in: 8543639bab user: vandys tags: master, trunk | |
Changes
Added tools/blacklist.py.
1 +#!/usr/bin/python3 2 +import sys, threading, os, time 3 +import dbus, dbus.exceptions, dbus.mainloop.glib 4 +from gi.repository import GLib 5 +import pdb 6 + 7 +class Blacklist(object): 8 + def __init__(self, fn): 9 + 10 + # Initial load of @fn 11 + self.fname = fn 12 + self.ftime = None 13 + self.reload() 14 + 15 + # Threading; one for the watcher, one for main 16 + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) 17 + l = GLib.MainLoop() 18 + t = threading.Thread(target=l.run) 19 + t.start() 20 + 21 + # Connection to dbus 22 + bus = self.bus = dbus.SystemBus() 23 + bus.add_signal_receiver(self.watcher, "CallAdded", 24 + dbus_interface="org.ofono.VoiceCallManager") 25 + 26 + # Watching for new call 27 + def watcher(self, *args, **kwargs): 28 + self.reload() 29 + call = str(args[0]) 30 + obdict = args[1] 31 + callerid = str(obdict["LineIdentification"]) 32 + if any( (s in callerid) for s in self.rejects ): 33 + sys.stderr.write("%s Rejecting call from %s\n" % 34 + (time.strftime("%m/%d %H:%M"), callerid)) 35 + self.hangup(call) 36 + 37 + # (re-)Load blacklist 38 + def reload(self): 39 + 40 + # Reload when needed 41 + try: 42 + f = open(self.fname, "r") 43 + except: 44 + self.ftime = None 45 + return 46 + st = os.fstat(f.fileno()) 47 + if st.st_mtime == self.ftime: 48 + f.close() 49 + return 50 + self.ftime = st.st_mtime 51 + 52 + # Load new contents 53 + self.rejects = [] 54 + for l in f: 55 + 56 + # One phone number per line 57 + l = l.strip() 58 + 59 + # Ignore empty and comments 60 + if not l: 61 + continue 62 + if l[0] == '#': 63 + continue 64 + 65 + # Add to reject list 66 + self.rejects.append(l) 67 + f.close() 68 + sys.stderr.write("%d blacklist items\n" % 69 + (len(self.rejects or ()),)) 70 + 71 + # Drop the named call 72 + def hangup(self, callid): 73 + callob = self.bus.get_object('org.ofono', callid) 74 + call = dbus.Interface(callob, 'org.ofono.VoiceCall') 75 + call.Hangup() 76 + 77 +if __name__ == "__main__": 78 + b = Blacklist(os.environ["HOME"] + "/.config/blacklist.txt")
Changes to tools/ham.py.
44 44 rhost,rigcfg = cfg["rig"] 45 45 rport = rigcfg["port"] 46 46 self.raddr = (rhost, rport) 47 47 rchan = rigcfg["channel"][0].upper() 48 48 self.rtxon = json.dumps({"chan": rchan, "val": 1}) 49 49 self.rtxoff = json.dumps({"chan": rchan, "val": 0}) 50 50 51 + # Log all alerts? 52 + self.logf = None 53 + if "log" in cfg: 54 + self.logf = open(cfg["log"], "a") 55 + 51 56 # Transmitter control 52 57 def tx_on(self): 53 58 self.rconn.sendto(self.rtxon, self.raddr) 54 59 def tx_off(self): 55 60 self.rconn.sendto(self.rtxoff, self.raddr) 56 61 57 62 # Configuration, indented chore style ................................................................................ 75 80 # port Y 76 81 # channel Z 77 82 # audio "audio-device-name" 78 83 c.onearg.add( ("rig",) ) 79 84 c.ints.add( ("rig", "port") ) 80 85 c.onearg.add( ("rig", "channel") ) 81 86 c.onearg.add( ("rig", "audio") ) 87 + 88 + # Plain text dump of what we've been told to notify 89 + c.onearg.add( ("log",) ) 82 90 83 91 # Parse and set config dict 84 92 self.cfg = c.load_cfg(fn) 85 93 86 94 # New notifications contained in this packet 87 95 def notify(self, pak): 88 96 ................................................................................ 91 99 if time.time() < self.starttm: 92 100 return 93 101 self.starttm = None 94 102 95 103 inner = pak.inner 96 104 log("Notification: gen %d -> %d\n" % (self.gen, inner["gen"])) 97 105 for tup in inner["msgs"]: 98 - lt = len(tup) 106 + 107 + # Possibly record messaged text 108 + if self.logf is not None: 109 + self.logf.write("%s\n" % (tup,)) 110 + self.logf.flush() 99 111 100 112 # Ignore mirrors of our own sends on other devices 113 + lt = len(tup) 101 114 if lt and (not tup[0]): 102 115 continue 103 116 104 117 # No details at all, so just show one notification 105 118 if lt in (0, 1): 106 119 n1 = "New Message" 107 120 n2 = None
Changes to tools/notified.py.
58 58 # Are LEDs available for notification indication? 59 59 LED = "/sys/class/leds/red" 60 60 blinking = leds = False 61 61 62 62 # Initial condition, no events ever seen 63 63 gen = 0 64 64 65 +# Timestamp of our start, for suppressing initial message 66 +# notifications 67 +Started = time.time() 68 + 65 69 # Hook for logging 66 70 def log(s): 67 71 sys.stderr.write(s) 68 72 sys.stderr.write('\n') 69 73 70 74 # Quick/easy way to turn dict into an ob with those k/v as attrs 71 75 class DictOb(object): ................................................................................ 273 277 break 274 278 275 279 # Nothing happened 276 280 if resp.inner["gen"] == gen: 277 281 continue 278 282 279 283 # New messages 280 - notify(resp) 284 + # During startup, we'll get these as we 285 + # catch up, so don't show those initial ones 286 + if (time.time() - Started) > 10: 287 + notify(resp) 288 + 289 + # Always note latest generation 281 290 gen = resp.inner["gen"] 282 291 283 292 if __name__ == "__main__": 284 293 load_cfg() 285 294 286 295 # No arg, just be a service daemon 287 296 if len(sys.argv) == 1: