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
......@@ -18,13 +18,15 @@
#
from xaal.lib import Engine,helpers
from xaal.lib import Engine, helpers
helpers.set_console_title("xaal-dumper")
def display(msg):
msg.dump()
def main():
try:
eng = Engine()
......
......@@ -17,26 +17,25 @@
# 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):
def __init__(self, engine):
self.eng = engine
# new fake device
addr = tools.get_random_uuid()
dev = Device("cli.experimental",addr)
dev = Device("cli.experimental", addr)
dev.vendor_id = "IHSEV"
dev.product_id = "xAAL InfoDumper"
self.eng.add_device(dev)
......@@ -44,9 +43,8 @@ class InfoDumper:
print(f"xAAL Info dumper [{addr}]")
self.dev = dev
def query(self,addr):
""" send getDescription & getAttributes and wait for reply"""
def query(self, addr):
"""send getDescription & getAttributes and wait for reply"""
self.target = addr
self.msgCnt = 0
self.timer = 0
......@@ -63,12 +61,13 @@ class InfoDumper:
if self.timer > 30:
print("TimeOut...")
break
if self.msgCnt > 1:break
if self.msgCnt > 1:
break
self.timer += 1
print('\n')
def parse_answer(self,msg):
""" message parser """
def parse_answer(self, msg):
"""message parser"""
if msg.is_reply():
if self.dev.address in msg.targets:
if self.target == msg.source:
......@@ -91,7 +90,7 @@ def main():
eng.start()
dev = InfoDumper(eng)
dev.query(addr)
print("Time : %0.3f sec" % (time.time() -t0))
print("Time : %0.3f sec" % (time.time() - t0))
else:
print("Invalid addr")
......
from xaal.lib import NetworkConnector,config,cbor,core
from xaal.lib import NetworkConnector, cbor, config
class ParseError(Exception):pass
def incr(value,max_value,increment=1):
class ParseError(Exception):
pass
def incr(value, max_value, increment=1):
tmp = value + increment
if tmp > max_value:
raise ParseError("Unable to go forward, issue w/ packet lenght ?")
return tmp
def hexdump(data):
print("HEX:",end="")
print("HEX:", end="")
for k in data:
print("0x%x" % k,end=", ")
print("0x%x" % k, end=", ")
def parse(data):
i = 0
......@@ -21,51 +26,52 @@ def parse(data):
header_size = data[i]
if header_size != 0x85:
raise ParseError("Wrong array in header: 0x%x" % header_size)
print("Array w/ size=5 (0x85) : 0x%x" %header_size)
print("Array w/ size=5 (0x85) : 0x%x" % header_size)
i = incr(i,size)
i = incr(i, size)
ver = data[i]
if ver != 7:
raise ParseError("Wrong packet version: 0x%x" % ver)
print("Version: 0%x" % ver)
i = incr(i,size)
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:
i=incr(i,size,5)
ts0 = list(data[i-4:i])
print("TS0: ",end="")
print("TS0 size (0x1a or 0x1b): 0x%x" % ts0_size)
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])))
print("=> %s" % cbor.loads(bytes(data[i - 5 : i])))
if ts0_size == 0x1b:
i=incr(i,size,9)
ts0 = list(data[i-8:i])
print("TS0: ",end="")
if ts0_size == 0x1B:
i = incr(i, size, 9)
ts0 = list(data[i - 8 : i])
print("TS0: ", end="")
hexdump(ts0)
print("=> %s" % cbor.loads(bytes(data[i-9:i])))
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)
ts1 = list(data[i-4:i])
print("TS1: ",end="")
print("TS1 size (0x1a): 0x%x" % ts0_size)
i = incr(i, size, 5)
ts1 = list(data[i - 4 : i])
print("TS1: ", end="")
hexdump(ts1)
print("=> %s" % cbor.loads(bytes(data[i-5:i])))
print("=> %s" % cbor.loads(bytes(data[i - 5 : i])))
target_size = data[i]
hexdump(data[i:i+10])
#print("0x%x" % target_size)
hexdump(data[i : i + 10])
# print("0x%x" % target_size)
print()
def main():
nc = NetworkConnector(config.address,config.port,config.hops)
nc = NetworkConnector(config.address, config.port, config.hops)
while 1:
data = nc.get_data()
if data:
......@@ -74,9 +80,10 @@ def main():
except ParseError as e:
print("ERROR ==> %s" % e)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print("Bye...")
\ No newline at end of file
......@@ -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,28 +26,33 @@ import logging
helpers.setup_console_logger()
logger = logging.getLogger("xaal-isalive")
class Scanner:
def __init__(self,engine):
class Scanner:
def __init__(self, engine):
self.eng = engine
# new fake device
self.dev = Device("cli.experimental",tools.get_random_uuid())
self.dev = Device("cli.experimental", tools.get_random_uuid())
self.eng.add_device(self.dev)
self.eng.subscribe(self.parse_answer)
def query(self,dev_type):
def query(self, dev_type):
if not tools.is_valid_dev_type(dev_type):
logger.warning("dev_type not valid [%s]" % dev_type)
return
self.dev_type = dev_type
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,])
logger.info("[%s] searching [%s]" % (self.dev.address, self.dev_type))
self.eng.send_is_alive(
self.dev,
dev_types=[
self.dev_type,
],
)
print("="*70)
print("=" * 70)
self.loop()
print("="*70)
print("=" * 70)
print("Found %d devices" % len(self.seen))
def loop(self):
......@@ -57,15 +62,15 @@ class Scanner:
if time.time() > (t0 + 2):
break
def parse_answer(self,msg):
def parse_answer(self, msg):
if msg.is_alive():
# hidding myself
if msg.source == self.dev.address:
return
#it is really for us ?
# it is really for us ?
if self.dev_type != 'any.any':
(target_dev_type,target_devsubtype) = self.dev_type.split('.')
(msg_dev_type,msg_devsubtype) = msg.dev_type.split('.')
(target_dev_type, target_devsubtype) = self.dev_type.split('.')
(msg_dev_type, msg_devsubtype) = msg.dev_type.split('.')
if msg_dev_type != target_dev_type:
return
if target_devsubtype != 'any' and target_devsubtype != msg_devsubtype:
......@@ -73,13 +78,12 @@ class Scanner:
if msg.source in self.seen:
return
# everything is Ok :)
print("%s : %s" % (msg.source,msg.dev_type))
print("%s : %s" % (msg.source, msg.dev_type))
self.seen.append(msg.source)
def run():
""" run the isalive scanner from cmdline"""
"""run the isalive scanner from cmdline"""
eng = Engine()
eng.disable_msg_filter()
......@@ -91,17 +95,19 @@ def run():
scan.query(dev_type)
def search(engine,dev_type='any.any'):
""" send request and return list of xaal-addr"""
def search(engine, dev_type='any.any'):
"""send request and return list of xaal-addr"""
scan = Scanner(engine)
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
"""Tool to build a key pass for xAAL config file"""
import binascii
from xaal.lib import tools
import binascii
def main():
try:
temp = input("Please enter your passphrase: ")
key = tools.pass2key(temp)
key = tools.pass2key(temp)
print("Cut & Paste this key in your xAAL config-file")
print("key=%s"% binascii.hexlify(key).decode('utf-8'))
print("key=%s" % binascii.hexlify(key).decode('utf-8'))
except KeyboardInterrupt:
print("Bye Bye..")
if __name__ == '__main__':
main()
""" dumb script that display attributes change the xAAL bus"""
"""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
if msg.is_notify():
print("%s %s %s %s %s" % (time.ctime(),msg.source,msg.dev_type,msg.action,msg.body))
print("%s %s %s %s %s" % (time.ctime(), msg.source, msg.dev_type, msg.action, msg.body))
def main():
......@@ -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
......@@ -23,23 +24,25 @@ def load_pkgs(eng):
try:
mod = importlib.import_module(xaal_mod)
except ModuleNotFoundError:
logger.critical("Unable to load module: %s" %xaal_mod )
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()
#helpers.setup_file_logger(MY_NAME)
# helpers.setup_file_logger(MY_NAME)
# Start the engine
eng = Engine()
eng.start()
load_pkgs(eng)
eng.run()
eng.run()
def main():
try:
......
......@@ -17,41 +17,39 @@
# 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):
def __init__(self, engine, db_servers):
self.eng = engine
self.db_servers = db_servers
# new fake device
self.addr = tools.get_random_uuid()
self.dev = Device("cli.experimental",self.addr)
self.dev = Device("cli.experimental", self.addr)
self.eng.add_device(self.dev)
self.eng.add_rx_handler(self.parse_answer)
print("xAAL DB query [%s]" % self.addr)
self.eng.subscribe(self.parse_answer)
print("xAAL DB query [%s]" % self.addr)
def query(self,addr):
def query(self, addr):
self.timer = 0
mf = self.eng.msg_factory
body = {'device': addr,}
msg = mf.build_msg(self.dev,self.db_servers, MessageType.REQUEST,'get_keys_values',body)
body = {
'device': addr,
}
msg = mf.build_msg(self.dev, self.db_servers, MessageType.REQUEST, 'get_keys_values', body)
self.eng.queue_msg(msg)
while 1:
......@@ -62,12 +60,12 @@ class QueryDB:
self.timer += 1
print('\n')
def parse_answer(self,msg):
""" message parser """
def parse_answer(self, msg):
"""message parser"""
if msg.is_reply():
if (self.addr in msg.targets) and (msg.action == 'get_keys_values'):
term('yellow')
print("%s => " % msg.source,end='')
print("%s => " % msg.source, end='')
print(msg.body)
term()
......@@ -79,13 +77,13 @@ def main():
t0 = time.time()
eng = Engine()
eng.start()
db_servers = isalive.search(eng,'metadatadb.basic')
db_servers = isalive.search(eng, 'metadatadb.basic')
if len(db_servers) == 0:
print("No metadb server found")
return
dev = QueryDB(eng,db_servers)
dev = QueryDB(eng, db_servers)
dev.query(addr)
print("Time : %0.3f sec" % (time.time() -t0))
print("Time : %0.3f sec" % (time.time() - t0))
else:
print("Invalid addr")
......
......@@ -17,16 +17,16 @@
# 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
HIDE_ACTION=['get_attributes','get_description','get_keys_values','is_alive']
HIDE_ACTION = ['get_attributes', 'get_description', 'get_keys_values', 'is_alive']
def type_to_string(mtype):
......@@ -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')
......@@ -59,11 +62,12 @@ def display(msg):
tmp = shutil.get_terminal_size()[0] - (8 + 20 + 36 + 20 + 16 + 9)
if tmp < 50:
tmp = 50
BODY_FORMAT = '%-50.'+str(tmp)+'s'
FORMAT = '%-8.08s=> %-18.18s %-36.36s (%-20.20s) %-16.16s '+BODY_FORMAT
res = FORMAT % (type_to_string(msg.msg_type),msg.action,msg.source,msg.dev_type,targets,msg.body)
BODY_FORMAT = '%-50.' + str(tmp) + 's'
FORMAT = '%-8.08s=> %-18.18s %-36.36s (%-20.20s) %-16.16s ' + BODY_FORMAT
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])
......@@ -85,8 +89,8 @@ def main():
eng.start()
term('@@')
FORMAT = '%-8.08s=> %-18.18s %-36.36s (%-20.20s) %-16.16s %-50.50s'
print(FORMAT % ('type','action','source','dev_type','targets','body'))
FORMAT = '%-8.08s=> %-18.18s %-36.36s (%-20.20s) %-16.16s %-50.50s'
print(FORMAT % ('type', 'action', 'source', 'dev_type', 'targets', 'body'))
try:
eng.run()
except KeyboardInterrupt:
......@@ -94,5 +98,6 @@ def main():
else:
usage()
if __name__ == '__main__':
main()
......@@ -7,19 +7,20 @@ def main():
if len(sys.argv) > 1:
value = sys.argv[1]
uuid = tools.get_uuid(value)
if uuid == None:
uuid=tools.get_random_uuid()
if uuid is None:
uuid = tools.get_random_uuid()
print("TXT: %s" % uuid)
print("HEX: ",end="")
print("HEX: ", end="")
for b in uuid.bytes:
print("0x%x" % b,end=',')
print("0x%x" % b, end=',')
print()
print("INT: ",end="")
print("INT: ", end="")
for b in uuid.bytes:
print("%d" % b,end=',')
print("%d" % b, end=',')
print()
if __name__ == '__main__':
main()
......@@ -9,13 +9,12 @@ import time
import xaal.lib
from . import info
from . import isalive
def main():
""" search for alive devices and gather informations about this device"""
"""search for alive devices and gather informations about this device"""
eng = xaal.lib.Engine()
eng.disable_msg_filter()
......@@ -23,13 +22,14 @@ def main():
devtype = 'any.any'
if len(sys.argv) == 2:
devtype = sys.argv[1]
devs = isalive.search(eng,devtype)
devs = isalive.search(eng, devtype)
print()
dumper = info.InfoDumper(eng)
t0 = time.time()
for k in devs:
dumper.query(k)
print("Time : %0.3f sec (%d devices)" % (time.time() -t0,len(devs)))
print("Time : %0.3f sec (%d devices)" % (time.time() - t0, len(devs)))
if __name__=='__main__':
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment