xaal.legacytools 0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.1
2
+ Name: xaal.legacytools
3
+ Version: 0.1
4
+ Summary: xAAL devices tools
5
+ Author-email: Jerome Kerdreux <Jerome.Kerdreux@imt-atlantique.fr>
6
+ License: GPL License
7
+ Keywords: xaal,tools
8
+ Classifier: Programming Language :: Python
9
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
10
+ Description-Content-Type: text/x-rst
11
+ Requires-Dist: xaal.lib
File without changes
@@ -0,0 +1,27 @@
1
+ [project]
2
+ name = "xaal.legacytools"
3
+ version = "0.1"
4
+ description = "xAAL devices tools"
5
+ readme = "README.rst"
6
+ authors = [ { name = "Jerome Kerdreux", email = "Jerome.Kerdreux@imt-atlantique.fr" } ]
7
+ license = { text = "GPL License"}
8
+ classifiers = ["Programming Language :: Python",
9
+ "Topic :: Software Development :: Libraries :: Python Modules"]
10
+ keywords = ["xaal", "tools"]
11
+ dependencies = ["xaal.lib"]
12
+
13
+ [project.scripts]
14
+ xaal-isalive-legacy = "xaal.legacytools.isalive:main"
15
+ xaal-info-legacy = "xaal.legacytools.info:main"
16
+ xaal-dumper-legacy = "xaal.legacytools.dumper:main"
17
+ xaal-tail-legacy = "xaal.legacytools.tail:main"
18
+ xaal-walker-legacy = "xaal.legacytools.walker:main"
19
+ xaal-keygen-legacy = "xaal.legacytools.keygen:main"
20
+ xaal-log-legacy = "xaal.legacytools.log:main"
21
+ xaal-querydb-legacy = "xaal.legacytools.querydb:main"
22
+ xaal-pkgrun-legacy = "xaal.legacytools.pkgrun:main"
23
+ xaal-uuidgen-legacy = "xaal.legacytools.uuidgen:main"
24
+ xaal-inspector-legacy = "xaal.legacytools.inspector:main"
25
+
26
+ [tool.setuptools.packages.find]
27
+ include = ["xaal.legacytools"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,113 @@
1
+ '''
2
+ Set ANSI Terminal Color and Attributes.
3
+ '''
4
+ from sys import stdout
5
+
6
+ esc = '%s['%chr(27)
7
+ reset = '%s0m'%esc
8
+ format = '1;%dm'
9
+ fgoffset, bgoffset = 30, 40
10
+ for k, v in dict(
11
+ attrs = 'none bold faint italic underline blink fast reverse concealed',
12
+ colors = 'grey red green yellow blue magenta cyan white'
13
+ ).items(): globals()[k]=dict((s,i) for i,s in enumerate(v.split()))
14
+
15
+ def term(arg=None, sep=' ', end='\n'):
16
+ '''
17
+ "arg" is a string or None
18
+ if "arg" is None : the terminal is reset to his default values.
19
+ if "arg" is a string it must contain "sep" separated values.
20
+ if args are found in globals "attrs" or "colors", or start with "@" \
21
+ they are interpreted as ANSI commands else they are output as text.
22
+ colors, if any, must be first (foreground first then background)
23
+ you can not specify a background color alone ; \
24
+ if you specify only one color, it will be the foreground one.
25
+ @* commands handle the screen and the cursor :
26
+ @x;y : go to xy
27
+ @ : go to 1;1
28
+ @@ : clear screen and go to 1;1
29
+
30
+ examples:
31
+ term('red') : set red as the foreground color
32
+ term('red blue') : red on blue
33
+ term('red blink') : blinking red
34
+ term() : restore terminal default values
35
+ term('reverse') : swap default colors
36
+ term('cyan blue reverse') : blue on cyan <=> term('blue cyan)
37
+ term('red reverse') : a way to set up the background only
38
+ term('red reverse blink') : you can specify any combinaison of \
39
+ attributes in any order with or without colors
40
+ term('blink Python') : output a blinking 'Python'
41
+ term('@@ hello') : clear the screen and print 'hello' at 1;1
42
+ '''
43
+ cmd, txt = [reset], []
44
+ if arg:
45
+ arglist=arg.split(sep)
46
+ for offset in (fgoffset, bgoffset):
47
+ if arglist and arglist[0] in colors:
48
+ cmd.append(format % (colors[arglist.pop(0)]+offset))
49
+ for a in arglist:
50
+ c=format % attrs[a] if a in attrs else None
51
+ if c and c not in cmd:
52
+ cmd.append(c)
53
+ else:
54
+ if a.startswith('@'):
55
+ a=a[1:]
56
+ if a=='@':
57
+ cmd.append('2J')
58
+ cmd.append('H')
59
+ else:
60
+ cmd.append('%sH'%a)
61
+ else:
62
+ txt.append(a)
63
+ if txt and end: txt[-1]+=end
64
+ # JKX debug
65
+ #print cmd
66
+ stdout.write(esc.join(cmd)+sep.join(txt))
67
+
68
+ if __name__ == '__main__':
69
+
70
+ print()
71
+ term('@@ reverse blink')
72
+ print('reverse blink default colors at 1;1 on a cleared screen')
73
+ term('red')
74
+ print('red')
75
+ term('red blue')
76
+ print('red blue')
77
+ term('yellow blink')
78
+ print('yellow blink')
79
+ term('default')
80
+ term('cyan blue cyan blue')
81
+ term('cyan blue reverse cyan blue reverse')
82
+ term('blue cyan blue cyan')
83
+ term('red reverse red reverse')
84
+ term('yellow red yellow on red 1')
85
+ term('yellow,red,yellow on red 2', sep=',')
86
+ print('yellow on red 3')
87
+ print()
88
+ for bg in colors:
89
+ term(bg.title().center(8), sep='.', end='')
90
+ for fg in colors:
91
+ att=[fg, bg]
92
+ if fg==bg: att.append('blink')
93
+ att.append(fg.center(8))
94
+ term(','.join(att), sep=',', end='')
95
+ print()
96
+ print()
97
+ for att in attrs:
98
+ term('%s,%s' % (att, att.title().center(10)), sep=',', end='')
99
+ print()
100
+ from time import sleep, strftime, gmtime
101
+ colist='grey blue cyan white cyan blue'.split()
102
+ while True:
103
+ try:
104
+ for c in colist:
105
+ sleep(.1)
106
+ term('%s @28;33 hit ctrl-c to quit' % c)
107
+ term('yellow @6;66 %s' % strftime('%H:%M:%S', gmtime()))
108
+ except KeyboardInterrupt:
109
+ break
110
+ except:
111
+ raise
112
+ term('@30;1')
113
+ print()
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ #
4
+ # Copyright 2014 Jérôme Colin, Jérôme Kerdreux, Telecom Bretagne.
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+
21
+ from xaal.lib import Engine,helpers
22
+
23
+ helpers.set_console_title("xaal-dumper")
24
+
25
+ def display(msg):
26
+ msg.dump()
27
+
28
+ def main():
29
+ try:
30
+ eng = Engine()
31
+ eng.subscribe(display)
32
+ eng.disable_msg_filter()
33
+ eng.run()
34
+ except KeyboardInterrupt:
35
+ print("Bye Bye")
36
+
37
+
38
+ if __name__ == '__main__':
39
+ main()
@@ -0,0 +1,103 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ #
4
+ # Copyright 2016 Jérôme Kerdreux, IMT Atlantique.
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+
20
+ from xaal.lib import Engine, Device
21
+ from xaal.lib import tools
22
+
23
+ import sys
24
+ import time
25
+ import pprint
26
+
27
+ from .ansi2 import term
28
+
29
+ def usage():
30
+ print("xaal-info xxxx-xxxx-xxxx : display information about a given device")
31
+
32
+
33
+ class InfoDumper:
34
+
35
+ def __init__(self,engine):
36
+ self.eng = engine
37
+ # new fake device
38
+ addr = tools.get_random_uuid()
39
+ dev = Device("cli.experimental",addr)
40
+ dev.vendor_id = "IHSEV"
41
+ dev.product_id = "xAAL InfoDumper"
42
+ self.eng.add_device(dev)
43
+ self.eng.subscribe(self.parse_answer)
44
+ print(f"xAAL Info dumper [{addr}]")
45
+ self.dev = dev
46
+
47
+ def query(self,addr):
48
+ """ send getDescription & getAttributes and wait for reply"""
49
+
50
+ self.target = addr
51
+ self.msgCnt = 0
52
+ self.timer = 0
53
+
54
+ self.eng.send_get_description(self.dev,[addr,])
55
+ self.eng.send_get_attributes(self.dev,[addr,])
56
+
57
+ term('cyan')
58
+ print("** Device : [%s]" % self.target)
59
+ term()
60
+
61
+ while 1:
62
+ self.eng.loop()
63
+ if self.timer > 30:
64
+ print("TimeOut...")
65
+ break
66
+ if self.msgCnt > 1:break
67
+ self.timer += 1
68
+ print('\n')
69
+
70
+ def parse_answer(self,msg):
71
+ """ message parser """
72
+ if msg.is_reply():
73
+ if self.dev.address in msg.targets:
74
+ if self.target == msg.source:
75
+ if msg.is_get_attribute_reply():
76
+ print("== Attributes =====")
77
+
78
+ if msg.is_get_description_reply():
79
+ print("== Description ====")
80
+
81
+ pprint.pprint(msg.body)
82
+ self.msgCnt += 1
83
+
84
+
85
+ def main():
86
+ if len(sys.argv) == 2:
87
+ addr = tools.get_uuid(sys.argv[1])
88
+ if addr:
89
+ t0 = time.time()
90
+ eng = Engine()
91
+ eng.start()
92
+ dev = InfoDumper(eng)
93
+ dev.query(addr)
94
+ print("Time : %0.3f sec" % (time.time() -t0))
95
+ else:
96
+ print("Invalid addr")
97
+
98
+ else:
99
+ usage()
100
+
101
+
102
+ if __name__ == '__main__':
103
+ main()
@@ -0,0 +1,82 @@
1
+ from xaal.lib import NetworkConnector,config,cbor,core
2
+
3
+ class ParseError(Exception):pass
4
+
5
+ def incr(value,max_value,increment=1):
6
+ tmp = value + increment
7
+ if tmp > max_value:
8
+ raise ParseError("Unable to go forward, issue w/ packet lenght ?")
9
+ return tmp
10
+
11
+ def hexdump(data):
12
+ print("HEX:",end="")
13
+ for k in data:
14
+ print("0x%x" % k,end=", ")
15
+
16
+ def parse(data):
17
+ i = 0
18
+ size = len(data)
19
+
20
+ print("========= Headers ========")
21
+ header_size = data[i]
22
+ if header_size != 0x85:
23
+ raise ParseError("Wrong array in header: 0x%x" % header_size)
24
+ print("Array w/ size=5 (0x85) : 0x%x" %header_size)
25
+
26
+ i = incr(i,size)
27
+ ver = data[i]
28
+ if ver != 7:
29
+ raise ParseError("Wrong packet version: 0x%x" % ver)
30
+ print("Version: 0%x" % ver)
31
+
32
+ i = incr(i,size)
33
+ ts0_size = data[i]
34
+ if ts0_size not in [0x1a,0x1b]:
35
+ raise ParseError("Wrong timestamp part0 size: 0x%x" % ts0_size)
36
+ print("TS0 size (0x1a or 0x1b): 0x%x" % ts0_size )
37
+ if ts0_size == 0x1a:
38
+ i=incr(i,size,5)
39
+ ts0 = list(data[i-4:i])
40
+ print("TS0: ",end="")
41
+ hexdump(ts0)
42
+ print("=> %s" % cbor.loads(bytes(data[i-5:i])))
43
+
44
+ if ts0_size == 0x1b:
45
+ i=incr(i,size,9)
46
+ ts0 = list(data[i-8:i])
47
+ print("TS0: ",end="")
48
+ hexdump(ts0)
49
+ print("=> %s" % cbor.loads(bytes(data[i-9:i])))
50
+
51
+ ts1_size = data[i]
52
+ if ts1_size != 0x1a:
53
+ raise ParseError("Wrong timestamp part1 size: 0x%x" % ts1_size)
54
+ print("TS1 size (0x1a): 0x%x" % ts0_size )
55
+ i = incr(i,size,5)
56
+ ts1 = list(data[i-4:i])
57
+ print("TS1: ",end="")
58
+ hexdump(ts1)
59
+ print("=> %s" % cbor.loads(bytes(data[i-5:i])))
60
+
61
+ target_size = data[i]
62
+ hexdump(data[i:i+10])
63
+ #print("0x%x" % target_size)
64
+
65
+ print()
66
+
67
+ def main():
68
+ nc = NetworkConnector(config.address,config.port,config.hops)
69
+ while 1:
70
+ data = nc.get_data()
71
+ if data:
72
+ try:
73
+ parse(data)
74
+ except ParseError as e:
75
+ print("ERROR ==> %s" % e)
76
+
77
+ if __name__ == '__main__':
78
+ try:
79
+ main()
80
+ except KeyboardInterrupt:
81
+ print("Bye...")
82
+
@@ -0,0 +1,107 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ #
4
+ # Copyright 2014 Jérôme Kerdreux, Telecom Bretagne.
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ from xaal.lib import Engine, Device, tools, config,helpers
21
+
22
+ import sys
23
+ import time
24
+ import logging
25
+
26
+ helpers.setup_console_logger()
27
+ logger = logging.getLogger("xaal-isalive")
28
+
29
+ class Scanner:
30
+
31
+ def __init__(self,engine):
32
+ self.eng = engine
33
+ # new fake device
34
+ self.dev = Device("cli.experimental",tools.get_random_uuid())
35
+ self.eng.add_device(self.dev)
36
+ self.eng.subscribe(self.parse_answer)
37
+
38
+ def query(self,dev_type):
39
+ if not tools.is_valid_dev_type(dev_type):
40
+ logger.warning("dev_type not valid [%s]" % dev_type)
41
+ return
42
+ self.dev_type = dev_type
43
+ self.seen = []
44
+
45
+ logger.info("[%s] searching [%s]" % (self.dev.address,self.dev_type))
46
+ self.eng.send_is_alive(self.dev,dev_types=[self.dev_type,])
47
+
48
+ print("="*70)
49
+ self.loop()
50
+ print("="*70)
51
+ print("Found %d devices" % len(self.seen))
52
+
53
+ def loop(self):
54
+ t0 = time.time()
55
+ while 1:
56
+ self.eng.loop()
57
+ if time.time() > (t0 + 2):
58
+ break
59
+
60
+ def parse_answer(self,msg):
61
+ if msg.is_alive():
62
+ # hidding myself
63
+ if msg.source == self.dev.address:
64
+ return
65
+ #it is really for us ?
66
+ if self.dev_type != 'any.any':
67
+ (target_dev_type,target_devsubtype) = self.dev_type.split('.')
68
+ (msg_dev_type,msg_devsubtype) = msg.dev_type.split('.')
69
+ if msg_dev_type != target_dev_type:
70
+ return
71
+ if target_devsubtype != 'any' and target_devsubtype != msg_devsubtype:
72
+ return
73
+ if msg.source in self.seen:
74
+ return
75
+ # everything is Ok :)
76
+ print("%s : %s" % (msg.source,msg.dev_type))
77
+ self.seen.append(msg.source)
78
+
79
+
80
+
81
+ def run():
82
+ """ run the isalive scanner from cmdline"""
83
+ eng = Engine()
84
+ eng.disable_msg_filter()
85
+
86
+ scan = Scanner(eng)
87
+ eng.start()
88
+ dev_type = 'any.any'
89
+ if len(sys.argv) == 2:
90
+ dev_type = sys.argv[1]
91
+ scan.query(dev_type)
92
+
93
+
94
+ def search(engine,dev_type='any.any'):
95
+ """ send request and return list of xaal-addr"""
96
+ scan = Scanner(engine)
97
+ scan.query(dev_type)
98
+ return scan.seen
99
+
100
+ def main():
101
+ try:
102
+ run()
103
+ except KeyboardInterrupt:
104
+ print("Bye bye")
105
+
106
+ if __name__ == '__main__':
107
+ main()
@@ -0,0 +1,22 @@
1
+ """ Tool to build a key pass for xAAL config file"""
2
+
3
+ from __future__ import print_function
4
+
5
+ from six.moves import input
6
+
7
+
8
+ from xaal.lib import tools
9
+ import binascii
10
+
11
+ def main():
12
+ try:
13
+ temp = input("Please enter your passphrase: ")
14
+ key = tools.pass2key(temp)
15
+ print("Cut & Paste this key in your xAAL config-file")
16
+ print("key=%s"% binascii.hexlify(key).decode('utf-8'))
17
+ except KeyboardInterrupt:
18
+ print("Bye Bye..")
19
+
20
+
21
+ if __name__ == '__main__':
22
+ main()
@@ -0,0 +1,25 @@
1
+ """ dumb script that display attributes change the xAAL bus"""
2
+
3
+ from xaal.lib import Engine,helpers,Message
4
+ import time
5
+
6
+ helpers.set_console_title("xaal-log")
7
+
8
+ def print_evt(msg):
9
+ if msg.is_alive():
10
+ return
11
+ if msg.is_notify():
12
+ print("%s %s %s %s %s" % (time.ctime(),msg.source,msg.dev_type,msg.action,msg.body))
13
+
14
+
15
+ def main():
16
+ try:
17
+ eng = Engine()
18
+ eng.disable_msg_filter()
19
+ eng.subscribe(print_evt)
20
+ eng.run()
21
+ except KeyboardInterrupt:
22
+ print("ByeBye..")
23
+
24
+ if __name__ == '__main__':
25
+ main()
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env python
2
+ try:
3
+ from gevent import monkey;monkey.patch_all(thread=False)
4
+ except ModuleNotFoundError:
5
+ pass
6
+
7
+ import sys
8
+ import importlib
9
+
10
+
11
+ from xaal.lib import helpers
12
+ from xaal.lib import AsyncEngine as Engine
13
+ import logging
14
+
15
+
16
+ MY_NAME = "xaal-pkgrun"
17
+ logger = logging.getLogger(MY_NAME)
18
+
19
+
20
+ def load_pkgs(eng):
21
+ for k in sys.argv[1:]:
22
+ xaal_mod = 'xaal.' + k
23
+ try:
24
+ mod = importlib.import_module(xaal_mod)
25
+ except ModuleNotFoundError:
26
+ logger.critical("Unable to load module: %s" %xaal_mod )
27
+ continue
28
+
29
+ if hasattr(mod,'setup') == False:
30
+ logger.critical("Unable to setup %s" % xaal_mod)
31
+ continue
32
+ mod.setup(eng)
33
+
34
+ def run():
35
+ # some init stuffs
36
+ helpers.setup_console_logger()
37
+ #helpers.setup_file_logger(MY_NAME)
38
+ # Start the engine
39
+ eng = Engine()
40
+ eng.start()
41
+ load_pkgs(eng)
42
+ eng.run()
43
+
44
+ def main():
45
+ try:
46
+ run()
47
+ except KeyboardInterrupt:
48
+ print("Byebye")
49
+
50
+
51
+ if __name__ == '__main__':
52
+ main()
@@ -0,0 +1,97 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ #
4
+ # Copyright 2016 Jérôme Kerdreux, IMT Atlantique.
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+
20
+ from xaal.lib import Engine, Device, MessageType
21
+ from xaal.lib import tools
22
+ from . import isalive
23
+
24
+
25
+ import sys
26
+ import json
27
+ import time
28
+
29
+ from .ansi2 import term
30
+
31
+ def usage():
32
+ print("xaal-querydb xxxx-xxxx-xxxx : display metadata for a given device")
33
+
34
+
35
+ class QueryDB:
36
+
37
+ def __init__(self,engine,db_servers):
38
+ self.eng = engine
39
+ self.db_servers = db_servers
40
+ # new fake device
41
+ self.addr = tools.get_random_uuid()
42
+ self.dev = Device("cli.experimental",self.addr)
43
+ self.eng.add_device(self.dev)
44
+ self.eng.add_rx_handler(self.parse_answer)
45
+
46
+ print("xAAL DB query [%s]" % self.addr)
47
+
48
+
49
+ def query(self,addr):
50
+ self.timer = 0
51
+
52
+ mf = self.eng.msg_factory
53
+ body = {'device': addr,}
54
+ msg = mf.build_msg(self.dev,self.db_servers, MessageType.REQUEST,'get_keys_values',body)
55
+ self.eng.queue_msg(msg)
56
+
57
+ while 1:
58
+ self.eng.loop()
59
+ if self.timer > 40:
60
+ print("TimeOut...")
61
+ break
62
+ self.timer += 1
63
+ print('\n')
64
+
65
+ def parse_answer(self,msg):
66
+ """ message parser """
67
+ if msg.is_reply():
68
+ if (self.addr in msg.targets) and (msg.action == 'get_keys_values'):
69
+ term('yellow')
70
+ print("%s => " % msg.source,end='')
71
+ print(msg.body)
72
+ term()
73
+
74
+
75
+ def main():
76
+ if len(sys.argv) == 2:
77
+ addr = tools.get_uuid(sys.argv[1])
78
+ if tools.is_valid_address(addr):
79
+ t0 = time.time()
80
+ eng = Engine()
81
+ eng.start()
82
+ db_servers = isalive.search(eng,'metadatadb.basic')
83
+ if len(db_servers) == 0:
84
+ print("No metadb server found")
85
+ return
86
+ dev = QueryDB(eng,db_servers)
87
+ dev.query(addr)
88
+ print("Time : %0.3f sec" % (time.time() -t0))
89
+ else:
90
+ print("Invalid addr")
91
+
92
+ else:
93
+ usage()
94
+
95
+
96
+ if __name__ == '__main__':
97
+ main()
@@ -0,0 +1,98 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ #
4
+ # Copyright 2014 Jérôme Colin, Jérôme Kerdreux, Telecom Bretagne.
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ from xaal.lib import Engine,MessageType
21
+ from xaal.lib import tools
22
+
23
+ from .ansi2 import term
24
+ import sys
25
+ import shutil
26
+
27
+ level = 0
28
+
29
+ HIDE_ACTION=['get_attributes','get_description','get_keys_values','is_alive']
30
+
31
+
32
+ def type_to_string(mtype):
33
+ tmp = str(MessageType(mtype))
34
+ return tmp.split('.')[-1]
35
+
36
+
37
+ def display(msg):
38
+ term('yellow')
39
+
40
+ if (msg.action in HIDE_ACTION and level==2):
41
+ return
42
+
43
+ if msg.is_reply():
44
+ if level > 2: return
45
+ term('red')
46
+
47
+ if msg.is_request():
48
+ if level > 3: return
49
+ term('green')
50
+
51
+ if msg.is_notify():
52
+ if msg.is_alive():
53
+ if level > 0: return
54
+ term('grey')
55
+ if msg.is_attributes_change():
56
+ term('cyan')
57
+
58
+ targets = [tools.reduce_addr(addr) for addr in msg.targets]
59
+ tmp = shutil.get_terminal_size()[0] - (8 + 20 + 36 + 20 + 16 + 9)
60
+ if tmp < 50:
61
+ tmp = 50
62
+ BODY_FORMAT = '%-50.'+str(tmp)+'s'
63
+ FORMAT = '%-8.08s=> %-18.18s %-36.36s (%-20.20s) %-16.16s '+BODY_FORMAT
64
+ res = FORMAT % (type_to_string(msg.msg_type),msg.action,msg.source,msg.dev_type,targets,msg.body)
65
+ print(res)
66
+
67
+ def usage():
68
+ print("%s : monitor xAAL network w/ tail format" % sys.argv[0])
69
+ print(" usage : %s log-level" % sys.argv[0])
70
+ print(" level=0 => display all messages")
71
+ print(" level=1 => hide alive messages")
72
+ print(" level=2 => hide xAAL actions messages")
73
+ print(" level=3 => hide reply messages")
74
+ print(" level=4 => only notifications (attributesChange)")
75
+
76
+
77
+ def main():
78
+ global level
79
+ if len(sys.argv) == 2:
80
+ level = int(sys.argv[1])
81
+
82
+ eng = Engine()
83
+ eng.disable_msg_filter()
84
+ eng.subscribe(display)
85
+
86
+ eng.start()
87
+ term('@@')
88
+ FORMAT = '%-8.08s=> %-18.18s %-36.36s (%-20.20s) %-16.16s %-50.50s'
89
+ print(FORMAT % ('type','action','source','dev_type','targets','body'))
90
+ try:
91
+ eng.run()
92
+ except KeyboardInterrupt:
93
+ pass
94
+ else:
95
+ usage()
96
+
97
+ if __name__ == '__main__':
98
+ main()
@@ -0,0 +1,25 @@
1
+ from xaal.lib import tools
2
+ import sys
3
+
4
+
5
+ def main():
6
+ uuid = None
7
+ if len(sys.argv) > 1:
8
+ value = sys.argv[1]
9
+ uuid = tools.get_uuid(value)
10
+ if uuid == None:
11
+ uuid=tools.get_random_uuid()
12
+ print("TXT: %s" % uuid)
13
+
14
+ print("HEX: ",end="")
15
+ for b in uuid.bytes:
16
+ print("0x%x" % b,end=',')
17
+ print()
18
+
19
+ print("INT: ",end="")
20
+ for b in uuid.bytes:
21
+ print("%d" % b,end=',')
22
+ print()
23
+
24
+ if __name__ == '__main__':
25
+ main()
@@ -0,0 +1,35 @@
1
+ """
2
+ Little helper script to walk in device list
3
+ It first send an isAlive message and then
4
+ gather information on each device
5
+ """
6
+
7
+ import sys
8
+ import time
9
+
10
+ import xaal.lib
11
+
12
+
13
+ from . import info
14
+ from . import isalive
15
+
16
+
17
+ def main():
18
+ """ search for alive devices and gather informations about this device"""
19
+
20
+ eng = xaal.lib.Engine()
21
+ eng.disable_msg_filter()
22
+ eng.start()
23
+ devtype = 'any.any'
24
+ if len(sys.argv) == 2:
25
+ devtype = sys.argv[1]
26
+ devs = isalive.search(eng,devtype)
27
+ print()
28
+ dumper = info.InfoDumper(eng)
29
+ t0 = time.time()
30
+ for k in devs:
31
+ dumper.query(k)
32
+ print("Time : %0.3f sec (%d devices)" % (time.time() -t0,len(devs)))
33
+
34
+ if __name__=='__main__':
35
+ main()
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.1
2
+ Name: xaal.legacytools
3
+ Version: 0.1
4
+ Summary: xAAL devices tools
5
+ Author-email: Jerome Kerdreux <Jerome.Kerdreux@imt-atlantique.fr>
6
+ License: GPL License
7
+ Keywords: xaal,tools
8
+ Classifier: Programming Language :: Python
9
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
10
+ Description-Content-Type: text/x-rst
11
+ Requires-Dist: xaal.lib
@@ -0,0 +1,21 @@
1
+ README.rst
2
+ pyproject.toml
3
+ xaal.legacytools.egg-info/PKG-INFO
4
+ xaal.legacytools.egg-info/SOURCES.txt
5
+ xaal.legacytools.egg-info/dependency_links.txt
6
+ xaal.legacytools.egg-info/entry_points.txt
7
+ xaal.legacytools.egg-info/requires.txt
8
+ xaal.legacytools.egg-info/top_level.txt
9
+ xaal/legacytools/__init__.py
10
+ xaal/legacytools/ansi2.py
11
+ xaal/legacytools/dumper.py
12
+ xaal/legacytools/info.py
13
+ xaal/legacytools/inspector.py
14
+ xaal/legacytools/isalive.py
15
+ xaal/legacytools/keygen.py
16
+ xaal/legacytools/log.py
17
+ xaal/legacytools/pkgrun.py
18
+ xaal/legacytools/querydb.py
19
+ xaal/legacytools/tail.py
20
+ xaal/legacytools/uuidgen.py
21
+ xaal/legacytools/walker.py
@@ -0,0 +1,12 @@
1
+ [console_scripts]
2
+ xaal-dumper-legacy = xaal.legacytools.dumper:main
3
+ xaal-info-legacy = xaal.legacytools.info:main
4
+ xaal-inspector-legacy = xaal.legacytools.inspector:main
5
+ xaal-isalive-legacy = xaal.legacytools.isalive:main
6
+ xaal-keygen-legacy = xaal.legacytools.keygen:main
7
+ xaal-log-legacy = xaal.legacytools.log:main
8
+ xaal-pkgrun-legacy = xaal.legacytools.pkgrun:main
9
+ xaal-querydb-legacy = xaal.legacytools.querydb:main
10
+ xaal-tail-legacy = xaal.legacytools.tail:main
11
+ xaal-uuidgen-legacy = xaal.legacytools.uuidgen:main
12
+ xaal-walker-legacy = xaal.legacytools.walker:main