Exemple #1
0
    def set_device(self, identifier):
        """
        Method for registering the device with the server.
        """

        self.device = identifier
        if identifier is None:
            self.notifier = None
        else:
            self.notifier = AlertNotifier(self.settings, identifier)
Exemple #2
0
    def set_device(self, identifier):
        """
        Method for registering the device with the server.
        """

        self.device = identifier
        if identifier is None:
            self.notifier = None
        else:
            self.notifier = AlertNotifier(self.settings,  identifier)
Exemple #3
0
class MotionProcess(object):
    """
    Encapsulates the motion process handling.
    """
    def __init__(self, settings):
        self.process = None
        self.device = None
        self.control_port = settings['control_port']
        self.settings = settings
        self.snapshot_event = threading.Event()
        self.latest_snapshot = None
        self.notifier = None

    def start(self):
        """
        Encapsulates the start procedure for creating the Motion process.
        """

        if self.device is None:
            abort(409, 'Cannot start motion detection without device')
        elif self.process is None:
            LOG.info('Start motion process')
            default_path = '/usr/local/etc/security-cam/motion.conf'
            if os.path.exists(default_path):
                self.process = subprocess.Popen(['motion', '-c', default_path])
            else:
                self.process = subprocess.Popen(
                    ['motion', '-c', 'conf/motion.conf'])
        else:
            LOG.info('Motion process already running')

    def stop(self):
        """
        Encapsulates the start procedure for killing the Motion process.
        """

        if self.process is not None:
            self.process.kill()
            self.process = None

    def status(self):
        """
        Returns the server state based on the device and process state.
        """

        if self.device is None:
            return 'Idle'
        elif self.process is None:
            return 'Ready'
        else:
            return 'Running'

    def set_device(self, identifier):
        """
        Method for registering the device with the server.
        """

        self.device = identifier
        if identifier is None:
            self.notifier = None
        else:
            self.notifier = AlertNotifier(self.settings, identifier)

    def alert(self, filename):
        """
        Sends a push notification to the registered device.
        """

        self.notifier.notify(filename)

    def request_snapshot(self):
        """
        Issues the creation of a new snapshot and returns it after the file has
        been saved.
        """

        url = 'http://localhost:%d/0/action/snapshot' % self.control_port
        requests.get(url)
        self.snapshot_event.wait()
        return self.latest_snapshot

    def notify_about_snapshot(self, filename):
        """
        Used to set the filename and clear the lock so the request snapshot
        routine eventually returns the image.
        """

        self.latest_snapshot = filename
        self.snapshot_event.set()
        self.snapshot_event.clear()
Exemple #4
0
class MotionProcess(object):
    """
    Encapsulates the motion process handling.
    """

    def __init__(self, settings):
        self.process = None
        self.device = None
        self.control_port = settings['control_port']
        self.settings = settings
        self.snapshot_event = threading.Event()
        self.latest_snapshot = None
        self.notifier = None

    def start(self):
        """
        Encapsulates the start procedure for creating the Motion process.
        """

        if self.device is None:
            abort(409, 'Cannot start motion detection without device')
        elif self.process is None:
            LOG.info('Start motion process')
            default_path = '/usr/local/etc/security-cam/motion.conf'
            if os.path.exists(default_path):
                self.process = subprocess.Popen(['motion', '-c', default_path])
            else:
                self.process = subprocess.Popen(['motion', '-c',
                                                 'conf/motion.conf'])
        else:
            LOG.info('Motion process already running')

    def stop(self):
        """
        Encapsulates the start procedure for killing the Motion process.
        """

        if self.process is not None:
            self.process.kill()
            self.process = None

    def status(self):
        """
        Returns the server state based on the device and process state.
        """

        if self.device is None:
            return 'Idle'
        elif self.process is None:
            return 'Ready'
        else:
            return 'Running'

    def set_device(self, identifier):
        """
        Method for registering the device with the server.
        """

        self.device = identifier
        if identifier is None:
            self.notifier = None
        else:
            self.notifier = AlertNotifier(self.settings,  identifier)

    def alert(self, filename):
        """
        Sends a push notification to the registered device.
        """

        self.notifier.notify(filename)

    def request_snapshot(self):
        """
        Issues the creation of a new snapshot and returns it after the file has
        been saved.
        """

        url = 'http://localhost:%d/0/action/snapshot' % self.control_port
        requests.get(url)
        self.snapshot_event.wait()
        return self.latest_snapshot

    def notify_about_snapshot(self, filename):
        """
        Used to set the filename and clear the lock so the request snapshot
        routine eventually returns the image.
        """

        self.latest_snapshot = filename
        self.snapshot_event.set()
        self.snapshot_event.clear()