Beispiel #1
0
    def remove_all_jobs():
        """Removes all existing cron jobs"""
        LOGGER.info('REMOVEALLJOBS')

        LOGGER.info('REMOVING ALL JOBS...')
        LOGGER.info('CRONTAB section start')
        #*************************CRONTAB*************************#
        for job in USER_CRON:
            if "pi~@$^*" not in job.comment:
                USER_CRON.remove(job)
        #*************************CRONTAB*************************#
        LOGGER.info('CRONTAB section end!')

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

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

        USER_CRON.write()  # Actual write to crontab
        LOGGER.info('CRONTAB write')
        #****$$****JSONDUMP****$$****#
        flag = '1'
        msg = 'All Records deleted successfully'
        dump = {'flag': flag, 'msg': msg}
        LOGGER.debug('dump >> flag:' + flag + ',msg:' + msg)
        print json.dumps(dump)
        #****$$****JSONDUMP****$$****#
        LOGGER.info('JSON dumps')
Beispiel #2
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')
Beispiel #3
0
    def update_jobs():
        """Updates all existing cron jobs"""
        LOGGER.info('UPDATEJOBS')

        LOGGER.info('UPDATING SCHEDULE FOR ALL JOBS...')
        LOGGER.info('CRONTAB section start')
        #*************************CRONTAB*************************#
        for job in USER_CRON:
            comment = job.comment
            LOGGER.debug('comment : ' + comment)

            schedule = job.schedule(date_from=datetime.now())
            prev_sche = schedule.get_prev()
            next_sche = schedule.get_next()

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

            LOGGER.info('updateschedule')
            #######################Update Query#######################
            updateschedule = "UPDATE schedular SET "
            updateschedule = updateschedule + "prev_schedule = '" + \
                str(prev_sche) + "',next_schedule  = '" + \
                str(next_sche) + "' WHERE "
            updateschedule = updateschedule + "comment='" + \
                comment + "' AND isactive = 1 AND isdeleted = 0;"
            LOGGER.debug(updateschedule)

            ml.db_execquery(updateschedule)
            LOGGER.info('executed')
            #######################Update Query#######################
        #*************************CRONTAB*************************#
        LOGGER.info('CRONTAB section end!')
        #****$$****JSONDUMP****$$****#
        flag = '1'
        msg = 'All Records updated successfully'
        dump = {'flag': flag, 'msg': msg}
        LOGGER.debug('dump >> flag:' + flag + ',msg:' + msg)
        print json.dumps(dump)
        #****$$****JSONDUMP****$$****#
        LOGGER.info('JSON dumps')
Beispiel #4
0
                LOGGER.debug('COUNT >> ' + str(COUNT))

                # Query to check whether a record exists i

                if COUNT == 1:  # record already exists go with updation
                    LOGGER.info('UPDATE_SQL')

                    #######################Update Query#######################
                    UPDATE_SQL = "UPDATE devicestat SET "
                    UPDATE_SQL = UPDATE_SQL + "status =" + STATUS_CODE + \
                        " , updated_date = datetime('NOw', 'localtime') , ack = 0  WHERE "
                    UPDATE_SQL = UPDATE_SQL + "userid=" + USER_ID + " AND room=" + \
                        ROOM_NO + " AND type=" + D_TYPE + " AND NO=" + NO + ";"
                    LOGGER.debug(UPDATE_SQL)

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

                else:  # record does NOt exists go with insertion
                    LOGGER.info('INSERT_SQL')

                    #######################Insert Query#######################
                    INSERT_SQL = "INSERT INTO devicestat (userid, room, type, NO, status,updated_date) VALUES ("
                    INSERT_SQL = INSERT_SQL + USER_ID + "," + ROOM_NO + "," + D_TYPE + \
                        "," + NO + "," + STATUS_CODE + \
                        ",datetime('NOw', 'localtime'));"
                    LOGGER.debug(INSERT_SQL)

                    ml.db_execquery(INSERT_SQL)
                    LOGGER.info('executed')
Beispiel #5
0
            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)

                ml.db_execquery(resettimer)
                logger.info('executed')
                #######################Update Query#######################

            #mins += 1

        mins += 1

        if mins == 1:
            logger.info('minchangecode')
            #######################Update Query#######################
            minchangecode = "update motion set "
            minchangecode = minchangecode + "status =88 , start_date = datetime('now', 'localtime'), updated_date = datetime('now', 'localtime') WHERE "
            minchangecode = minchangecode + "userid=" + user_id + " AND room=" + room_no + " AND type=" + d_type + " AND no=" + no + ";"
            logger.debug(minchangecode)
Beispiel #6
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')
Beispiel #7
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')
Beispiel #8
0
                MSG.attach(part)

            server = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
            server.starttls()

            server.login(FROM_ADDRESS, FROM_PASSWORD)
            server.sendmail(FROM_ADDRESS, TO_ADDRESS, MSG.as_string())

            print 'Email sent!'
            LOGGER.info('Email sent!')

            LOGGER.info('updatefeedback')
            updatefeedback = "UPDATE feedback SET "
            updatefeedback = updatefeedback + \
                "issend=1 , send_date = datetime('now', 'localtime') WHERE "
            updatefeedback = updatefeedback + "message='" + message + "' ;"
            LOGGER.debug(updatefeedback)
            ml.db_execquery(updatefeedback)
            LOGGER.info('executed')
            #######################Update Query#######################

        LOGGER.info('**AttachCount**')
        LOGGER.debug('ATTACH_COUNT >> ' + str(ATTACH_COUNT))
    else:
        LOGGER.info('No Records found!')

    LOGGER.warning('sendmail has stopped << ')
except:
    LOGGER.exception("got error")
    LOGGER.critical('senmail has stopped unexpectedly!!! <<')
Beispiel #9
0
    NUM = 3
    MSG = 0

    START = time.time()

    CONFIG = ' TX:' + str(TX) + ' RX:' + str(RX) + ' BPS:' + str(BPS)
    LOGGER.warning('RFSniffer has started with CONFIG. >> ' + CONFIG)

    LOGGER1.warning('RFSniffer has started >> ')
    ################Update entry for RFSniffer################
    LOGGER.info('Update entry for RFSniffer in db')

    UPDATE_ENTRY = "UPDATE status SET isrunning=1 WHERE name='RFSniffer'"
    LOGGER.debug(UPDATE_ENTRY)

    ml.db_execquery(UPDATE_ENTRY)
    LOGGER.info('executed')
    ################Update entry for RFSniffer################

    CAL_TEMP = ""  # testing

    while (time.time() - START) > 0:

        while not TX.ready():
            time.sleep(0.02)

            time.sleep(0.1)

        while not TX.ready():
            time.sleep(0.02)