Example #1
0
    def threads(self, data, address, lock):
        """
            run thread
        """
        # Parse Devices
        rawData = Devices.devices.getTypeClass(data, address) 
        
        if not rawData.has_key('id'): 
            print >> sys.stdout, rawData
            return 

        ### Eventos
        import Event.captureEvent
        event = Event.captureEvent.parseEvent(rawData) 
                                                       
        ### Escribe el la Tabla de Log
        import Log.logDB as LogDB
        LogDB.insertLog(rawData)
        # End Tabla de Log

        #### Escribe en el Fichero de Log
        lock.acquire(True)
        self.__class__.endfile = logFile(str(load('FILELOG', 'FILE')),
                                         self.__class__.endfile,
                                         raw=rawData 
                                        )
        lock.release()
Example #2
0
    def threads(self, data, address, lock):
        """
            run thread
        """

        print >> sys.stdout, "Data: %s|Hilo: %s" % (data, self.thread.getName())

        rawData = Devices.devices.getTypeClass(data, address) 
        
        if not rawData.has_key('id'): 
            print >> sys.stdout, rawData
            return 


        import Event.captureEvent
        event = Event.captureEvent.parseEvent(rawData) 
                                                      
        print >> sys.stdout, "Evento Gestionado: %s" % (event)

        import Log.logDB as LogDB
        LogDB.insertLog(rawData)

        lock.acquire(True)
        self.__class__.endfile = logFile(str(load('FILELOG', 'FILE')),
                                         self.__class__.endfile,
                                         raw=rawData 
                                        )
        lock.release()
Example #3
0
    def threads(self, data, address, lock):
        """
            run thread
        """
        # Parse Devices
        rawData = Devices.devices.getTypeClass(data, address)

        if not rawData.has_key('id'):
            print >> sys.stdout, rawData
            return

        ### Eventos
        import Event.captureEvent
        event = Event.captureEvent.parseEvent(rawData)

        ### Escribe el la Tabla de Log
        import Log.logDB as LogDB
        LogDB.insertLog(rawData)
        # End Tabla de Log

        #### Escribe en el Fichero de Log
        lock.acquire(True)
        self.__class__.endfile = logFile(str(load('FILELOG', 'FILE')),
                                         self.__class__.endfile,
                                         raw=rawData)
        lock.release()
Example #4
0
def main():
    from twisted.internet import reactor
    log.startLogging(sys.stdout);
    root = resource.Resource()
    root.putChild('RPC2', XMLRPCQuoter())
    root.putChild('SOAP', SOAPQuoter())
    root.putChild('RESET',RESETQuoter())
    reactor.listenTCP(int(load('WebService', 'Port')), server.Site(root))
    reactor.run()
Example #5
0
def connection(args=None): 
    """ 
        args, puede ser una cadena con todos los datos para conectarse a la base de datos o 
        simplemente enviarse sin datos, para lo cual tomara la configuración por defecto 
        almacenada en el fichero de configuración "config.cfg" (en la sección [DATABASE]).
        así:

        
        Usage:
        >>> from DB.pgSQL import connection

        >>> connection("dbname='test010' user='******' host='localhost' password='******'") # Con argumentos
        >>> connection() # Sin argumento
        <connection object at 0xb715a72c; dsn: 'dbname='test009' user='******' host='localhost' password=xxxxxxxx', closed: 0>
        >>> conn = connection()
        >>> cursor = conn.cursor()
        >>> cursor.execute("select * from gps")
        >>> print cursor.fetchall()
        [(11, 'GPS0003', 2, False, datetime.datetime(2012, 7, 13, 8, 11, 31, 945952, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=1140, name=None))), ...]
        >>>

    """
    if args is None:
        from Load.loadconfig import load

        args = {}
        
        args['dbname'] = load('DATABASE', 'DBNAME')
        args['user'] = load('DATABASE', 'USER')
        args['host'] = load('DATABASE', 'HOST')
        args['password'] = load('DATABASE', 'PASSWORD')

        args = " ".join(["%s=\'%s\'" % (k, v) for k, v in args.items()])

    # Conexión a la base de datos: 
    try:
        conn = pgsql.connect(args)
    except pgsql.OperationalError, e:
        print >> sys.stderr, "\nNo se pudo poner en marcha la base de datos.\n"
        print >> sys.stderr, e
        print >> sys.stdout, 'Error: Revisar el archivo de error.log'
        sys.exit(1)
Example #6
0
def connection(args=None): 
    """ 
        args, puede ser una cadena con todos los datos para conectarse a la base de datos o 
        simplemente enviarse sin datos, para lo cual tomara la configuración por defecto 
        almacenada en el fichero de configuración "config.cfg" (en la sección [DATABASE]).
        así:

        
        Usage:
        >>> from DB.pgSQL import connection

        >>> connection("dbname='test010' user='******' host='localhost' password='******'") # Con argumentos
        >>> connection() # Sin argumento
        <connection object at 0xb715a72c; dsn: 'dbname='test009' user='******' host='localhost' password=xxxxxxxx', closed: 0>
        >>> conn = connection()
        >>> cursor = conn.cursor()
        >>> cursor.execute("select * from gps")
        >>> print cursor.fetchall()
        [(11, 'GPS0003', 2, False, datetime.datetime(2012, 7, 13, 8, 11, 31, 945952, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=1140, name=None))), ...]
        >>>

    """
    if args is None:
        from Load.loadconfig import load

        args = {}
        
        args['dbname'] = load('DATABASE', 'DBNAME')
        args['user'] = load('DATABASE', 'USER')
        args['host'] = load('DATABASE', 'HOST')
        args['password'] = load('DATABASE', 'PASSWORD')

        args = " ".join(["%s=\'%s\'" % (k, v) for k, v in args.items()])

    # Conexión a la base de datos: 
    try:
        conn = pgsql.connect(args)
    except pgsql.OperationalError, e:
        print >> sys.stderr, "\nNo se pudo poner en marcha la base de datos.\n"
        print >> sys.stderr, e
        print >> sys.stdout, 'Error: Revisar el archivo de error.log'
        sys.exit(1)
Example #7
0
def connection(args=None): 
    if args is None:
        from Load.loadconfig import load
       
        args = {}
        
        args['dbname'] = load('DATABASE', 'DBNAME')
        args['user'] = load('DATABASE', 'USER')
        args['host'] = load('DATABASE', 'HOST')
        args['password'] = load('DATABASE', 'PASSWORD')

        args = " ".join(["%s=\'%s\'" % (k, v) for k, v in args.items()])
    # Conexión a la base de datos: 
    try:
        conn = pgsql.connect(args)
    except pgsql.OperationalError, e:
        print >> sys.stderr, "\nNo se pudo poner en marcha la base de datos.\n"
        print >> sys.stderr, e
        print >> sys.stdout, 'Error: Revisar el archivo de error.log'
        sys.exit(1)
Example #8
0
    def start(self):
        """
            Prepara el servidor 
        """

        if createLogFile(str(load('FILELOG', 'FILE'))): # Creamos el fichero de Log
            try:
                self.server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Creamos el Socket Server 
                self.server.bind((self.host, self.port))
                print >> sys.stdout, ("Server run %s:%s" % (self.host, self.port))
            except socket.error, (value, message):
                if self.server:
                    self.server.close()
                print >> sys.stderr, "Could not open socket:", message
                sys.exit(1)
Example #9
0
    def threads(self, data, address, lock):
        """
            run thread
        """
        import time, random
            
        # Fichero de Log
        lock.acquire(True)
        self.__class__.endfile = logFile(str(load('FILELOG', 'FILE')),
                                         self.__class__.endfile,
                                         address=address, data=data, 
                                        )
        lock.release()
        # End Fichero de Log

        time.sleep(random.randint(1, 10))
Example #10
0
    def threads(self, data, address, lock):
        """
            run thread
        """
        #import Devices

        print "Data: " + data, "Nombre Hilo: " + self.thread.getName(), "Lock: " + str(lock)
        print "Hilo actual: ", threading.currentThread()
        print "Hilos presentes:",  threading.enumerate()
        
        # Parse Devices
        rawData = Devices.devices.getTypeClass(data, address) # retorna la data analizada en un diccionario
        
        if not rawData.has_key('id'): # Si la trama no tiene ID 
            print >> sys.stdout, rawData#, '\n'
            return # Termina de ejecutar el hilo

        print rawData # Imprime la data procesada (Print de Prueba)

        ### Eventos
        import Event.captureEvent
        event = Event.captureEvent.parseEvent(rawData) # Si se gestiona retorna el nombre del 
                                                       # evento gestionado. Si no retorna None.
        print "Evento Gestionado:", event
        # End Event

        ### Escribe el la Tabla de Log
        import Log.logDB as LogDB
        LogDB.insertLog(rawData)
        # End Tabla de Log

        #### Escribe en el Fichero de Log
        lock.acquire(True)
        self.__class__.endfile = logFile(str(load('FILELOG', 'FILE')),
                                         self.__class__.endfile,
                                         raw=rawData 
                                        )
        lock.release()
Example #11
0
def fechaHoraSkp(date, time):
    """
        Crea un datetime para la fecha y la hora en que la unidad 
        genero la trama.

        >>> from datetime import datetime
        >>> from pytz import timezone
        >>>
        >>> d1 = date(2012, 12, 4)
        >>> d2 = time(21, 27, 53, tzinfo=timezone('UTC'))
        >>> d3 = datetime.combine(d1, d2)
        >>> d3
        datetime.datetime(2012, 12, 4, 21, 27, 53, tzinfo=<UTC>)
        >>> d3.astimezone(timezone('America/Bogota'))
        datetime.datetime(2012, 12, 4, 16, 27, 53, tzinfo=<DstTzInfo 'America/Bogota' COT-1 day, 19:00:00 STD>)
        >>>

    """
    from datetime import datetime
    from Load.loadconfig import load
    utc = load('CONFIGURE', 'UTC')
    dt = datetime.combine(date, time)
    return dt.astimezone(timezone(str(utc)))
Example #12
0
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
    Server GPS

    Autor: Jorge A. Toro [[email protected]]
"""
import daemon
from Load.loadconfig import load

if __name__ == "__main__":
    server = daemon.DaemonUDP(
                str(load('DAEMON', 'DAEMONHost')), 
                int(load('DAEMON', 'DAEMONPort')), 
                int(load('DAEMON', 'DAEMONBuffer')) 
             )
    server.start()
    server.run()
Example #13
0
# -*- coding: UTF-8 -*-
"""
    Server GPS

    Autor: Jorge A. Toro [[email protected]]
"""
import daemon
from Load.loadconfig import load

#print("El fichero de modulos es: %s" % load('MODULES', 'GpsIP'))


if __name__ == "__main__":
    print ("Host: %s" % load('DAEMON', 'DAEMONHost'))
    server = daemon.DaemonUDP(load('DAEMON', 'DAEMONHost'), 50007, 256)
    server.start()
    server.run()
Example #14
0
#       documentation and/or other materials provided with the distribution.
#    3. Neither the name of copyright holders nor the names of its
#       contributors may be used to endorse or promote products derived
#       from this software without specific prior written permission.
#
#    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
#    ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
#    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
#    PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
#    BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
#    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
#    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
#    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#    POSSIBILITY OF SUCH DAMAGE.
"""
    Run Server UDP
"""

import daemon
from Load.loadconfig import load


if __name__ == "__main__":
    server = daemon.DaemonUDP(
        str(load("DAEMON", "DAEMONHost")), int(load("DAEMON", "DAEMONPort")), int(load("DAEMON", "DAEMONBuffer"))
    )
    server.start()
    server.run()
Example #15
0
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
    Server GPS

    Autor: Jorge A. Toro [[email protected]]
"""
import daemon
from Load.loadconfig import load

if __name__ == "__main__":
    server = daemon.DaemonUDP(str(load('DAEMON', 'DAEMONHost')),
                              int(load('DAEMON', 'DAEMONPort')),
                              int(load('DAEMON', 'DAEMONBuffer')))
    server.start()
    server.run()
Example #16
0
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
    Server GPS

    Autor: Jorge A. Toro [[email protected]]
"""
import daemon
from Load.loadconfig import load


if __name__ == "__main__":
    server = daemon.DaemonUDP(
                str(load('DAEMON', 'DAEMONHost')), 
                int(load('DAEMON', 'DAEMONPort')), 
                int(load('DAEMON', 'DAEMONBuffer')) 
             )
    server.start()
    server.run()