コード例 #1
0
    def remove_job(p_comment):
        """Removes existing cron job"""
        LOGGER.info('REMOVEJOB')
        LOGGER.debug('p_comment : ' + p_comment)

        LOGGER.info('checkjob')
        #######################Query to check whether a record exists in table#
        checkjob = "SELECT EXISTS (SELECT * FROM schedular WHERE "
        checkjob = checkjob + "comment='" + p_comment + "' AND isdeleted = 0);"
        LOGGER.debug(checkjob)

        count = ml.db_fetchone(checkjob)
        LOGGER.info('executed')
        LOGGER.debug('count >> ' + str(count))
        #######################Query to check whether a record exists in table#

        if count == 1:
            LOGGER.info('REMOVING JOB...')
            LOGGER.info('CRONTAB section start')
            #*************************CRONTAB*************************#
            for job in USER_CRON.find_comment(p_comment):
                if "pi~@$^*" not in job.comment:  # To avoid pi Jobs
                    USER_CRON.remove(job)

                    LOGGER.info('removejob')
                    #######################Update Query#######################
                    removejob = "UPDATE schedular SET "
                    removejob = removejob + \
                        "isdeleted = 1,updated_date = datetime('now', 'localtime') WHERE "
                    removejob = removejob + "comment='" + p_comment + "';"
                    LOGGER.debug(removejob)

                    ml.db_execquery(removejob)
                    LOGGER.info('executed')
                    #######################Update Query#######################

            #*************************CRONTAB*************************#
            LOGGER.info('CRONTAB section end!')
            USER_CRON.write()  # Actual write to crontab
            LOGGER.info('CRONTAB write')
            #****$$****JSONDUMP****$$****#
            flag = '1'
            msg = 'Record deleted successfully'
            dump = {'flag': flag, 'msg': msg}
            LOGGER.debug('dump >> flag:' + flag + ',msg:' + msg)
            print json.dumps(dump)
            #****$$****JSONDUMP****$$****#
            LOGGER.info('JSON dumps')
        else:
            LOGGER.info('job not found')
コード例 #2
0
ファイル: codesend.py プロジェクト: hiteshtare/beymax-python
            # Extraction of Details from Code

            DETAILS = 'USER_ID:' + USER_ID + ' ROOM_NO:' + ROOM_NO + \
                ' D_TYPE:' + D_TYPE + ' NO:' + NO + ' STATUS_CODE:' + STATUS_CODE
            LOGGER.debug('DETAILS >> ' + DETAILS)

            if STATUS_CODE != "99":  # To avoid code that is triggered by rpi

                LOGGER.info('DEVICE_CHECK')
                # Query to check whether a record exists i
                DEVICE_CHECK = "SELECT EXISTS (SELECT * FROM revoke WHERE "
                DEVICE_CHECK = DEVICE_CHECK + "deviceid=" + \
                    USER_ID + STR_ROOM_NO + D_TYPE + NO + " );"
                LOGGER.debug(DEVICE_CHECK)

                COUNT = ml.db_fetchone(DEVICE_CHECK)
                LOGGER.info('executed')
                LOGGER.debug('COUNT >> ' + str(COUNT))
                # Query to check whether a record exists i
                if COUNT == 1:
                    # Query to check whether a record exis
                    LOGGER.info('REVOKE_CHECK')
                    REVOKE_CHECK = "SELECT EXISTS (SELECT * FROM revoke WHERE "
                    REVOKE_CHECK = REVOKE_CHECK + "deviceid=" + USER_ID + \
                        STR_ROOM_NO + D_TYPE + NO + " AND ischeck=1 );"
                    LOGGER.debug(REVOKE_CHECK)

                    COUNT = ml.db_fetchone(REVOKE_CHECK)
                    LOGGER.info('executed')
                    LOGGER.debug('COUNT >> ' + str(COUNT))
                    # Query to check whether a record exis
コード例 #3
0
        # Increment the minute total
        elif mins > settime / 2:
            print ">second phase>", mins
            logger.info('>second phase>' + str(mins))

            time.sleep(1)

            #read database
            logger.info('checksql')
            #######################Query to check whether a record exists in table#######################
            checksql = "SELECT EXISTS (select * from motion WHERE "
            checksql = checksql + "userid=" + user_id + " AND room=" + room_no + " AND type=" + d_type + " AND no=" + no + " AND status=12);"
            logger.debug(checksql)

            count = ml.db_fetchone(checksql)
            logger.info('executed')
            logger.debug('count >> ' + str(count))
            #######################Query to check whether a record exists in table#######################

            if count == 1:  #record already exists go with updation
                logger.info('*-*Timer Reset*-*')
                mins = 0  #reset the timer
                #dump null into database
                logger.info('resettimer')
                #######################Update Query#######################
                resettimer = "update motion set "
                resettimer = resettimer + "status =99 , start_date = datetime('now', 'localtime'), updated_date = datetime('now', 'localtime') WHERE "
                resettimer = resettimer + "userid=" + user_id + " AND room=" + room_no + " AND type=" + d_type + " AND no=" + no + ";"
                logger.debug(resettimer)
コード例 #4
0
    def insert_job(p_comment, p_timeslice, p_command, p_devicestat):
        """Inserts a new cron job"""
        LOGGER.info('INSERTJOB')
        LOGGER.debug('p_devicestat : ' + p_devicestat)

        # Extraction of Details from p_devicestat
        arr_devicestat = p_devicestat.split('.')
        room = arr_devicestat[0]
        d_type = arr_devicestat[1]
        number = arr_devicestat[2]
        status = arr_devicestat[3]
        # Extraction of Details from p_devicestat

        commanddetails = 'room:' + room + ' type:' + \
            d_type + ' no:' + number + ' status:' + status
        LOGGER.debug('command details >> ' + commanddetails)
        jobdetails = 'p_command:' + p_command + ' p_comment:' + \
            p_comment + ' p_timeslice:' + p_timeslice
        LOGGER.debug('job details >> ' + jobdetails)

        LOGGER.info('checkjob')
        #######################Query to check whether a record exists in table#
        checkjob = "SELECT EXISTS (SELECT * from schedular WHERE "
        checkjob = checkjob + "comment='" + p_comment + "' AND isdeleted = 0);"
        LOGGER.debug(checkjob)

        count = ml.db_fetchone(checkjob)
        LOGGER.info('executed')
        LOGGER.debug('count >> ' + str(count))
        #######################Query to check whether a record exists in table#

        if count == 1:
            LOGGER.info('JOB ALREADY EXISTS')
            #****$$****JSONDUMP****$$****#
            flag = '0'
            msg = 'Record already Exist'
            dump = {'flag': flag, 'msg': msg}
            LOGGER.debug('dump >> flag:' + flag + ',msg:' + msg)
            print json.dumps(dump)
            #****$$****JSONDUMP****$$****#
            LOGGER.info('JSON dumps')
        else:
            LOGGER.info('NEW JOB')
            LOGGER.info('CRONTAB section start')
            #*************************CRONTAB*************************#
            job = USER_CRON.new(command=p_command, comment=p_comment)
            job.setall(p_timeslice)
            freq = job.frequency_per_day()
            schedule = job.schedule(date_from=datetime.now())
            prev_sche = schedule.get_prev()
            next_sche = schedule.get_next()
            #*************************CRONTAB*************************#
            LOGGER.info('CRONTAB section end!')

            computeddetails = 'Frequency:' + \
                str(freq) + ' Prev Schedule:' + str(prev_sche) + \
                ' Next Schedule:' + str(next_sche)
            LOGGER.debug('computed details >> ' + computeddetails)

            LOGGER.info('insertjob')
            #######################Insert Query#######################
            insertjob = "INSERT INTO schedular (room, type, no, status, command, comment, timeslice, frequency, prev_schedule, next_schedule, inserted_date, updated_date) VALUES ("
            insertjob = insertjob + "'" + room + "','" + type + "','" + number + "','" + status + "','" + p_command + "','" + p_comment + "','" + p_timeslice + \
                "','" + str(freq) + "','" + str(prev_sche) + "','" + str(next_sche) + \
                "',datetime('now', 'localtime'),datetime('now', 'localtime'));"
            LOGGER.debug(insertjob)

            ml.db_execquery(insertjob)
            LOGGER.info('executed')
            #######################Insert Query#######################

            USER_CRON.write()  # Actual write to crontab
            LOGGER.info('CRONTAB write')
            #****$$****JSONDUMP****$$****#
            flag = '1'
            msg = 'Record added successfully'
            dump = {'flag': flag, 'msg': msg}
            LOGGER.debug('dump >> flag:' + flag + ',msg:' + msg)
            print json.dumps(dump)
            #****$$****JSONDUMP****$$****#
            LOGGER.info('JSON dumps')
コード例 #5
0
    def disable_job(p_comment, p_timeslice):
        """Disables existing cron job"""
        LOGGER.info('DISABLEJOB')
        LOGGER.debug('p_comment : ' + p_comment)
        LOGGER.debug('p_timeslice : ' + p_timeslice)

        LOGGER.info('checkjob')
        #######################Query to check whether a record exists in table#
        checkjob = "SELECT EXISTS (SELECT * FROM schedular WHERE "
        checkjob = checkjob + "comment='" + p_comment + \
            "' AND isactive = 1 AND isdeleted = 0);"
        LOGGER.debug(checkjob)

        count = ml.db_fetchone(checkjob)
        LOGGER.info('executed')
        LOGGER.debug('count >> ' + str(count))
        #######################Query to check whether a record exists in table#

        if count == 1:
            LOGGER.info('DISABLING JOB...')
            LOGGER.info('CRONTAB section start')
            #*************************CRONTAB*************************#
            for job in USER_CRON.find_comment(p_comment):
                job.enable(False)
                job.setall(p_timeslice)
                freq = job.frequency_per_day()
                schedule = job.schedule(date_from=datetime.now())
                prev_sche = schedule.get_prev()
                next_sche = schedule.get_next()

                LOGGER.info('disablejob')
                #######################Update Query#######################
                disablejob = "UPDATE schedular SET "
                disablejob = disablejob + "timeslice = '" + p_timeslice + "' , frequency = " + str(freq) + " , prev_schedule = '" + str(
                    prev_sche) + "' , next_schedule = '" + str(next_sche) + "' , isactive = 0,updated_date = datetime('now', 'localtime') WHERE "
                disablejob = disablejob + "comment='" + p_comment + "' AND isdeleted = 0;"
                LOGGER.debug(disablejob)

                ml.db_execquery(disablejob)
                LOGGER.info('executed')
                #######################Update Query#######################
            #*************************CRONTAB*************************#
            LOGGER.info('CRONTAB section end!')
            USER_CRON.write()  # Actual write to crontab
            LOGGER.info('CRONTAB write')
            #****$$****JSONDUMP****$$****#
            flag = '1'
            msg = 'Record updated successfully'
            dump = {'flag': flag, 'msg': msg}
            LOGGER.debug('dump >> flag:' + flag + ',msg:' + msg)
            print json.dumps(dump)
            #****$$****JSONDUMP****$$****#
            LOGGER.info('JSON dumps')
        else:
            LOGGER.info('checkjob_dis')
            # Query to check whether a record exists in ta
            checkjob_dis = "SELECT EXISTS (SELECT * FROM schedular WHERE "
            checkjob_dis = checkjob_dis + "comment='" + \
                p_comment + "' AND isactive = 0 AND isdeleted = 0);"
            LOGGER.debug(checkjob_dis)

            count = ml.db_fetchone(checkjob_dis)
            LOGGER.info('executed')
            LOGGER.debug('count >> ' + str(count))
            # Query to check whether a record exists in ta

            if count == 1:
                LOGGER.info('UPDATING SCHEDULE...')
                LOGGER.info('CRONTAB section start')
                #*************************CRONTAB*************************#
                for job in USER_CRON.find_comment(p_comment):
                    job.setall(p_timeslice)
                    freq = job.frequency_per_day()
                    schedule = job.schedule(date_from=datetime.now())
                    prev_sche = schedule.get_prev()
                    next_sche = schedule.get_next()

                    LOGGER.info('updateschedule')
                    #######################Update Query#######################
                    updateschedule = "UPDATE schedular SET "
                    updateschedule = updateschedule + "timeslice = '" + p_timeslice + "' , frequency = " + str(freq) + " , prev_schedule = '" + str(
                        prev_sche) + "' , next_schedule = '" + str(next_sche) + "' , updated_date = datetime('now', 'localtime') WHERE "
                    updateschedule = updateschedule + "comment='" + p_comment + "' AND isdeleted = 0;"
                    LOGGER.debug(updateschedule)

                    ml.db_execquery(updateschedule)
                    LOGGER.info('executed')
                    #######################Update Query#######################
                #*************************CRONTAB*************************#
                LOGGER.info('CRONTAB section end!')
                USER_CRON.write()  # Actual write to crontab
                LOGGER.info('CRONTAB write')
                #****$$****JSONDUMP****$$****#
                flag = '1'
                msg = 'Record updated successfully'
                dump = {'flag': flag, 'msg': msg}
                LOGGER.debug('dump >> flag:' + flag + ',msg:' + msg)
                print json.dumps(dump)
                #****$$****JSONDUMP****$$****#
                LOGGER.info('JSON dumps')
            else:
                LOGGER.info('job not found')
コード例 #6
0
ファイル: sendmail.py プロジェクト: hiteshtare/beymax-python
            TO_ADDRESS) + ' From:	' + str(FROM_ADDRESS) + ' Sub:	' + str(
                MSG_SUBJECT)
    LOGGER.warning('sendmail has started with CONFIG. >> ' + CONFIG)

    # Construct email
    MSG = MIMEMultipart('alternative')
    MSG['To'] = TO_ADDRESS
    MSG['From'] = FROM_ADDRESS
    MSG['Subject'] = MSG_SUBJECT + " : " + FULL_NAME

    # read database
    LOGGER.info('CHECK_FEEDBACK')
    #######################Query to check whether a record exists in table####
    CHECK_FEEDBACK = "SELECT COUNT(*) FROM feedback WHERE issend=0;"
    LOGGER.debug(CHECK_FEEDBACK)
    COUNT = ml.db_fetchone(CHECK_FEEDBACK)
    LOGGER.info('executed')
    LOGGER.debug('COUNT >> ' + str(COUNT))
    #######################Query to check whether a record exists in table####

    if COUNT != 0:  # records exists go with updation
        LOGGER.info('*-*Records Found*-*')

        LOGGER.info('GET_FEEDBACK')
        GET_FEEDBACK = "SELECT * FROM feedback WHERE issend=0 ORDER BY inserted_date asc;"
        LOGGER.debug(GET_FEEDBACK)
        CURSOR = ml.db_fetchall(GET_FEEDBACK)
        LOGGER.info('executed')

        ATTACH_COUNT = 0
        for row in CURSOR:
コード例 #7
0
ファイル: dbtest.py プロジェクト: hiteshtare/beymax-python
import time
import pigpio
import vw
import sys
import traceback

import os
import subprocess
import mylib as ml  #user-defined

try:

    fetch_humi1 = "select humi from humis WHERE roomno=1;"

    humi1 = ml.db_fetchone(fetch_humi1)
    print "humi1 :" + str(humi1)

    fetch_humi2 = "select humi from humis WHERE roomno=2;"

    humi2 = ml.db_fetchone(fetch_humi2)
    print "humi2 :" + str(humi2)

    fetch_temp1 = "select temp from temps WHERE roomno=1;"

    temp1 = ml.db_fetchone(fetch_temp1)
    print "temp1 :" + str(temp1)

    fetch_temp2 = "select temp from temps WHERE roomno=2;"

    temp2 = ml.db_fetchone(fetch_temp2)
コード例 #8
0
ファイル: RFSniffer.py プロジェクト: hiteshtare/beymax-python
                LOGGER.debug('DETAILS >> ' + DETAILS)

                CODE_VALID = False
                LOGGER.info('code validity check >>')
                CODE_VALID = True if ml.check_int(USER_ID, ROOM_NO, D_TYPE, NO,
                                                  STATUS_CODE) else False

                if CODE_VALID == True:
                    # Query to check whether a give table
                    #-----------------------------To Check Table Exists new logic--------------------------------------#
                    LOGGER.debug('TABLE_SQL')
                    TABLE_SQL = "SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND "
                    TABLE_SQL = TABLE_SQL + "name='room" + ROOM_NO + "_log';"
                    LOGGER.debug(TABLE_SQL)

                    COUNT = ml.db_fetchone(TABLE_SQL)
                    LOGGER.info('executed')
                    LOGGER.debug('COUNT >> ' + str(COUNT))

                    if COUNT == 0:  # table does not exists go with creation
                        LOGGER.info('new log table creation : NEW_TABLE_SQL')
                        #######################new Table Creation##############
                        NEW_TABLE_SQL = "CREATE TABLE room" + ROOM_NO + "_log"
                        NEW_TABLE_SQL = NEW_TABLE_SQL + \
                            " (userid int, room int, type int, NO int, status int, inserted_date datetime);"
                        LOGGER.debug(NEW_TABLE_SQL)

                        ml.db_execquery(NEW_TABLE_SQL)
                        LOGGER.info('executed')
                        #######################new Table Creation##############