Exemple #1
0
 def __init__(self, logfile, parent=None):
     QtGui.QWidget.__init__(self, parent)
     self.setWindowTitle('Praetor')
     self.tcr = QtGui.QLabel()
     self.slide = QtGui.QLabel()
     btn = QtGui.QPushButton()
     btn.setText('Reload log')
     btn.clicked.connect(self._load_log)
     hbox = QtGui.QHBoxLayout()
     hbox.addWidget(btn)
     hbox.addWidget(self.tcr)
     hbox.addStretch()
     vbox = QtGui.QVBoxLayout()
     vbox.addLayout(hbox)
     vbox.addWidget(self.slide)
     vbox.addStretch()
     w = QtGui.QWidget(self)
     w.setLayout(vbox)
     self.setCentralWidget(w)
     self.logfile = logfile
     self._load_log()
     self.load_image.connect(self._load_image)
     self.resize(680, 540)
     MplayerThread(self).start()
     wm = pyinotify.WatchManager()
     s = pyinotify.Stats()
     self.notifier = pyinotify.ThreadedNotifier(wm,
                                                default_proc_fun=ReloadLog(
                                                    self, s))
     self.notifier.start()
     wm.add_watch(path.dirname(logfile), pyinotify.ALL_EVENTS)
 def _setup_file_inotify(self):
     """ setup inotify for the actual file
     """
     watch_manager = pyinotify.WatchManager()
     stats = pyinotify.Stats()
     self._notifier_file = pyinotify.ThreadedNotifier(
         watch_manager, default_proc_fun=EventHandlerFile(stats, self.read_new_content))
     self._notifier_file.start()
     self._wdd_file = watch_manager.add_watch(self._path, pyinotify.IN_MODIFY)
    def progress(self, infolist, progress, extract_path):
        self.logger.debug("extract thread progress() start")
        next_tick = time.time() + REQUEST_DELAY
        # print pprint.pformat("Clock = %s ,  tick = %s" % (str(time.time()), str(next_tick)))
        progress["count"] = 0

        class Identity(pyinotify.ProcessEvent):
            def process_default(self, event):
                progress["count"] += 1
                # print("Has event %s progress %s" % (repr(event), pprint.pformat(progress)))

        wm1 = pyinotify.WatchManager()
        wm1.add_watch(extract_path,
                      pyinotify.IN_CREATE,
                      rec=True,
                      auto_add=True)

        s1 = pyinotify.Stats()  # Stats is a subclass of ProcessEvent
        notifier1 = pyinotify.ThreadedNotifier(wm1,
                                               default_proc_fun=Identity(s1))
        notifier1.start()

        total = float(len(infolist))

        while not progress["done"]:
            if time.time() > next_tick:
                # print("Tick progress %s / %s" % (pprint.pformat(progress), str(total)))
                count = float(progress["count"]) * 1.5

                if count <= total:
                    op_progress = {
                        'percent': round(count / total, 2),
                        'text': str(int(round(count / total, 2) * 100)) + '%'
                    }
                else:
                    op_progress = {'percent': round(99, 2), 'text': '99%'}

                self.on_running(self.status_id,
                                progress=op_progress,
                                pid=self.pid,
                                pname=self.name)
                next_tick = time.time() + REQUEST_DELAY
                time.sleep(REQUEST_DELAY)

        # иначе пользователям кажется что распаковалось не полностью
        op_progress = {'percent': round(99, 2), 'text': '99%'}
        self.on_running(self.status_id,
                        progress=op_progress,
                        pid=self.pid,
                        pname=self.name)
        time.sleep(REQUEST_DELAY)

        notifier1.stop()
 def _setup_dir_inotify(self):
     """ setup inotify for the directory
     """
     path = re.sub(r"/[^/]+$", "", self._path)
     watch_manager = pyinotify.WatchManager()
     stats = pyinotify.Stats()
     self._notifier_dir = pyinotify.ThreadedNotifier(
         watch_manager,
         default_proc_fun=EventHandlerDirectory(stats, self.open, self.close, self.read_new_content,
                                                self._setup_file_inotify, self._path))
     self._notifier_dir.start()
     self._wdd_file = watch_manager.add_watch(path, pyinotify.IN_CREATE | pyinotify.IN_DELETE)
Exemple #5
0
def main():
    print "PID main :", os.getpid()
    print 'Loaded config file'
    signal.signal(signal.SIGINT, signal_handler)

    s = pyinotify.Stats()
    notifier.start()
    wm.add_watch(config.get('FOLDER', 'watch'),
                 pyinotify.IN_CLOSE_WRITE,
                 rec=True,
                 auto_add=True)
    print 'watching %s' % config.get('FOLDER', 'watch')
    while (True):
        time.sleep(1)
Exemple #6
0
    def __init__(self):
        self.stats = pyinotify.Stats()
        log.info("Initialize notifier...")
        self.queue = collections.deque()
        self.wm = pyinotify.WatchManager()
        self.notifier = pyinotify.ThreadedNotifier(self.wm,
                                                   default_proc_fun=self)
        self.managed_files = _get_managed_files()
        log.warning("adding %d watches", len(self.managed_files))

        for mf in self.managed_files:
            log.warning("Add watch for %s" % mf.path())
            self.wm.add_watch(mf.path(),
                              pyinotify.IN_MODIFY | pyinotify.IN_DELETE_SELF,
                              auto_add=True)
        self.notifier.start()
Exemple #7
0
    def __init__(self,
                 write_video: str = None,
                 limit_time: int = None,
                 input_video_path: str = None):

        # Init ini
        self.ini = utils.get_ini_parameters(INI_FNAME)

        # Init logger
        self.logger = setup_logger_with_ini(self.ini['LOGGER'],
                                            logging_=True,
                                            console_=True)

        # Image size
        self.img_height = None
        self.img_width = None
        self.img_height = int(self.ini['OUT_VIDEO']['height'])
        self.img_width = int(self.ini['OUT_VIDEO']['width'])

        # Init video captuer updater
        status = pyinotify.Stats()
        self.video_capture_updater = VideoCaptureUpdater(
            status, input_video_path=input_video_path)

        # change process name
        setproctitle("python StreamAdaptor.py in StreamAdaptor")

        # last send socket time
        self.last_send_socket_time = time.time()

        # Write Video
        self.write_video = write_video
        self.video_writer = None
        self.limit_time = limit_time
        self.start_time = time.time()
        if self.write_video is not None:
            self.logger.info('WRITE VIDEO MODE : ON')
            CODEC = cv2.VideoWriter_fourcc(*'XVID')
            self.video_writer = cv2.VideoWriter(
                self.write_video,
                fourcc=CODEC,
                fps=float(self.video_capture_updater.frame_fps),
                frameSize=(self.img_width, self.img_height))
Exemple #8
0
    def __init__(self, logger, callback=None):
        super().__init__(pyinotify.Stats())

        self.logger = logger

        self.callback = callback

        wm = pyinotify.WatchManager()
        self.notifier = pyinotify.ThreadedNotifier(wm, default_proc_fun=self)
        self.notifier.daemon = True
        self.notifier.start()

        self.wm = wm

        self.modified_time = {}

        self.watched_files = {}
        self.watched_parents = {}

        self.watched_directories = {}
# Example: prints statistics.
#
import pyinotify


class Identity(pyinotify.ProcessEvent):
    def process_default(self, event):
        # Does nothing, just to demonstrate how stuffs could trivially
        # be accomplished after having processed statistics.
        print 'Does nothing.'


def on_loop(notifier):
    # notifier.proc_fun() is Identity's instance
    s_inst = notifier.proc_fun().nested_pevent()
    print repr(s_inst), '\n', s_inst, '\n'


wm = pyinotify.WatchManager()
# Stats is a subclass of ProcessEvent provided by pyinotify
# for computing basics statistics.
s = pyinotify.Stats()
notifier = pyinotify.Notifier(wm, default_proc_fun=Identity(s), read_freq=5)
wm.add_watch('/tmp/', pyinotify.ALL_EVENTS, rec=True, auto_add=True)
notifier.loop(callback=on_loop)
Exemple #10
0
# Do the same thing than stats.py but with a ThreadedNotifier's
# instance.
# This example illustrates the use of this class but the recommanded
# implementation is whom of stats.py


class Identity(pyinotify.ProcessEvent):
    def process_default(self, event):
        # Does nothing, just to demonstrate how stuffs could be done
        # after having processed statistics.
        print 'Does nothing.'


# Thread #1
wm1 = pyinotify.WatchManager()
s1 = pyinotify.Stats()  # Stats is a subclass of ProcessEvent
notifier1 = pyinotify.ThreadedNotifier(wm1, default_proc_fun=Identity(s1))
notifier1.start()
wm1.add_watch('/tmp/', pyinotify.ALL_EVENTS, rec=True, auto_add=True)

# Thread #2
wm2 = pyinotify.WatchManager()
s2 = pyinotify.Stats()  # Stats is a subclass of ProcessEvent
notifier2 = pyinotify.ThreadedNotifier(wm2, default_proc_fun=Identity(s2))
notifier2.start()
wm2.add_watch('/var/log/', pyinotify.ALL_EVENTS, rec=False, auto_add=False)

while True:
    try:
        print "Thread 1", repr(s1)
        print s1