From ffa508a7838c7daf3d648a6c29ee7e98a2fbc2f3 Mon Sep 17 00:00:00 2001 From: dbarzin Date: Sat, 11 Jun 2022 16:26:40 +0200 Subject: [PATCH] firsts tests --- README.md | 6 +++++- tests/detect-usb.py | 34 ++++++++++++++++++++++++++++++++++ tests/mouse-click.py | 27 +++++++++++++++++++++++++++ tests/screen.py | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100755 tests/detect-usb.py create mode 100755 tests/mouse-click.py create mode 100755 tests/screen.py diff --git a/README.md b/README.md index 00e09be..4f78670 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ -# pandora-box \ No newline at end of file +Pandora-BOX +============ + +Pandorabox is a USB scaning station base on Pandora + diff --git a/tests/detect-usb.py b/tests/detect-usb.py new file mode 100755 index 0000000..7fd9b36 --- /dev/null +++ b/tests/detect-usb.py @@ -0,0 +1,34 @@ +#!/usr/bin/python3 + +import pyudev +import psutil +import time + +context = pyudev.Context() +monitor = pyudev.Monitor.from_netlink(context) +monitor.filter_by('block') + +# enumerate at device connection +for device in iter(monitor.poll, None): + if 'ID_FS_TYPE' in device: + if device.action == 'add': + if device.device_node[5:7] == 'sd': + print("New device {}".format(device.device_node)) + # loop until device is mounted + found=False + loop=0 + while (not found) and (loop<10): + # need to sleep before devide is mounted + time.sleep(1) + for partition in psutil.disk_partitions(): + if partition.device == device.device_node: + print("Mounted at {}".format(partition.mountpoint)) + found=True + loop+=1 + + if device.action == 'remove': + if device.device_node[5:7] == 'sd': + print('Device removed') + + + diff --git a/tests/mouse-click.py b/tests/mouse-click.py new file mode 100755 index 0000000..22dcc4e --- /dev/null +++ b/tests/mouse-click.py @@ -0,0 +1,27 @@ +#!/usr/bin/python3 + +import curses + +screen = curses.initscr() +screen.keypad(1) +curses.curs_set(0) +curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION) +curses.flushinp() +curses.noecho() +screen.clear() + +while True: + key = screen.getch() + screen.clear() + screen.addstr(0, 0, 'key: {}'.format(key)) + if key == curses.KEY_MOUSE: + _, x, y, _, button = curses.getmouse() + screen.addstr(1, 0, 'x, y, button = {}, {}, {}'.format(x, y, button)) + elif key == 27: + break + +curses.endwin() +curses.flushinp() + + + diff --git a/tests/screen.py b/tests/screen.py new file mode 100755 index 0000000..f346a26 --- /dev/null +++ b/tests/screen.py @@ -0,0 +1,33 @@ +#!/usr/bin/python + +import curses + +screen = curses.initscr() +screen.keypad(1) +curses.curs_set(0) +curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION) +curses.flushinp() +curses.noecho() +screen.clear() + +screen.addstr(1,0," ██▓███ ▄▄▄ ███▄ █ ▓█████▄ ▒█████ ██▀███ ▄▄▄ ▄▄▄▄ ▒█████ ▒██ ██▒") +screen.addstr(2,0," ▓██░ ██▒▒████▄ ██ ▀█ █ ▒██▀ ██▌▒██▒ ██▒▓██ ▒ ██▒▒████▄ ▓█████▄ ▒██▒ ██▒▒▒ █ █ ▒░") +screen.addstr(3,0," ▓██░ ██▓▒▒██ ▀█▄ ▓██ ▀█ ██▒░██ █▌▒██░ ██▒▓██ ░▄█ ▒▒██ ▀█▄ ▒██▒ ▄██▒██░ ██▒░░ █ ░") +screen.addstr(4,0," ▒██▄█▓▒ ▒░██▄▄▄▄██ ▓██▒ ▐▌██▒░▓█▄ ▌▒██ ██░▒██▀▀█▄ ░██▄▄▄▄██ ▒██░█▀ ▒██ ██░ ░ █ █ ▒ ") +screen.addstr(5,0," ▒██▒ ░ ░ ▓█ ▓██▒▒██░ ▓██░░▒████▓ ░ ████▓▒░░██▓ ▒██▒ ▓█ ▓██▒ ░▓█ ▀█▓░ ████▓▒░▒██▒ ▒██▒") +screen.addstr(6,0," ▒▓▒░ ░ ░ ▒▒ ▓▒█░░ ▒░ ▒ ▒ ▒▒▓ ▒ ░ ▒░▒░▒░ ░ ▒▓ ░▒▓░ ▒▒ ▓▒█░ ░▒▓███▀▒░ ▒░▒░▒░ ▒▒ ░ ░▓ ░") +screen.addstr(7,0," ░▒ ░ ▒ ▒▒ ░░ ░░ ░ ▒░ ░ ▒ ▒ ░ ▒ ▒░ ░▒ ░ ▒░ ▒ ▒▒ ░ ▒░▒ ░ ░ ▒ ▒░ ░░ ░▒ ░") +screen.addstr(8,0," ░░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░ ▒ ░ ░ ░ ░ ░ ▒ ░ ░ ") +screen.addstr(9,0," ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ") +screen.addstr(10,0," ░ ░ ") +screen.addstr(11,0,"READY."); + +while True: + key = screen.getch() + if key == curses.KEY_MOUSE: + break + if key == 27: + break + +curses.endwin() +curses.flushinp()