예제 #1
0
파일: restat.py 프로젝트: smok-serwis/smok1
def clearstats(request):
    if request.session['Account.privileges'] == 1:
        dev = Device.objects.get(id=request.session['Device.id'])
        af = AFDevice(dev.dev_number)
        af.setStat('transmission.successes', 0)
        af.setStat('transmission.errors', 0)
    return redirect('/device/overview/')
예제 #2
0
def fastRead(id):
    SENSORICS_QUERY_LOCK.acquire()
    try:
        sidsensors = SENSORICS[id]
        Device(id).setStat('runlevel1.lastreported', datetime.now())
        Device(id).setStat('runlevel', 1)
        for sensor in sidsensors:
            sensor.rt1expire = datetime.now() + timedelta(0, 15)
            sensor.advanceToRunlevel(1)
    except Exception, e:
        debugLog(str(e))
예제 #3
0
def runner():  # coś co odpytuje jak trza
    while True:
        min_time = 120
        for k, v in SENSORICS.iteritems():
            try:
                x = Device(k).getStat('online')
                if x == 0:
                    raise Exception
            except:
                continue

            for sensor in v:
                if sensor.needUpdating():
                    sensor.execute()
                if sensor.weight() < min_time:
                    min_time = sensor.weight()
        if min_time == 0:
            continue
        sleep(min_time)
        try:
            open(DATABASE_ROOT + 'FORCE.REREAD.ARCH', 'r')
        except:
            pass
        else:
            os.unlink(DATABASE_ROOT + 'FORCE.REREAD.ARCH')
            completeConfigReread()
예제 #4
0
    def handle(self):
        '''If an exception happens in handle(), then finish() is not executed'''
        self.request.setsockopt(SOL_TCP, TCP_NODELAY, 1)  # Nagle - sio!
        self.request.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 0)  # no keepalive
        self.request.setblocking(1)
        self.request.settimeout(60)
        self.packet = RequestHandlerPacket(proxy(self))
        self.packet.readInStrict(12)  # wczytaj pakiet inicjalizacji
        id, self.protocolVersion = getI_INITIALIZATION(self.packet)

        debugLog('Remote identified as ' + str(id))

        self.id = id
        self.incoming = Queue.Queue()
        self.orders = Queue.Queue()

        try:
            self.device = Device(id)
        except DeviceNotFound:
            debugLog('Unrecognized device ' + str(id))
            return

        try:
            if self.device.getStat('thread.handler') == 1:
                raise Exception
            if self.device.getStat('thread.reader') == 1:
                raise Exception
        except StatisticNotFound:
            pass

        CONNECTIONS[self.id] = self

        try:
            self.xhandle()
        except Exception, e:
            debugLog('Exception for ' + str(self.id) + ': ' + str(e))
예제 #5
0
파일: Server.py 프로젝트: smok-serwis/smok1
    def handle(self):
        '''If an exception happens in handle(), then finish() is not executed'''
        self.request.setsockopt(SOL_TCP, TCP_NODELAY, 1) # Nagle - sio!
        self.request.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 0) # no keepalive
        self.request.setblocking(1)
        self.request.settimeout(60)
        self.packet = RequestHandlerPacket(proxy(self))
        self.packet.readInStrict(12) # wczytaj pakiet inicjalizacji
        id, self.protocolVersion = getI_INITIALIZATION(self.packet)

        debugLog('Remote identified as '+str(id))

        self.id = id
        self.incoming = Queue.Queue()
        self.orders = Queue.Queue()

        try:
            self.device = Device(id)
        except DeviceNotFound:
            debugLog('Unrecognized device '+str(id))
            return

        try:
            if self.device.getStat('thread.handler') == 1:
                raise Exception
            if self.device.getStat('thread.reader') == 1:
                raise Exception
        except StatisticNotFound:
            pass

        CONNECTIONS[self.id] = self

        try:
            self.xhandle()
        except Exception, e:
            debugLog('Exception for '+str(self.id)+': '+str(e))
예제 #6
0
class P24Handler(SocketServer.BaseRequestHandler
                 ):  # Obiekty przetwarzający, yay!
    def finish(self):
        self.device.setStat('thread.handler', 0)
        self.device.setStat('online', 0)
        self.device.setStat('disconnected.on', datetime.now())
        try:
            Get(afsObj.offline(self.id))
        except:
            pass
        debugLog('Finishing for ' + str(self.id))
        try:
            del CONNECTIONS[self.id]
        except:
            pass

    def stall_incoming(self):
        self.device.setStat('thread.handler.status', 'stall')
        self.device.setStat('queue.pending', self.orders.qsize())

        if self.device.getStat('thread.reader.lasttick') + timedelta(
                0, 60) < datetime.now():
            debugLog('Handler quits due to thread.reader watchdog faulting')
            self.device.setStat('thread.reader.lasttick.watchdogged',
                                datetime.now())
            raise Exception, ' watchdog'

        while self.incoming.qsize() > 100:
            self.device.setStat('thread.handler.status', 'stall-busywait')
            if self.device.getStat('thread.reader.lasttick') + timedelta(
                    0, 60) < datetime.now():
                debugLog(
                    'Handler quits due to thread.reader watchdog faulting')
                self.device.setStat('thread.reader.lasttick.watchdogged',
                                    datetime.now())
                raise Exception, 'qsize > 100 + watchdog'
            sleep(1)

    def handle(self):
        '''If an exception happens in handle(), then finish() is not executed'''
        self.request.setsockopt(SOL_TCP, TCP_NODELAY, 1)  # Nagle - sio!
        self.request.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 0)  # no keepalive
        self.request.setblocking(1)
        self.request.settimeout(60)
        self.packet = RequestHandlerPacket(proxy(self))
        self.packet.readInStrict(12)  # wczytaj pakiet inicjalizacji
        id, self.protocolVersion = getI_INITIALIZATION(self.packet)

        debugLog('Remote identified as ' + str(id))

        self.id = id
        self.incoming = Queue.Queue()
        self.orders = Queue.Queue()

        try:
            self.device = Device(id)
        except DeviceNotFound:
            debugLog('Unrecognized device ' + str(id))
            return

        try:
            if self.device.getStat('thread.handler') == 1:
                raise Exception
            if self.device.getStat('thread.reader') == 1:
                raise Exception
        except StatisticNotFound:
            pass

        CONNECTIONS[self.id] = self

        try:
            self.xhandle()
        except Exception, e:
            debugLog('Exception for ' + str(self.id) + ': ' + str(e))
예제 #7
0
파일: Server.py 프로젝트: smok-serwis/smok1
class P24Handler(SocketServer.BaseRequestHandler):    # Obiekty przetwarzający, yay!
    def finish(self):
        self.device.setStat('thread.handler', 0)
        self.device.setStat('online', 0)
        self.device.setStat('disconnected.on', datetime.now())
        try:
            Get(afsObj.offline(self.id))
        except:
            pass
        debugLog('Finishing for '+str(self.id))
        try:
            del CONNECTIONS[self.id]
        except:
            pass

    def stall_incoming(self):
        self.device.setStat('thread.handler.status', 'stall')
        self.device.setStat('queue.pending', self.orders.qsize())

        if self.device.getStat('thread.reader.lasttick') + timedelta(0, 60) < datetime.now():
            debugLog('Handler quits due to thread.reader watchdog faulting')
            self.device.setStat('thread.reader.lasttick.watchdogged', datetime.now())
            raise Exception, ' watchdog'

        while self.incoming.qsize() > 100:
            self.device.setStat('thread.handler.status', 'stall-busywait')
            if self.device.getStat('thread.reader.lasttick') + timedelta(0, 60) < datetime.now():
                debugLog('Handler quits due to thread.reader watchdog faulting')
                self.device.setStat('thread.reader.lasttick.watchdogged', datetime.now())
                raise Exception, 'qsize > 100 + watchdog'
            sleep(1)

    def handle(self):
        '''If an exception happens in handle(), then finish() is not executed'''
        self.request.setsockopt(SOL_TCP, TCP_NODELAY, 1) # Nagle - sio!
        self.request.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 0) # no keepalive
        self.request.setblocking(1)
        self.request.settimeout(60)
        self.packet = RequestHandlerPacket(proxy(self))
        self.packet.readInStrict(12) # wczytaj pakiet inicjalizacji
        id, self.protocolVersion = getI_INITIALIZATION(self.packet)

        debugLog('Remote identified as '+str(id))

        self.id = id
        self.incoming = Queue.Queue()
        self.orders = Queue.Queue()

        try:
            self.device = Device(id)
        except DeviceNotFound:
            debugLog('Unrecognized device '+str(id))
            return

        try:
            if self.device.getStat('thread.handler') == 1:
                raise Exception
            if self.device.getStat('thread.reader') == 1:
                raise Exception
        except StatisticNotFound:
            pass

        CONNECTIONS[self.id] = self

        try:
            self.xhandle()
        except Exception, e:
            debugLog('Exception for '+str(self.id)+': '+str(e))
예제 #8
0
파일: restat.py 프로젝트: smok-serwis/smok1
def errtoggle(request):
    if request.session['Account.privileges'] == 1:
        dev = Device.objects.get(id=request.session['Device.id'])
        af = AFDevice(dev.dev_number)
        af.setRegistry('correct.errors', not af.getRegistry('correct.errors'))
    return redirect('/device/overview/')
예제 #9
0
#! /usr/bin/python
# coding=UTF-8
'''Uruchamiane gdy serwer się wyłącza'''
from patelnia.p24 import enumDevices
from afruntime.device import Device
import os
from sys import exit

for x in enumDevices():
    Device(x.devid).setStat('thread.reader', 0)
    Device(x.devid).setStat('thread.handler', 0)
    Device(x.devid).setStat('online', 0)
exit(0)