You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
3 years ago
|
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()
|