forked from darkguy2008/hotplugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.py
More file actions
executable file
·67 lines (49 loc) · 1.54 KB
/
monitor.py
File metadata and controls
executable file
·67 lines (49 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python3
import os
import signal
import subprocess
print("")
print("Using both an USB 3.0 and an USB 2.0 device (could be a thumb drive,")
print("an audio device or any other simple USB device), plug and unplug the")
print("device in the ports that you are interested for VM passthrough.")
print("")
print("Press Control + C when finished. The app will then print the device")
print("path of the USB ports. Also make sure that 'udevadm' is installed.")
print("")
input("Press ENTER to continue or abort with CTRL+C...")
print("")
print("Monitoring USB ports...")
###########################
# This gets the UDEV events
###########################
listout = []
def handle(sig, _):
if sig == signal.SIGINT:
print("")
signal.signal(signal.SIGINT, handle)
proc = subprocess.Popen(
["udevadm", "monitor", "-k", "-u", "-p", "-s", "usb"], stdout=subprocess.PIPE)
while True:
line = proc.stdout.readline()
if not line:
break
if line.startswith(b'DEVPATH'):
listout.append(line)
proc.wait()
# print(listout)
######################################
# This gets an unique list of DEVPATHs
######################################
# function to get unique values
def unique(list1):
# intilize a null list
unique_list = []
# traverse for all elements
for x in list1:
# check if exists in unique_list or not
if x not in unique_list:
unique_list.append(x)
return unique_list
uniq = unique(listout)
stringlist = [x.decode('utf-8') for x in uniq]
print(*stringlist, sep='')