Commit #10: more classes
[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 getTemperatureScale = open("Methods/"+"getTemperatureScale.groovy", "r")
26 getSunriseAndSunset = open("Methods/"+"getSunriseAndSunset.groovy", "r")
27 App1 = open("Extractor/"+"App1/App1.groovy", "r")
28 extractedObjectsApp1 = open("Extractor/"+"App1/extractedObjectsApp1.groovy", "r")
29 extractedObjectsConstructorApp1 = open("Extractor/"+"App1/extractedObjectsConstructorApp1.groovy", "r")
30 extractedFunctionsApp1 = open("Extractor/"+"App1/extractedFunctionsApp1.groovy", "r")
31
32
33
34
35 Out.write("//Infrastructure for SmartThings Application\n")
36 Out.write("//Importing Libraries\n")
37 Out.write("import groovy.transform.Field\n")
38 Out.write("\n")
39 Out.write("//Importing Classes\n")
40 Out.write("import ContactSensor.ContactSensor\n")
41 Out.write("import ContactSensor.ContactSensors\n")
42 Out.write("import DoorControl.DoorControl\n")
43 Out.write("import DoorControl.DoorControls\n")
44 Out.write("import Lock.Lock\n")
45 Out.write("import Lock.Locks\n")
46 Out.write("import Thermostat.Thermostat\n")
47 Out.write("import Thermostat.Thermostats\n")
48 Out.write("import Switch.Switch\n")
49 Out.write("import Switch.Switches\n")
50 Out.write("import PresenceSensor.PresenceSensor\n")
51 Out.write("import PresenceSensor.PresenceSensors\n")
52 Out.write("import Logger.Logger\n")
53 Out.write("import Location.LocationVar\n")
54 Out.write("import Location.Phrase\n")
55 Out.write("import appTouch.Touched\n")
56 Out.write("import NfcTouch.NfcTouch\n")
57 Out.write("import AeonKeyFob.AeonKeyFob\n")
58 Out.write("import AeonKeyFob.AeonKeyFobs\n")
59 Out.write("import MusicPlayer.MusicPlayer\n")
60 Out.write("import MusicPlayer.MusicPlayers\n")
61 Out.write("import MotionSensor.MotionSensor\n")
62 Out.write("import MotionSensor.MotionSensors\n")
63 Out.write("import ImageCapture.ImageCapture\n")
64 Out.write("import ImageCapture.ImageCaptures\n")
65 Out.write("import SmokeDetector.SmokeDetector\n")
66 Out.write("import SmokeDetector.SmokeDetectors\n")
67 Out.write("import Alarm.Alarm\n")
68 Out.write("import Alarm.Alarms\n")
69 Out.write("import SpeechSynthesis.SpeechSynthesis\n")
70 Out.write("import SpeechSynthesis.SpeechSynthesises\n")
71 Out.write("import AccelerationSensor.AccelerationSensor\n")
72 Out.write("import AccelerationSensor.AccelerationSensors\n")
73 Out.write("import Battery.Battery\n")
74 Out.write("import Battery.Batteries\n")
75 Out.write("import BeaconSensor.BeaconSensor\n")
76 Out.write("import BeaconSensor.BeaconSensors\n")
77 Out.write("import CarbonMonoxideDetector.CarbonMonoxideDetector\n")
78 Out.write("import CarbonMonoxideDetector.CarbonMonoxideDetectors\n")
79 Out.write("import ColorControl.ColorControl\n")
80 Out.write("import ColorControl.ColorControls\n")
81 Out.write("import EnergyMeter.EnergyMeter\n")
82 Out.write("import EnergyMeter.EnergyMeters\n")
83 Out.write("import Event.Event\n")
84 Out.write("import Timer.SimulatedTimer\n")
85 Out.write("\n")
86 Out.write("//Global eventHandler\n")
87 for line in eventHandler:
88         Out.write(line)
89 Out.write("\n")
90 Out.write("//GlobalVariables for both Apps\n")
91 for line in GlobalVariablesBothApps:
92         Out.write(line)
93 Out.write("\n")
94 Out.write("//Application #1\n")
95 Out.write("class App1 {\n")
96 Out.write("\tdef reference\n")
97 Out.write("\tdef location\n")
98 Out.write("\tdef app\n")
99 Out.write("\n")
100 Out.write("\t//Extracted objects for App1\n")
101 for line in extractedObjectsApp1:
102         Out.write("\t"+line)
103 Out.write("\n")
104 Out.write("\t//Extracted objects for functions for App1\n")
105 for line in extractedFunctionsApp1:
106         Out.write("\t"+line)
107 Out.write("\n")
108 Out.write("\tApp1(Object obj) {\n")
109 Out.write("\t\treference = obj\n")
110 Out.write("\t\tlocation = obj.locationObject\n")
111 Out.write("\t\tapp = obj.appObject\n")
112 for line in extractedObjectsConstructorApp1:
113         Out.write("\t\t"+line)
114 Out.write("\t}\n")
115 Out.write("\t//Global variables for each app\n")
116 for line in GlobalVariablesEachApp:
117         Out.write("\t"+line)
118 Out.write("\n")
119 Out.write("\t//Methods\n")
120 for line in setLocationMode:
121         Out.write("\t"+line)
122 for line in subscribe:
123         Out.write("\t"+line)
124 for line in runIn:
125         Out.write("\t"+line)
126 for line in unschedule:
127         Out.write("\t"+line)
128 for line in sendNotificationToContacts:
129         Out.write("\t"+line)
130 for line in sendSms:
131         Out.write("\t"+line)
132 for line in sendPush:
133         Out.write("\t"+line)
134 for line in schedule:
135         Out.write("\t"+line)
136 for line in now:
137         Out.write("\t"+line)
138 for line in getTemperatureScale:
139         Out.write("\t"+line)
140 for line in getSunriseAndSunset:
141         Out.write("\t"+line)
142 Out.write("\n")
143 Start = 0
144 for line in App1:
145         if ("def " in line):
146                 Start = 1
147         if (Start):
148                 Out.write("\t"+line)
149 Out.write("}\n")
150 Out.write("\n")
151 Out.write("\n")
152 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
153
154 #For App2
155 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
156 setLocationMode = open("Methods/"+"setLocationMode.groovy", "r")
157 subscribe = open("Methods/"+"subscribe.groovy", "r")
158 runIn = open("Methods/"+"runIn.groovy", "r")
159 unschedule = open("Methods/"+"unschedule.groovy", "r")
160 sendNotificationToContacts = open("Methods/"+"sendNotificationToContacts.groovy", "r")
161 sendSms = open("Methods/"+"sendSms.groovy", "r")
162 eventHandler = open("Methods/"+"eventHandler.groovy", "r")
163 schedule = open("Methods/"+"schedule.groovy", "r")
164 now = open("Methods/"+"now.groovy", "r")
165 getTemperatureScale = open("Methods/"+"getTemperatureScale.groovy", "r")
166 getSunriseAndSunset = open("Methods/"+"getSunriseAndSunset.groovy", "r")
167 App2 = open("Extractor/"+"App2/App2.groovy", "r")
168 extractedObjectsApp2 = open("Extractor/"+"App2/extractedObjectsApp2.groovy", "r")
169 extractedObjectsConstructorApp2 = open("Extractor/"+"App2/extractedObjectsConstructorApp2.groovy", "r")
170 extractedFunctionsApp2 = open("Extractor/"+"App2/extractedFunctionsApp2.groovy", "r")
171
172 Out.write("//Application #2\n")
173 Out.write("class App2 {\n")
174 Out.write("\tdef reference\n")
175 Out.write("\tdef location\n")
176 Out.write("\tdef app\n")
177 Out.write("\n")
178 Out.write("\t//Extracted objects for App2\n")
179 for line in extractedObjectsApp2:
180         Out.write("\t"+line)
181 Out.write("\n")
182 Out.write("\t//Extracted objects for functions for App2\n")
183 for line in extractedFunctionsApp2:
184         Out.write("\t"+line)
185 Out.write("\n")
186 Out.write("\tApp2(Object obj) {\n")
187 Out.write("\t\treference = obj\n")
188 Out.write("\t\tlocation = obj.locationObject\n")
189 Out.write("\t\tapp = obj.appObject\n")
190 for line in extractedObjectsConstructorApp2:
191         Out.write("\t\t"+line)
192 Out.write("\t}\n")
193 Out.write("\t//Global variables for each app\n")
194 for line in GlobalVariablesEachApp:
195         Out.write("\t"+line)
196 Out.write("\n")
197 Out.write("\t//Methods\n")
198 for line in setLocationMode:
199         Out.write("\t"+line)
200 for line in subscribe:
201         Out.write("\t"+line)
202 for line in runIn:
203         Out.write("\t"+line)
204 for line in unschedule:
205         Out.write("\t"+line)
206 for line in sendNotificationToContacts:
207         Out.write("\t"+line)
208 for line in sendSms:
209         Out.write("\t"+line)
210 for line in sendPush:
211         Out.write("\t"+line)
212 for line in schedule:
213         Out.write("\t"+line)
214 for line in now:
215         Out.write("\t"+line)
216 for line in getTemperatureScale:
217         Out.write("\t"+line)
218 for line in getSunriseAndSunset:
219         Out.write("\t"+line)
220 Out.write("\n")
221 Start = 0
222 for line in App2:
223         if ("def " in line):
224                 Start = 1
225         if (Start):
226                 Out.write("\t"+line)
227 Out.write("}\n")
228 Out.write("\n")
229 Out.write("@Field def app1 = new App1(this)\n")
230 Out.write("@Field def app2 = new App2(this)\n")
231 Out.write("app1.installed()\n")
232 Out.write("app2.installed()\n")
233 Out.write("\n")
234 for line in eventSimulator:
235         Out.write(line)
236 Out.close()
237
238
239
240