automatic mounting of external drives plugged in to USB or card readers.
parent
e30f74bbda
commit
546259ade2
@ -0,0 +1,58 @@
|
||||
import os
|
||||
|
||||
from bureau import Bureau, add_command
|
||||
import pyudev
|
||||
|
||||
|
||||
class Archives(Bureau):
|
||||
"""
|
||||
The Archives is the central library resource for the storage and retreival
|
||||
of persistent data files. Audio, graphic and textual documents may be
|
||||
managed for the use of any other bureau.
|
||||
"""
|
||||
|
||||
name = "Central Archives"
|
||||
prefix = "AR"
|
||||
version = 0
|
||||
|
||||
def __init__(self):
|
||||
Bureau.__init__(self)
|
||||
|
||||
# get location of archive root storage from config
|
||||
|
||||
def _mount_and_archive(dev):
|
||||
# TODO: small print options to import stuff
|
||||
print("MOUNTING EXTERNAL MEDIUM: ", dev)
|
||||
|
||||
# pmount dev
|
||||
os.system("pmount " + str(dev))
|
||||
# path is always /media/device
|
||||
|
||||
#os.walk()
|
||||
|
||||
# walk through the tree looking for mp3 / ogg
|
||||
|
||||
# walk through looking for photos
|
||||
|
||||
# walk through looking for pdfs
|
||||
|
||||
# pumount dev
|
||||
|
||||
def run_io(self):
|
||||
# monitor for insert of any removable block storage devices (SD/USB)
|
||||
context = pyudev.Context()
|
||||
monitor = pyudev.Monitor.from_netlink(context)
|
||||
monitor.filter_by('block')
|
||||
for device in iter(monitor.poll, None):
|
||||
if ('ID_FS_TYPE' in device) and (device.action == "add"):
|
||||
self._mount_and_archive(device.device_node)
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
ar = Archives()
|
||||
ar.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue