Ejemplo n.º 1
0
    def check_locks(self, path, lock_suffix):
        """
        Check if there are active locks ending with ``lock_suffix`` in ``path``.
        If the process owning the lock doesn't exist anymore this will remove
        the lock.

        Args:
            path (str):         full path to lock directory
            lock_suffix (str):  last part of locks name

        Returns:
            bool:               ``True`` if there are active locks in ``path``
        """
        for f in os.listdir(path):
            if not f[-len(lock_suffix):] == lock_suffix:
                continue
            is_tmp = os.path.basename(f)[-len(lock_suffix)-len('.tmp'):-len(lock_suffix)] == '.tmp'
            if is_tmp:
                lock_pid = os.path.basename(f)[:-len('.tmp')-len(lock_suffix)]
            else:
                lock_pid = os.path.basename(f)[:-len(lock_suffix)]
            if lock_pid == self.pid:
                if is_tmp == self.tmp_mount:
                    continue
            if tools.is_process_alive(int(lock_pid)):
                return True
            else:
                logger.debug('Remove old and invalid lock %s'
                             %f, self)
                #clean up
                os.remove(os.path.join(path, f))
                for symlink in os.listdir(self.mount_root):
                    if symlink.endswith('_%s' % lock_pid):
                        os.remove(os.path.join(self.mount_root, symlink))
        return False
Ejemplo n.º 2
0
    def update_info( self ):
        if not tools.is_process_alive( self.ppid ):
            self.prepare_exit()
            self.qapp.exit(0)
            return

        message = self.snapshots.get_take_snapshot_message()
        if message is None and self.last_message is None:
            message = ( 0, _('Working...') )

        if not message is None:
            if message != self.last_message:
                self.last_message = message
                self.menuStatusMessage.setText('\n'.join(tools.wrap_line(self.last_message[1],\
                                                                         size = 80,\
                                                                         delimiters = '',\
                                                                         new_line_indicator = '') \
                                                                        ))
                self.status_icon.setToolTip( self.last_message[1] )

        pg = progress.ProgressFile(self.config)
        if pg.isFileReadable():
            pg.load()
            percent = pg.get_int_value('percent')
            if percent != self.progressBar.value():
                self.progressBar.setValue(percent)
                self.progressBar.render(self.pixmap, sourceRegion = QRegion(0, -14, 24, 6), flags = QWidget.RenderFlags(QWidget.DrawChildren))
                self.status_icon.setIcon(QIcon(self.pixmap))

            self.menuProgress.setText(' | '.join(self.getMenuProgress(pg)) )
            self.menuProgress.setVisible(True)
        else:
            self.status_icon.setIcon(self.icon.BIT_LOGO)
            self.menuProgress.setVisible(False)
Ejemplo n.º 3
0
 def test_is_process_alive(self):
     """
     Test the function is_process_alive
     """
     #TODO: add test (in chroot) running proc as root and kill as non-root
     self.assertTrue(tools.is_process_alive(os.getpid()))
     pid = self.createProcess()
     self.assertTrue(tools.is_process_alive(pid))
     self.killProcess()
     self.assertFalse(tools.is_process_alive(pid))
     self.assertFalse(tools.is_process_alive(999999))
     with self.assertRaises(ValueError):
         tools.is_process_alive(0)
     self.assertFalse(tools.is_process_alive(-1))
Ejemplo n.º 4
0
    def check(self, auto_exit=False):
        """
        Check if the current application is already running

        Args:
            auto_exit (bool):   automatically call sys.exit if there is an other
                                instance running

        Returns:
            bool:               True if this is the only application instance
        """
        # check if the pidfile exists
        if not os.path.isfile(self.pid_file):
            return True

        self.pid, self.procname = self.readPidFile()

        # check if the process with specified by pid exists
        if 0 == self.pid:
            return True

        if not tools.is_process_alive(self.pid):
            return True

        # check if the process has the same procname
        # check cmdline for backwards compatibility
        if (
            self.procname
            and self.procname != tools.process_name(self.pid)
            and self.procname != tools.process_cmdline(self.pid)
        ):
            return True

        if auto_exit:
            # exit the application
            print("The application is already running !")
            exit(0)  # exit raise an exception so don't put it in a try/except block

        return False
Ejemplo n.º 5
0
    def update_info(self):
        if not tools.is_process_alive(self.ppid):
            self.prepare_exit()
            self.qapp.exit(0)
            return

        message = self.snapshots.get_take_snapshot_message()
        if message is None and self.last_message is None:
            message = (0, _('Working...'))

        if not message is None:
            if message != self.last_message:
                self.last_message = message
                self.menuStatusMessage.setText('\n'.join(tools.wrap_line(self.last_message[1],\
                                                                         size = 80,\
                                                                         delimiters = '',\
                                                                         new_line_indicator = '') \
                                                                        ))
                self.status_icon.setToolTip(self.last_message[1])

        pg = progress.ProgressFile(self.config)
        if pg.isFileReadable():
            pg.load()
            percent = pg.get_int_value('percent')
            if percent != self.progressBar.value():
                self.progressBar.setValue(percent)
                self.progressBar.render(self.pixmap,
                                        sourceRegion=QRegion(0, -14, 24, 6),
                                        flags=QWidget.RenderFlags(
                                            QWidget.DrawChildren))
                self.status_icon.setIcon(QIcon(self.pixmap))

            self.menuProgress.setText(' | '.join(self.getMenuProgress(pg)))
            self.menuProgress.setVisible(True)
        else:
            self.status_icon.setIcon(self.icon.BIT_LOGO)
            self.menuProgress.setVisible(False)
Ejemplo n.º 6
0
 def test_is_process_alive(self):
     """
     Test the function is_process_alive
     """
     self.assertTrue(tools.is_process_alive(0))
     self.assertFalse(tools.is_process_alive(99999999999))
Ejemplo n.º 7
0
 def test_is_process_alive(self):
     """
     Test the function is_process_alive
     """
     self.assertTrue(tools.is_process_alive(0))
     self.assertFalse(tools.is_process_alive(99999999999))