aboutsummaryrefslogtreecommitdiff
path: root/src/compileAndRun/pythonSupportFiles/entry.py
blob: 45de822b5444658ff119acab644bbb5616ac9940 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# This is the entry-point for all Luxcena-Neo python-scripts
# The script should be in the same folder as this, and be named "script.py"
# In the future you could possibly have more files and stuff alongside the "script.py"-file as well
import sys
import json
import importlib
import datetime

def runSync(moduleSc, sc):
    timeNow = datetime.datetime.now()
    lastDay = timeNow.day
    lastHour = timeNow.hour
    lastMinute = timeNow.minute
    lastSecond = timeNow.second

    while True:
        timeNow = datetime.datetime.now()

        if ("LuxcenaNeo" in dir(moduleSc)):
            if moduleSc.LuxcenaNeo.forceStop: break
        elif ("neo" in dir(moduleSc)):
            if moduleSc.neo.forceStop == True: break

        if (timeNow.second != lastSecond):
            lastSecond = timeNow.second
            sc.eachSecond()

        if (timeNow.minute != lastMinute):
            lastMinute = timeNow.minute
            sc.eachMinute()

        if (timeNow.hour != lastHour):
            lastHour = timeNow.hour
            sc.eachHour()

        if (timeNow.day != lastDay):
            lastDay = timeNow.lastDay
            sc.eachDay()

def runAsync(moduleSc, sc):
    return

def main():
    print ("Starting script named \"{0}\"".format("test"))

    root_dir = sys.argv[1]
    config_dir = root_dir + "/config/"

    print ("> Loading pixel-configuration...")
    with open(config_dir + "strip.json", "r") as rawStripConf:
        stripConf = json.load(rawStripConf)

    print ("> Initializing script...")
    moduleSc = importlib.import_module("script")

    if ("LuxcenaNeo" in dir(moduleSc)):
        moduleSc.LuxcenaNeo.strip = moduleSc.LuxcenaNeo.Strip(stripConf)
    elif ("neo" in dir(moduleSc)):
        moduleSc.neo.strip = moduleSc.neo.Strip(stripConf)
    else:
        raise Exception("Neither LuxcenaNeo nor neo found in script, check docs!")

    sc = moduleSc.Main()

    print ("> Running the script...")
    sc.onStart()

    if (("async" in dir(moduleSc)) and (moduleSc.async == True)):
        runAsync(moduleSc, sc)
    else:
        runSync(moduleSc, sc)

    print ("> Script exited...")

if __name__ == "__main__":
    main()