コード例 #1
0
ファイル: pS.py プロジェクト: Donlanes/donlanes-projector
def main():
    try:
        projector = Projector()
    except ProjectorNotConnected:
        no_projector_message()
        sys.exit(-1)

    light = Light()

    if len(sys.argv) <= 1:
        print "Command required."
        sys.exit(-1)
    command = sys.argv[1]

    time.sleep(.5)

    # Control light.
    if command == 'ON' :
        light.set_state(False)
    elif command == 'OFF' :
        light.set_state(True)
    elif command == '711':
        if not ENABLE_SEVLEV_EMAIL:
            log_to_file('711.mail.disabled\n')

        if light.sevlev() and ENABLE_SEVLEV_EMAIL:
            SEVLEV_EMAIL_INTERVAL = 5*60 # 30 minutes
            if int(time.time()) - get_last_email_sent_time() > SEVLEV_EMAIL_INTERVAL:
                log_to_file('711.mail.sending\n')
                send_sevlev_mail()
                save_last_email_sent_time()
            else:
                log_to_file('711.mail.ignoring\n')
    elif (command == '711-force'):
        send_sevlev_mail()

    # Control projector.
    if projector.is_valid_cmd(command):
        projector.run_cmd(command)