|
@@ -23,7 +23,6 @@ class USBDetector():
|
|
|
''' Monitor udev for detection of usb '''
|
|
|
|
|
|
def __init__(self, handler, source_dir, dest_dir, ftp_args):
|
|
|
- ''' Initiate the object '''
|
|
|
self.usb_plugged_in = handler
|
|
|
self.source_dir = source_dir
|
|
|
self.dest_dir = dest_dir
|
|
@@ -34,17 +33,14 @@ class USBDetector():
|
|
|
thread.join()
|
|
|
|
|
|
def _work(self):
|
|
|
- ''' Runs the actual loop to detect the events '''
|
|
|
self.context = pyudev.Context()
|
|
|
self.monitor = pyudev.Monitor.from_netlink(self.context)
|
|
|
self.monitor.filter_by(subsystem='block')
|
|
|
- # this is module level logger, can be ignored
|
|
|
logger.info("Starting to monitor for usb")
|
|
|
self.monitor.start()
|
|
|
for device in iter(self.monitor.poll, None):
|
|
|
logger.debug("Got USB event: %s", device.action)
|
|
|
if device.action == 'add' and device.device_type == 'partition':
|
|
|
- # some function to run on insertion of usb
|
|
|
self.usb_plugged_in(device, self.source_dir, self.dest_dir, self.ftp_args)
|
|
|
|
|
|
|
|
@@ -128,16 +124,10 @@ def main(args):
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- """ This is executed when run from the command line """
|
|
|
parser = argparse.ArgumentParser()
|
|
|
-
|
|
|
- # Optional argument flag which defaults to False
|
|
|
- parser.add_argument("-f", "--flag", action="store_true", default=False)
|
|
|
-
|
|
|
# Directory options
|
|
|
parser.add_argument("-s", "--source", help="source directory with dashcam videos", action="store", dest="source", default="DCIM/Movie")
|
|
|
parser.add_argument("-d", "--destination", help="destination directory for joined dashcam videos", action="store", dest="destination", default="/var/dashcam")
|
|
|
-
|
|
|
# FTP options
|
|
|
parser.add_argument("--ftp-host", help="ftp host (server)", action="store", default="192.168.88.242")
|
|
|
parser.add_argument("--ftp-path", help="ftp path", action="store", default="/dashcam")
|