if (node["sendOption"] == 2): helper.loadPage(itemChecker.getWebAction(node, codearg), 0) elif (node["sendOption"] == 1): helper.runRadioSwitch(helper.settings.data["conradCodeSendPath"], str(node[codearg])) elif (node["sendOption"] == 0): helper.runRadioSwitch(helper.settings.data["codeSendPath"], str(node[codearg])) helper.deleteFile(helper.settings.data["delayfilesPath"] + '{0}.json'.format(namearg)) if helper.saveDailyLogsToFile: messageBody = "[AUTO] switch device " + str( namearg) + " with status=off" helper.writeLogToFile(time.strftime('actions/actions_%Y%m%d'), messageBody) except Exception, e: message = "[delayed_action error] for: " for arg in argv: message += str(arg) message += str(e) helper.writeExceptionToFile(message) helper.logMessage(message) pass except OSError: helper.writeExceptionToFile("Error on delayed_action for " + node["name"]) pass
from helpers import Helper scriptarg, namearg, codearg = argv helper = Helper() try: radioLockFilePath = helper.settings.data[ "delay.files.path"] + '{0}.lock'.format("radioLockFile") if os.path.exists(helper.settings.data["delay.files.path"]): radioLockFile = open(radioLockFilePath, 'w+') while True: try: fcntl.flock(radioLockFile, fcntl.LOCK_EX | fcntl.LOCK_NB) helper.logMessage("[run_radio_switch] execute radio switch...") call([namearg, codearg]) fcntl.flock(radioLockFile, fcntl.LOCK_UN) break except IOError as e: # raise on unrelated IOErrors if e.errno != errno.EAGAIN: raise else: helper.logMessage( "[run_radio_switch] radio transmission locked. Waiting to retry..." ) time.sleep(0.2) else: call([namearg, codearg]) except Exception, e: