# Path: elbepack/updated.py
# def is_update_file(upd_file):
#     _, extension = os.path.splitext(upd_file)
#     if extension == ".gpg":
#         return True
# 
#     try:
#         upd_file_z = ZipFile(upd_file)
#     except BadZipfile:
#         return False
# 
#     if "new.xml" not in upd_file_z.namelist():
#         return False
# 
#     return True
# 
# def handle_update_file(upd_file, status, remove=False):
#     with update_lock:
#         status.log("checking file: " + str(upd_file))
#         _, extension = os.path.splitext(upd_file)
# 
#         if extension == ".gpg":
#             fname = unsign_file(upd_file)
#             if remove:
#                 os.remove(upd_file)
#             if fname:
#                 action_select(fname, status)
#                 if remove:
#                     os.remove(fname)
#             else:
#                 status.log("checking signature failed: " + str(upd_file))
# 
#         elif status.nosign:
#             action_select(upd_file, status)
#             if remove:
#                 os.remove(upd_file)
#         else:
#             status.log("ignore file: " + str(upd_file))


import os
import threading
import pyinotify
import pyudev
from elbepack.updated import is_update_file, handle_update_file
        raise NotImplementedError


class USBMonitor (UpdateMonitor):
    def __init__(self, status, recursive=False):
        super(USBMonitor, self).__init__(status)
        self.recursive = recursive
        self.context = pyudev.Context()
        self.monitor = pyudev.Monitor.from_netlink(self.context)
        self.observer = pyudev.MonitorObserver(
            self.monitor, self.handle_event)

    def handle_event(self, action, device):
        if (action == 'add'
            and device.get('ID_BUS') == 'usb'
                and device.get('DEVTYPE') == 'partition'):

            mnt = self.get_mountpoint_for_device(device.device_node)
            if not mnt:
                self.status.log(
                    "Detected USB drive but it was not mounted.")
                return

            for (dirpath, dirnames, filenames) in os.walk(mnt):
                # Make sure we process the files in alphabetical order
                # to get a deterministic behaviour
                dirnames.sort()
                filenames.sort()
                for f in filenames:
                    upd_file = os.path.join(dirpath, f)

# Path: elbepack/updated.py
# def is_update_file(upd_file):
#     _, extension = os.path.splitext(upd_file)
#     if extension == ".gpg":
#         return True
# 
#     try:
#         upd_file_z = ZipFile(upd_file)
#     except BadZipfile:
#         return False
# 
#     if "new.xml" not in upd_file_z.namelist():
#         return False
# 
#     return True
# 
# def handle_update_file(upd_file, status, remove=False):
#     with update_lock:
#         status.log("checking file: " + str(upd_file))
#         _, extension = os.path.splitext(upd_file)
# 
#         if extension == ".gpg":
#             fname = unsign_file(upd_file)
#             if remove:
#                 os.remove(upd_file)
#             if fname:
#                 action_select(fname, status)
#                 if remove:
#                     os.remove(fname)
#             else:
#                 status.log("checking signature failed: " + str(upd_file))
# 
#         elif status.nosign:
#             action_select(upd_file, status)
#             if remove:
#                 os.remove(upd_file)
#         else:
#             status.log("ignore file: " + str(upd_file))


# Path: elbepack/updated_monitors.py
import os
import threading
import pyinotify
import pyudev
from elbepack.updated import is_update_file, handle_update_file

        raise NotImplementedError


class USBMonitor (UpdateMonitor):
    def __init__(self, status, recursive=False):
        super(USBMonitor, self).__init__(status)
        self.recursive = recursive
        self.context = pyudev.Context()
        self.monitor = pyudev.Monitor.from_netlink(self.context)
        self.observer = pyudev.MonitorObserver(
            self.monitor, self.handle_event)

    def handle_event(self, action, device):
        if (action == 'add'
            and device.get('ID_BUS') == 'usb'
                and device.get('DEVTYPE') == 'partition'):

            mnt = self.get_mountpoint_for_device(device.device_node)
            if not mnt:
                self.status.log(
                    "Detected USB drive but it was not mounted.")
                return

            for (dirpath, dirnames, filenames) in os.walk(mnt):
                # Make sure we process the files in alphabetical order
                # to get a deterministic behaviour
                dirnames.sort()
                filenames.sort()
                for f in filenames:
                    upd_file = os.path.join(dirpath, f)

                    if is_update_file(upd_file):