Skip to content
Snippets Groups Projects
Commit 270f48c5 authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Format for legacy tools

parent 57388ee1
No related branches found
No related tags found
1 merge request!1First try of type hints
......@@ -22,9 +22,11 @@ from xaal.lib import Engine,helpers
helpers.set_console_title("xaal-dumper")
def display(msg):
msg.dump()
def main():
try:
eng = Engine()
......
......@@ -17,21 +17,20 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xaal.lib import Engine, Device
from xaal.lib import tools
import pprint
import sys
import time
import pprint
from xaal.lib import Device, Engine, tools
from .ansi2 import term
def usage():
print("xaal-info xxxx-xxxx-xxxx : display information about a given device")
class InfoDumper:
def __init__(self, engine):
self.eng = engine
# new fake device
......@@ -46,7 +45,6 @@ class InfoDumper:
def query(self, addr):
"""send getDescription & getAttributes and wait for reply"""
self.target = addr
self.msgCnt = 0
self.timer = 0
......@@ -63,7 +61,8 @@ class InfoDumper:
if self.timer > 30:
print("TimeOut...")
break
if self.msgCnt > 1:break
if self.msgCnt > 1:
break
self.timer += 1
print('\n')
......
from xaal.lib import NetworkConnector,config,cbor,core
from xaal.lib import NetworkConnector, cbor, config
class ParseError(Exception):
pass
class ParseError(Exception):pass
def incr(value, max_value, increment=1):
tmp = value + increment
......@@ -8,11 +11,13 @@ def incr(value,max_value,increment=1):
raise ParseError("Unable to go forward, issue w/ packet lenght ?")
return tmp
def hexdump(data):
print("HEX:", end="")
for k in data:
print("0x%x" % k, end=", ")
def parse(data):
i = 0
size = len(data)
......@@ -31,17 +36,17 @@ def parse(data):
i = incr(i, size)
ts0_size = data[i]
if ts0_size not in [0x1a,0x1b]:
if ts0_size not in [0x1A, 0x1B]:
raise ParseError("Wrong timestamp part0 size: 0x%x" % ts0_size)
print("TS0 size (0x1a or 0x1b): 0x%x" % ts0_size)
if ts0_size == 0x1a:
if ts0_size == 0x1A:
i = incr(i, size, 5)
ts0 = list(data[i - 4 : i])
print("TS0: ", end="")
hexdump(ts0)
print("=> %s" % cbor.loads(bytes(data[i - 5 : i])))
if ts0_size == 0x1b:
if ts0_size == 0x1B:
i = incr(i, size, 9)
ts0 = list(data[i - 8 : i])
print("TS0: ", end="")
......@@ -49,7 +54,7 @@ def parse(data):
print("=> %s" % cbor.loads(bytes(data[i - 9 : i])))
ts1_size = data[i]
if ts1_size != 0x1a:
if ts1_size != 0x1A:
raise ParseError("Wrong timestamp part1 size: 0x%x" % ts1_size)
print("TS1 size (0x1a): 0x%x" % ts0_size)
i = incr(i, size, 5)
......@@ -64,6 +69,7 @@ def parse(data):
print()
def main():
nc = NetworkConnector(config.address, config.port, config.hops)
while 1:
......@@ -74,6 +80,7 @@ def main():
except ParseError as e:
print("ERROR ==> %s" % e)
if __name__ == '__main__':
try:
main()
......
......@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from xaal.lib import Engine, Device, tools, config,helpers
from xaal.lib import Engine, Device, tools, helpers
import sys
import time
......@@ -26,8 +26,8 @@ import logging
helpers.setup_console_logger()
logger = logging.getLogger("xaal-isalive")
class Scanner:
class Scanner:
def __init__(self, engine):
self.eng = engine
# new fake device
......@@ -43,7 +43,12 @@ class Scanner:
self.seen = []
logger.info("[%s] searching [%s]" % (self.dev.address, self.dev_type))
self.eng.send_is_alive(self.dev,dev_types=[self.dev_type,])
self.eng.send_is_alive(
self.dev,
dev_types=[
self.dev_type,
],
)
print("=" * 70)
self.loop()
......@@ -77,7 +82,6 @@ class Scanner:
self.seen.append(msg.source)
def run():
"""run the isalive scanner from cmdline"""
eng = Engine()
......@@ -97,11 +101,13 @@ def search(engine,dev_type='any.any'):
scan.query(dev_type)
return scan.seen
def main():
try:
run()
except KeyboardInterrupt:
print("Bye bye")
if __name__ == '__main__':
main()
"""Tool to build a key pass for xAAL config file"""
from __future__ import print_function
from six.moves import input
import binascii
from xaal.lib import tools
import binascii
def main():
try:
......
"""dumb script that display attributes change the xAAL bus"""
from xaal.lib import Engine,helpers,Message
from xaal.lib import Engine, helpers
import time
helpers.set_console_title("xaal-log")
def print_evt(msg):
if msg.is_alive():
return
......@@ -21,5 +22,6 @@ def main():
except KeyboardInterrupt:
print("ByeBye..")
if __name__ == '__main__':
main()
#!/usr/bin/env python
try:
from gevent import monkey;monkey.patch_all(thread=False)
from gevent import monkey
monkey.patch_all(thread=False)
except ModuleNotFoundError:
pass
......@@ -26,11 +27,12 @@ def load_pkgs(eng):
logger.critical("Unable to load module: %s" % xaal_mod)
continue
if hasattr(mod,'setup') == False:
if not hasattr(mod, 'setup'):
logger.critical("Unable to setup %s" % xaal_mod)
continue
mod.setup(eng)
def run():
# some init stuffs
helpers.setup_console_logger()
......@@ -41,6 +43,7 @@ def run():
load_pkgs(eng)
eng.run()
def main():
try:
run()
......
......@@ -17,23 +17,20 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xaal.lib import Engine, Device, MessageType
from xaal.lib import tools
from . import isalive
import sys
import json
import time
from xaal.lib import Device, Engine, MessageType, tools
from . import isalive
from .ansi2 import term
def usage():
print("xaal-querydb xxxx-xxxx-xxxx : display metadata for a given device")
class QueryDB:
def __init__(self, engine, db_servers):
self.eng = engine
self.db_servers = db_servers
......@@ -41,16 +38,17 @@ class QueryDB:
self.addr = tools.get_random_uuid()
self.dev = Device("cli.experimental", self.addr)
self.eng.add_device(self.dev)
self.eng.add_rx_handler(self.parse_answer)
self.eng.subscribe(self.parse_answer)
print("xAAL DB query [%s]" % self.addr)
def query(self, addr):
self.timer = 0
mf = self.eng.msg_factory
body = {'device': addr,}
body = {
'device': addr,
}
msg = mf.build_msg(self.dev, self.db_servers, MessageType.REQUEST, 'get_keys_values', body)
self.eng.queue_msg(msg)
......
......@@ -17,12 +17,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from xaal.lib import Engine,MessageType
from xaal.lib import tools
import shutil
import sys
from xaal.lib import Engine, MessageType, tools
from .ansi2 import term
import sys
import shutil
level = 0
......@@ -37,20 +37,23 @@ def type_to_string(mtype):
def display(msg):
term('yellow')
if (msg.action in HIDE_ACTION and level==2):
if msg.action in HIDE_ACTION and level == 2:
return
if msg.is_reply():
if level > 2: return
if level > 2:
return
term('red')
if msg.is_request():
if level > 3: return
if level > 3:
return
term('green')
if msg.is_notify():
if msg.is_alive():
if level > 0: return
if level > 0:
return
term('grey')
if msg.is_attributes_change():
term('cyan')
......@@ -64,6 +67,7 @@ def display(msg):
res = FORMAT % (type_to_string(msg.msg_type), msg.action, msg.source, msg.dev_type, targets, msg.body)
print(res)
def usage():
print("%s : monitor xAAL network w/ tail format" % sys.argv[0])
print(" usage : %s log-level" % sys.argv[0])
......@@ -94,5 +98,6 @@ def main():
else:
usage()
if __name__ == '__main__':
main()
......@@ -7,7 +7,7 @@ def main():
if len(sys.argv) > 1:
value = sys.argv[1]
uuid = tools.get_uuid(value)
if uuid == None:
if uuid is None:
uuid = tools.get_random_uuid()
print("TXT: %s" % uuid)
......@@ -21,5 +21,6 @@ def main():
print("%d" % b, end=',')
print()
if __name__ == '__main__':
main()
......@@ -9,7 +9,6 @@ import time
import xaal.lib
from . import info
from . import isalive
......@@ -31,5 +30,6 @@ def main():
dumper.query(k)
print("Time : %0.3f sec (%d devices)" % (time.time() - t0, len(devs)))
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment