Added physical interaction detection into the build flow.
[smartthings-infrastructure.git] / Runner.py
1 import os
2
3 #Create directory for files to append in the main file
4
5 #Extract information from preferences and subscribe method to create required objects
6 os.system("python Extractor/ExtractorScript.py")
7
8 #Files for both Apps
9 Out = open("main.groovy", "w+")
10 GlobalVariablesBothApps = open("GlobalVariables/"+"GlobalVariablesBothApps.groovy", "r")
11 eventSimulator = open("eventSimulator/"+"eventSimulator.groovy", "r")
12
13 #For App1
14 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
15 setLocationMode = open("Methods/"+"setLocationMode.groovy", "r")
16 subscribe = open("Methods/"+"subscribe.groovy", "r")
17 runIn = open("Methods/"+"runIn.groovy", "r")
18 unschedule = open("Methods/"+"unschedule.groovy", "r")
19 sendNotificationToContacts = open("Methods/"+"sendNotificationToContacts.groovy", "r")
20 sendSms = open("Methods/"+"sendSms.groovy", "r")
21 sendPush = open("Methods/"+"sendPush.groovy", "r")
22 eventHandler = open("Methods/"+"eventHandler.groovy", "r")
23 schedule = open("Methods/"+"schedule.groovy", "r")
24 now = open("Methods/"+"now.groovy", "r")
25 App1 = open("Extractor/"+"App1/App1.groovy", "r")
26 extractedObjectsApp1 = open("Extractor/"+"App1/extractedObjectsApp1.groovy", "r")
27 extractedObjectsConstructorApp1 = open("Extractor/"+"App1/extractedObjectsConstructorApp1.groovy", "r")
28 extractedFunctionsApp1 = open("Extractor/"+"App1/extractedFunctionsApp1.groovy", "r")
29
30
31
32
33 Out.write("//Infrastructure for SmartThings Application\n")
34 Out.write("//Importing Libraries\n")
35 Out.write("import groovy.transform.Field\n")
36 Out.write("\n")
37 Out.write("//Importing Classes\n")
38 Out.write("import ContactSensor.ContactSensor\n")
39 Out.write("import ContactSensor.ContactSensors\n")
40 Out.write("import DoorControl.DoorControl\n")
41 Out.write("import DoorControl.DoorControls\n")
42 Out.write("import Lock.Lock\n")
43 Out.write("import Lock.Locks\n")
44 Out.write("import Thermostat.Thermostat\n")
45 Out.write("import Thermostat.Thermostats\n")
46 Out.write("import Switch.Switch\n")
47 Out.write("import Switch.Switches\n")
48 Out.write("import PresenceSensor.PresenceSensor\n")
49 Out.write("import PresenceSensor.PresenceSensors\n")
50 Out.write("import Logger.Logger\n")
51 Out.write("import Location.LocationVar\n")
52 Out.write("import Location.Phrase\n")
53 Out.write("import appTouch.Touched\n")
54 Out.write("import NfcTouch.NfcTouch\n")
55 Out.write("import AeonKeyFob.AeonKeyFob\n")
56 Out.write("import AeonKeyFob.AeonKeyFobs\n")
57 Out.write("import MusicPlayer.MusicPlayer\n")
58 Out.write("import MusicPlayer.MusicPlayers\n")
59 Out.write("import Event.Event\n")
60 Out.write("import Timer.SimulatedTimer\n")
61 Out.write("\n")
62 Out.write("//Global eventHandler\n")
63 for line in eventHandler:
64         Out.write(line)
65 Out.write("\n")
66 Out.write("//GlobalVariables for both Apps\n")
67 for line in GlobalVariablesBothApps:
68         Out.write(line)
69 Out.write("\n")
70 Out.write("//Application #1\n")
71 Out.write("class App1 {\n")
72 Out.write("\tdef reference\n")
73 Out.write("\tdef location\n")
74 Out.write("\tdef app\n")
75 Out.write("\n")
76 Out.write("\t//Extracted objects for App1\n")
77 for line in extractedObjectsApp1:
78         Out.write("\t"+line)
79 Out.write("\n")
80 Out.write("\t//Extracted objects for functions for App1\n")
81 for line in extractedFunctionsApp1:
82         Out.write("\t"+line)
83 Out.write("\n")
84 Out.write("\tApp1(Object obj) {\n")
85 Out.write("\t\treference = obj\n")
86 Out.write("\t\tlocation = obj.locationObject\n")
87 Out.write("\t\tapp = obj.appObject\n")
88 for line in extractedObjectsConstructorApp1:
89         Out.write("\t\t"+line)
90 Out.write("\t}\n")
91 Out.write("\t//Global variables for each app\n")
92 for line in GlobalVariablesEachApp:
93         Out.write("\t"+line)
94 Out.write("\n")
95 Out.write("\t//Methods\n")
96 for line in setLocationMode:
97         Out.write("\t"+line)
98 for line in subscribe:
99         Out.write("\t"+line)
100 for line in runIn:
101         Out.write("\t"+line)
102 for line in unschedule:
103         Out.write("\t"+line)
104 for line in sendNotificationToContacts:
105         Out.write("\t"+line)
106 for line in sendSms:
107         Out.write("\t"+line)
108 for line in sendPush:
109         Out.write("\t"+line)
110 for line in schedule:
111         Out.write("\t"+line)
112 for line in now:
113         Out.write("\t"+line)
114 Out.write("\n")
115 Start = 0
116 for line in App1:
117         if ("def " in line):
118                 Start = 1
119         if (Start):
120                 Out.write("\t"+line)
121 Out.write("}\n")
122 Out.write("\n")
123 Out.write("\n")
124 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
125
126 #For App2
127 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
128 setLocationMode = open("Methods/"+"setLocationMode.groovy", "r")
129 subscribe = open("Methods/"+"subscribe.groovy", "r")
130 runIn = open("Methods/"+"runIn.groovy", "r")
131 unschedule = open("Methods/"+"unschedule.groovy", "r")
132 sendNotificationToContacts = open("Methods/"+"sendNotificationToContacts.groovy", "r")
133 sendSms = open("Methods/"+"sendSms.groovy", "r")
134 eventHandler = open("Methods/"+"eventHandler.groovy", "r")
135 schedule = open("Methods/"+"schedule.groovy", "r")
136 App2 = open("Extractor/"+"App2/App2.groovy", "r")
137 extractedObjectsApp2 = open("Extractor/"+"App2/extractedObjectsApp2.groovy", "r")
138 extractedObjectsConstructorApp2 = open("Extractor/"+"App2/extractedObjectsConstructorApp2.groovy", "r")
139 extractedFunctionsApp2 = open("Extractor/"+"App2/extractedFunctionsApp2.groovy", "r")
140
141 Out.write("//Application #2\n")
142 Out.write("class App2 {\n")
143 Out.write("\tdef reference\n")
144 Out.write("\tdef location\n")
145 Out.write("\tdef app\n")
146 Out.write("\n")
147 Out.write("\t//Extracted objects for App2\n")
148 for line in extractedObjectsApp2:
149         Out.write("\t"+line)
150 Out.write("\n")
151 Out.write("\t//Extracted objects for functions for App2\n")
152 for line in extractedFunctionsApp2:
153         Out.write("\t"+line)
154 Out.write("\n")
155 Out.write("\tApp2(Object obj) {\n")
156 Out.write("\t\treference = obj\n")
157 Out.write("\t\tlocation = obj.locationObject\n")
158 Out.write("\t\tapp = obj.appObject\n")
159 for line in extractedObjectsConstructorApp2:
160         Out.write("\t\t"+line)
161 Out.write("\t}\n")
162 Out.write("\t//Global variables for each app\n")
163 for line in GlobalVariablesEachApp:
164         Out.write("\t"+line)
165 Out.write("\n")
166 Out.write("\t//Methods\n")
167 for line in setLocationMode:
168         Out.write("\t"+line)
169 for line in subscribe:
170         Out.write("\t"+line)
171 for line in runIn:
172         Out.write("\t"+line)
173 for line in unschedule:
174         Out.write("\t"+line)
175 for line in sendNotificationToContacts:
176         Out.write("\t"+line)
177 for line in sendSms:
178         Out.write("\t"+line)
179 for line in sendPush:
180         Out.write("\t"+line)
181 for line in schedule:
182         Out.write("\t"+line)
183 for line in now:
184         Out.write("\t"+line)
185 Out.write("\n")
186 Start = 0
187 for line in App2:
188         if ("def " in line):
189                 Start = 1
190         if (Start):
191                 Out.write("\t"+line)
192 Out.write("}\n")
193 Out.write("\n")
194 Out.write("@Field def app1 = new App1(this)\n")
195 Out.write("@Field def app2 = new App2(this)\n")
196 Out.write("app1.installed()\n")
197 Out.write("app2.installed()\n")
198 Out.write("\n")
199 for line in eventSimulator:
200         Out.write(line)
201 Out.close()
202
203
204
205