# 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
    def start(self):
        self.status.log("monitoring USB")
        self.observer.start()

    def stop(self):
        self.observer.send_stop()

    def join(self):
        self.observer.join()

    @staticmethod
    def get_mountpoint_for_device(dev):
        with open("/proc/mounts") as f:
            for line in f:
                fields = line.split()
                try:
                    if fields[0] == dev:
                        return fields[1]
                except BaseException:
                    pass
            return None

class FileMonitor (UpdateMonitor):

    class EventHandler (pyinotify.ProcessEvent):
        def __init__(self, status):
            pyinotify.ProcessEvent.__init__(self)
            self.status = status

        def process_IN_CLOSE_WRITE(self, event):

# 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

    def start(self):
        self.status.log("monitoring USB")
        self.observer.start()

    def stop(self):
        self.observer.send_stop()

    def join(self):
        self.observer.join()

    @staticmethod
    def get_mountpoint_for_device(dev):
        with open("/proc/mounts") as f:
            for line in f:
                fields = line.split()
                try:
                    if fields[0] == dev:
                        return fields[1]
                except BaseException:
                    pass
            return None

class FileMonitor (UpdateMonitor):

    class EventHandler (pyinotify.ProcessEvent):
        def __init__(self, status):
            pyinotify.ProcessEvent.__init__(self)
            self.status = status

        def process_IN_CLOSE_WRITE(self, event):

            handle_update_file(event.pathname, self.status, remove=True)