Esempio n. 1
0
def UpdateRealtime(retstr):
    SUBNAME = "UpdateRealtime"

    db=None
    result=""
    RT_LASTUPDATE=""
    RT_STATE=""
    RT_NOTE=""
    RT_SUBJECT=""

    # PREPARO PARAMETRI QUERY
    RT_LASTUPDATE=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    r=retstr.split(" ")
    r=r[3:] # TOLGO I PRIMI 3 ELEMENTI PERCHE VUOTI
    RT_SUBJECT=r[0]
    RT_STATE=r[1]
    RT_NOTE=" ".join(r[2:])

    # UPDATE TB_REALTIME
    try:
        db=dbmanager.openDB(db, str(os.path.dirname(os.path.abspath(__file__))) + "/db/",'system.db')
        result=dbmanager.UPDATE_TB_SYS_REALTIME_INFO(db,RT_SUBJECT,RT_STATE,RT_LASTUPDATE,RT_NOTE)
        if result != '':
            raise Exception(result)

    # ERRORE!
    except Exception as e:
        result = "Error-%s:%s " % (SUBNAME, e)
    # RITORNA RISULTATO
    finally:
        db = dbmanager.closeDB(db)
        return result
Esempio n. 2
0
def nrf24cmd (authKey,command):
    db = None
    result = ''
    try:
        if not ValidateKey(authKey):
            result = "Invalid Auth Key!"
        else:
            #print str(os.path.dirname(os.path.abspath(__file__))) + "/db/"
            db = dbmanager.openDB(db, str(os.path.dirname(os.path.abspath(__file__))) + "/db/","system.db")
            try:
                dbmanager.insert_TB_HOME_COM(db, command)
                r = dbmanager.select_last_TB_HOME_COM(db)
                if int(r[0]) > 0:
                    time.sleep(3)
                    result = dbmanager.select_TB_HOME_COM(db, str(r[0]))
                    if result != '':
                        result = result[4]
            except  Exception as e:
                db = dbmanager.closeDB(db)
                result = "Error-%s:%s " % ("nrf24cmd", e)

    except  Exception as e:
        result = "Error-%s:%s " % ("nrf24cmd", e)
    finally:
        return result
Esempio n. 3
0
def nrf24cmdlist(authKey):
    db = None
    result = ''
    try:
        if not ValidateKey(authKey):
            result = "Invalid Auth Key!"
        else:
            #print str(os.path.dirname(os.path.abspath(__file__))) + "/db/"
            db = dbmanager.openDB(db, str(os.path.dirname(os.path.abspath(__file__))) + "/db/","system.db")
            try:
                rows=dbmanager.select_TB_HOME_DIZ_CMD_LIST(db)
                for row in rows:
                    result = result+str(row[0])+";"
            except  Exception as e:
                db = dbmanager.closeDB(db)
                result = "Error-%s:%s " % ("nrf24cmdlist", e)

    except  Exception as e:
        result = "Error-%s:%s " % ("nrf24cmdlist", e)
    finally:
        return result
Esempio n. 4
0
def servicelist(authKey):
    db = None
    result = ''
    try:
        print 'servicelist'
        if not ValidateKey(authKey):
            result = "Invalid Auth Key!"
        else:
            #print str(os.path.dirname(os.path.abspath(__file__))) + "/db/"
            db = dbmanager.openDB(db, str(os.path.dirname(os.path.abspath(__file__))) + "/db/","system.db")
            try:
                rows=dbmanager.SELECT_TB_SYS_SERVICE_LIST(db)
                for row in rows:
                    result = result+str(row[0])+";"
            except  Exception as e:
                db = dbmanager.closeDB(db)
                result = "Error-%s:%s " % ("servicelist", e)

    except  Exception as e:
        result = "Error-%s:%s " % ("servicelist", e)
    finally:
        return result
Esempio n. 5
0
def realtimeupd ():
    db = None
    result = ''
    try:
        data = {
            "vncserver": ["vncserver","ok","23122018_01"],"samba":["samba","ok","23122018_02"]
        }
        data2={}
        # ESEGUO SCRIPT RT.PY
        cmd="python %s/rt.py" % str(os.path.dirname(os.path.abspath(__file__)))
        system(cmd)
        # LEGGO ELENCO TB_REALTIME
        db = dbmanager.openDB(db, str(os.path.dirname(os.path.abspath(__file__))) + "/db/", 'system.db')
        rows = DB_Manager.SELECT_TB_SYS_SERVICE_INFO(db)
        for row in rows:
            data2[row[0]]=[str(row[0]),str(row[1]),str(row[2])]

        result=json.dumps(data2)
    except  Exception as e:
        result = "Error-%s:%s " % ("realtimeupd", e)
    finally:
        return result
Esempio n. 6
0
    def run(self):
        out = ""
        try:
            self.db = dbmanager.openDB(
                self.db,
                str(os.path.dirname(os.path.abspath(__file__))) + "/db/",
                'system.db')
            while 1:
                if self.ser.isOpen():

                    out = ""
                    mex = ""
                    while self.ser.inWaiting() > 0:
                        out = self.ser.readline()
                    out = ''.join(ch for ch in str(out) if ch.isalnum())
                    if out != "":
                        # HOME
                        mex = dbmanager.select_TB_HOME_DIZ_RES(
                            self.db, str(int(out) / 100), str(int(out) % 100))
                        dbmanager.update_last_TB_HOME_COM(
                            self.db, str(self.LAST_REQ_ID), "", out, mex)
                        print '<<' + out
                        print mex
                        # HOME
                        if self.RES_REQ_ID != self.LAST_REQ_ID:
                            self.RES_REQ_ID = self.LAST_REQ_ID

                    r = dbmanager.select_last_TB_HOME_COM(self.db)

                    # print "Leggo richiesta numero "+str(r[0])
                    if r != '':
                        if not int(r[0]) == self.LAST_REQ_ID:
                            if self.LAST_REQ_ID != 0:
                                #print "Leggo richiesta numero " + str(r[0]) + " " + str(r[1])
                                self.firs_time = 0

                            self.LAST_REQ_ID = int(r[0])
                            # print r[0],type(r[0]),r[2],type(r[2]),r[3],type(r[3])
                            self.COM_BUFF_TX = dbmanager.select_TB_HOME_DIZ_CMD(
                                self.db,
                                str(r[1]).strip())
                            # self.COM_BUFF_TX =''.join(ch for ch in str(r[1]) if ch.isalnum())

                    if self.COM_BUFF_TX != '' and self.ser.isOpen(
                    ) and self.firs_time == 0:
                        dbmanager.update_last_TB_HOME_COM(
                            self.db, str(self.LAST_REQ_ID), self.COM_BUFF_TX,
                            "", "")
                        print '>>' + self.COM_BUFF_TX
                        self.COM_BUFF_TX = self.COM_BUFF_TX.encode('utf-8')
                        self.ser.write(self.COM_BUFF_TX)
                        self.ser.flush()
                        time.sleep(0.5)
                        self.COM_BUFF_TX = ''

                else:
                    break

        except Exception as e:
            self.db = dbmanager.closeDB(self.db)
            print "Error:", e