Exemple #1
0
#!/usr/bin/env python
import os
import sys
import datetime
import time

from raspalarm.conf import getLogger, settings
from raspalarm.temperature import db, reader
from raspalarm.web import serve_forever

logger = getLogger('CMD')


def insert_reading():
    '''
        Should be called periodically and inserts temperature reading
        to our database.
    '''
    logger.debug('Inserting reading...')
    database = db.Database()
    database.insert_reading(reader.read())


def create_graph():
    '''
        Creates a graph from all readings today
    '''
    from raspalarm.temperature import grapher
    fn = grapher.get_filename()
    now = datetime.datetime.now()
    midnight = datetime.datetime.combine(now.date(), datetime.time.min)
import signal
from threading import Thread as Original_Thread

from raspalarm.conf import settings, getLogger

logger = getLogger(__name__)


class Thread(Original_Thread):
    __registry = []

    @classmethod
    def destroy_all(cls, signum):
        for t in cls.__registry:
            if t.is_alive():
                t.stop()
                logger.debug(
                    'Killed "%s" with signum %s',
                    t.__class__.__name__,
                    signum
                )

    def start(self, *args, **kwargs):
        logger.debug('Starting thread %s', self.__class__.__name__)
        Thread.__registry.append(self)
        super(Thread, self).start(*args, **kwargs)


def handler(signum, frame):
    Thread.destroy_all(signum)
    if signum == signal.SIGINT:
Exemple #3
0
#!/usr/bin/env python
import os
import sys
import datetime
import time

from raspalarm.conf import getLogger, settings
from raspalarm.temperature import db, reader
from raspalarm.web import serve_forever

logger = getLogger('CMD')

def insert_reading():
    '''
        Should be called periodically and inserts temperature reading
        to our database.
    '''
    logger.debug('Inserting reading...')
    database = db.Database()
    database.insert_reading(reader.read())

def create_graph():
    '''
        Creates a graph from all readings today
    '''
    from raspalarm.temperature import grapher
    fn = grapher.get_filename()
    now = datetime.datetime.now()
    midnight = datetime.datetime.combine(now.date(), datetime.time.min)
    connection = db.Database()
    data = connection.get_readings((midnight, now))