Commit #9: update to previous commit
[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 App1 = open("Extractor/"+"App1/App1.groovy", "r")
25 extractedObjectsApp1 = open("Extractor/"+"App1/extractedObjectsApp1.groovy", "r")
26 extractedObjectsConstructorApp1 = open("Extractor/"+"App1/extractedObjectsConstructorApp1.groovy", "r")
27 extractedFunctionsApp1 = open("Extractor/"+"App1/extractedFunctionsApp1.groovy", "r")
28
29
30
31
32 Out.write("//Infrastructure for SmartThings Application\n")
33 Out.write("//Importing Libraries\n")
34 Out.write("import groovy.transform.Field\n")
35 Out.write("\n")
36 Out.write("//Importing Classes\n")
37 Out.write("import ContactSensor.ContactSensor\n")
38 Out.write("import ContactSensor.ContactSensors\n")
39 Out.write("import DoorControl.DoorControl\n")
40 Out.write("import DoorControl.DoorControls\n")
41 Out.write("import Lock.Lock\n")
42 Out.write("import Lock.Locks\n")
43 Out.write("import Thermostat.Thermostat\n")
44 Out.write("import Thermostat.Thermostats\n")
45 Out.write("import Switch.Switch\n")
46 Out.write("import Switch.Switches\n")
47 Out.write("import PresenceSensor.PresenceSensor\n")
48 Out.write("import PresenceSensor.PresenceSensors\n")
49 Out.write("import Logger.Logger\n")
50 Out.write("import Location.LocationVar\n")
51 Out.write("import Location.Phrase\n")
52 Out.write("import appTouch.Touched\n")
53 Out.write("import NfcTouch.NfcTouch\n")
54 Out.write("import Event.Event\n")
55 Out.write("import Timer.SimulatedTimer\n")
56 Out.write("\n")
57 Out.write("//Global eventHandler\n")
58 for line in eventHandler:
59         Out.write(line)
60 Out.write("\n")
61 Out.write("//GlobalVariables for both Apps\n")
62 for line in GlobalVariablesBothApps:
63         Out.write(line)
64 Out.write("\n")
65 Out.write("//Application #1\n")
66 Out.write("class App1 {\n")
67 Out.write("\tdef reference\n")
68 Out.write("\tdef location\n")
69 Out.write("\tdef app\n")
70 Out.write("\n")
71 Out.write("\t//Extracted objects for App1\n")
72 for line in extractedObjectsApp1:
73         Out.write("\t"+line)
74 Out.write("\n")
75 Out.write("\t//Extracted objects for functions for App1\n")
76 for line in extractedFunctionsApp1:
77         Out.write("\t"+line)
78 Out.write("\n")
79 Out.write("\tApp1(Object obj) {\n")
80 Out.write("\t\treference = obj\n")
81 Out.write("\t\tlocation = obj.locationObject\n")
82 Out.write("\t\tapp = obj.appObject\n")
83 for line in extractedObjectsConstructorApp1:
84         Out.write("\t\t"+line)
85 Out.write("\t}\n")
86 Out.write("\t//Global variables for each app\n")
87 for line in GlobalVariablesEachApp:
88         Out.write("\t"+line)
89 Out.write("\n")
90 Out.write("\t//Methods\n")
91 for line in setLocationMode:
92         Out.write("\t"+line)
93 for line in subscribe:
94         Out.write("\t"+line)
95 for line in runIn:
96         Out.write("\t"+line)
97 for line in unschedule:
98         Out.write("\t"+line)
99 for line in sendNotificationToContacts:
100         Out.write("\t"+line)
101 for line in sendSms:
102         Out.write("\t"+line)
103 for line in sendPush:
104         Out.write("\t"+line)
105 for line in schedule:
106         Out.write("\t"+line)
107 Out.write("\n")
108 Start = 0
109 for line in App1:
110         if ("def " in line):
111                 Start = 1
112         if (Start):
113                 Out.write("\t"+line)
114 Out.write("}\n")
115 Out.write("\n")
116 Out.write("\n")
117 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
118
119 #For App2
120 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
121 setLocationMode = open("Methods/"+"setLocationMode.groovy", "r")
122 subscribe = open("Methods/"+"subscribe.groovy", "r")
123 runIn = open("Methods/"+"runIn.groovy", "r")
124 unschedule = open("Methods/"+"unschedule.groovy", "r")
125 sendNotificationToContacts = open("Methods/"+"sendNotificationToContacts.groovy", "r")
126 sendSms = open("Methods/"+"sendSms.groovy", "r")
127 eventHandler = open("Methods/"+"eventHandler.groovy", "r")
128 schedule = open("Methods/"+"schedule.groovy", "r")
129 App2 = open("Extractor/"+"App2/App2.groovy", "r")
130 extractedObjectsApp2 = open("Extractor/"+"App2/extractedObjectsApp2.groovy", "r")
131 extractedObjectsConstructorApp2 = open("Extractor/"+"App2/extractedObjectsConstructorApp2.groovy", "r")
132 extractedFunctionsApp2 = open("Extractor/"+"App2/extractedFunctionsApp2.groovy", "r")
133
134 Out.write("//Application #2\n")
135 Out.write("class App2 {\n")
136 Out.write("\tdef reference\n")
137 Out.write("\tdef location\n")
138 Out.write("\tdef app\n")
139 Out.write("\n")
140 Out.write("\t//Extracted objects for App2\n")
141 for line in extractedObjectsApp2:
142         Out.write("\t"+line)
143 Out.write("\n")
144 Out.write("\t//Extracted objects for functions for App2\n")
145 for line in extractedFunctionsApp2:
146         Out.write("\t"+line)
147 Out.write("\n")
148 Out.write("\tApp2(Object obj) {\n")
149 Out.write("\t\treference = obj\n")
150 Out.write("\t\tlocation = obj.locationObject\n")
151 Out.write("\t\tapp = obj.appObject\n")
152 for line in extractedObjectsConstructorApp2:
153         Out.write("\t\t"+line)
154 Out.write("\t}\n")
155 Out.write("\t//Global variables for each app\n")
156 for line in GlobalVariablesEachApp:
157         Out.write("\t"+line)
158 Out.write("\n")
159 Out.write("\t//Methods\n")
160 for line in setLocationMode:
161         Out.write("\t"+line)
162 for line in subscribe:
163         Out.write("\t"+line)
164 for line in runIn:
165         Out.write("\t"+line)
166 for line in unschedule:
167         Out.write("\t"+line)
168 for line in sendNotificationToContacts:
169         Out.write("\t"+line)
170 for line in sendSms:
171         Out.write("\t"+line)
172 for line in sendPush:
173         Out.write("\t"+line)
174 for line in schedule:
175         Out.write("\t"+line)
176 Out.write("\n")
177 Start = 0
178 for line in App2:
179         if ("def " in line):
180                 Start = 1
181         if (Start):
182                 Out.write("\t"+line)
183 Out.write("}\n")
184 Out.write("\n")
185 Out.write("@Field def app1 = new App1(this)\n")
186 Out.write("@Field def app2 = new App2(this)\n")
187 Out.write("app1.installed()\n")
188 Out.write("app2.installed()\n")
189 Out.write("\n")
190 for line in eventSimulator:
191         Out.write(line)
192 Out.close()
193
194
195
196