Browse Source

more documentation

master
Volker Birk 6 years ago
parent
commit
8548bfd9ac
  1. 23
      test/minimail.py
  2. 9
      test/sync_handshake.py

23
test/minimail.py

@ -1,5 +1,17 @@
# vim: set fileencoding=utf-8 : # vim: set fileencoding=utf-8 :
"""provide a trivial way to send messages between processes
messages are being sent to an inbox using a filename as a marker
recv_all() is delivering all messages, which are newer than the marker file
after completion reading is touching the marker file
to re-read messages touch the marker file with an older timestamp or just
delete the marker file to re-read all messages
"""
# Minimail # Minimail
# Copyleft 2019, p≡p foundation # Copyleft 2019, p≡p foundation
@ -13,6 +25,8 @@ from time import sleep
def unlock(inbox): def unlock(inbox):
"clear the inbox from lockfile"
lockfile = inbox / "lock" lockfile = inbox / "lock"
try: try:
lockfile.unlink() lockfile.unlink()
@ -21,6 +35,8 @@ def unlock(inbox):
class Lock: class Lock:
"lock inbox context to be used by with statement"
def __init__(self, inbox): def __init__(self, inbox):
self.inbox = inbox self.inbox = inbox
@ -35,6 +51,8 @@ class Lock:
def send(inbox, msg): def send(inbox, msg):
"send msg to inbox in MIME format"
with Lock(inbox): with Lock(inbox):
name = token_urlsafe(16) + ".eml" name = token_urlsafe(16) + ".eml"
with open(inbox / name, "wb") as f: with open(inbox / name, "wb") as f:
@ -42,6 +60,8 @@ def send(inbox, msg):
def newer(file1, file2=None): def newer(file1, file2=None):
"return True if file1 is newer than file2"
if not file1.is_file(): if not file1.is_file():
return False return False
elif not file2.is_file(): elif not file2.is_file():
@ -53,6 +73,9 @@ def newer(file1, file2=None):
def recv_all(inbox, marker): def recv_all(inbox, marker):
"""receive a list of new MIME messages from inbox, which are newer than the
marker file"""
r = [] r = []
while not r: while not r:
for p in inbox.glob("*.eml"): for p in inbox.glob("*.eml"):

9
test/sync_handshake.py

@ -46,10 +46,15 @@ if __name__=="__main__":
from optparse import OptionParser from optparse import OptionParser
optParser = OptionParser() optParser = OptionParser()
optParser.description = "do not run this manually" optParser.description = "For debugging try: $ cd $DEV && lldb python3 -- " \
+ "sync_handshake.py -e $DEV"
optParser.add_option("-e", "--exec-for", action="store", type="string", optParser.add_option("-e", "--exec-for", action="store", type="string",
dest="exec_for", help="execute for name") dest="exec_for", help="execute for name of simulated device")
options, args = optParser.parse_args() options, args = optParser.parse_args()
if not options.exec_for:
raise SyntaxError("--exec-for is mandatory, try --help")
run(options.exec_for) run(options.exec_for)

Loading…
Cancel
Save