]> www.average.org Git - loctrkd.git/blobdiff - gps303/mock.py
adjust debianization to wsgateway
[loctrkd.git] / gps303 / mock.py
index 9652fc1c6baadd23883a10a7c57b4f61f00eaf18..ed8c92229ae5aee9f573fa933f20592293d25187 100644 (file)
@@ -1,9 +1,11 @@
-""" Watch for locevt and print them """
+""" Generate and publish locevt from the text input """
 
+import atexit
 from datetime import datetime, timezone
 from logging import getLogger
-from os import umask
-from sys import argv, stdin
+from os import path, umask
+from readline import read_history_file, set_history_length, write_history_file
+from sys import argv
 import zmq
 
 from . import common
@@ -11,6 +13,7 @@ from .zmsg import LocEvt
 
 log = getLogger("gps303/watch")
 
+RL_HISTORY = path.join(path.expanduser("~"), ".gps303_history")
 
 def main(conf):
     zctx = zmq.Context()
@@ -18,13 +21,19 @@ def main(conf):
     oldmask = umask(0o117)
     zpub.bind(conf.get("lookaside", "publishurl"))
     umask(oldmask)
+    try:
+        read_history_file(RL_HISTORY)
+    except FileNotFoundError:
+        pass
+    set_history_length(1000)
+    atexit.register(write_history_file, RL_HISTORY)
 
     while True:
-        line = stdin.readline()
-        line = line.rstrip("\r\n")
-        if not line:
+        try:
+            line = input("> ")
+        except EOFError:
             break
-        print(line.encode())
+        line = line.rstrip("\r\n")
         args = line.split(" ")
         imei = args[0]
         kwargs = dict([arg.split("=") for arg in args[1:]])