-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflashman.py
49 lines (39 loc) · 1.52 KB
/
flashman.py
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
"""Flash Drive Manager
Update software from Flash
Set up destination for snapshots
Detect mount/unmount
version 0.2.1
"""
import pyudev
import psutil
import tempfile
class FlashMan():
def __init__(self,master):
self.master=master
self.context = pyudev.Context()
self.monitor = pyudev.Monitor.from_netlink(self.context)
self.monitor.filter_by('block')
self.observer = pyudev.MonitorObserver(self.monitor,self.log_event)
self.observer.start()
pass
def log_event(self,action,device):
#messagebox.showerror('error','mounted')
self.master.event_generate("<<myevent>>",when="tail",data="my data")
def usblist(self):
"""Detect and report on available USB drives"""
ulist = []
removable = [device for device in self.context.list_devices(subsystem='block', DEVTYPE='disk') if device.attributes.asstring('removable') == "1"]
for device in removable:
partitions = [device.device_node for device in self.context.list_devices(subsystem='block', DEVTYPE='partition', parent=device)]
for p in psutil.disk_partitions():
if p.device in partitions:
ulist.append(p.mountpoint)
return ulist
def isWritable(self,path):
"""Test to see if the usb drive can be written"""
try:
testfile = tempfile.TemporaryFile(dir = path)
testfile.close()
except OSError as e:
return False
return True