Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[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 outGlobal = open("Extractor/"+"outGlobal.groovy", "r")
12 eventSimulator = open("eventSimulator/"+"eventSimulator.groovy", "r")
13
14 #For App1
15 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
16 setLocationMode = open("Methods/"+"setLocationMode.groovy", "r")
17 subscribe = open("Methods/"+"subscribe.groovy", "r")
18 runIn = open("Methods/"+"runIn.groovy", "r")
19 unschedule = open("Methods/"+"unschedule.groovy", "r")
20 sendNotificationToContacts = open("Methods/"+"sendNotificationToContacts.groovy", "r")
21 sendSms = open("Methods/"+"sendSms.groovy", "r")
22 sendPush = open("Methods/"+"sendPush.groovy", "r")
23 eventHandler = open("Methods/"+"eventHandler.groovy", "r")
24 schedule = open("Methods/"+"schedule.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.Contacting\n")
39 Out.write("import ContactSensor.Contacts\n")
40 Out.write("import Lock.Locking\n")
41 Out.write("import Lock.Locks\n")
42 Out.write("import Switch.Switching\n")
43 Out.write("import Switch.Switches\n")
44 Out.write("import Logger.Logger\n")
45 Out.write("import Location.LocationVar\n")
46 Out.write("import Location.Phrase\n")
47 Out.write("import appTouch.Touched\n")
48 Out.write("import Event.Event\n")
49 Out.write("import Timer.SimulatedTimer\n")
50 Out.write("\n")
51 Out.write("//Global eventHandler\n")
52 for line in eventHandler:
53         Out.write(line)
54 Out.write("\n")
55 Out.write("//GlobalVariables for both Apps\n")
56 for line in GlobalVariablesBothApps:
57         Out.write(line)
58 Out.write("\n")
59 Out.write("//Extracted global objects for both Apps\n")
60 for line in outGlobal:
61         Out.write(line)
62 Out.write("\n")
63 Out.write("//Application #1\n")
64 Out.write("class App1 {\n")
65 Out.write("\tdef reference\n")
66 Out.write("\tdef location\n")
67 Out.write("\tdef app\n")
68 Out.write("\n")
69 Out.write("\t//Extracted objects for App1\n")
70 for line in extractedObjectsApp1:
71         Out.write("\t"+line)
72 Out.write("\n")
73 Out.write("\t//Extracted objects for functions for App1\n")
74 for line in extractedFunctionsApp1:
75         Out.write("\t"+line)
76 Out.write("\n")
77 Out.write("\tApp1(Object obj) {\n")
78 Out.write("\t\treference = obj\n")
79 Out.write("\t\tlocation = obj.locationObject\n")
80 Out.write("\t\tapp = obj.appObject\n")
81 for line in extractedObjectsConstructorApp1:
82         Out.write("\t\t"+line)
83 Out.write("\t}\n")
84 Out.write("\t//Global variables for each app\n")
85 for line in GlobalVariablesEachApp:
86         Out.write("\t"+line)
87 Out.write("\n")
88 Out.write("\t//Methods\n")
89 for line in setLocationMode:
90         Out.write("\t"+line)
91 for line in subscribe:
92         Out.write("\t"+line)
93 for line in runIn:
94         Out.write("\t"+line)
95 for line in unschedule:
96         Out.write("\t"+line)
97 for line in sendNotificationToContacts:
98         Out.write("\t"+line)
99 for line in sendSms:
100         Out.write("\t"+line)
101 for line in sendPush:
102         Out.write("\t"+line)
103 for line in schedule:
104         Out.write("\t"+line)
105 Out.write("\n")
106 Start = 0
107 for line in App1:
108         if ("def " in line):
109                 Start = 1
110         if (Start):
111                 Out.write("\t"+line)
112 Out.write("}\n")
113 Out.write("\n")
114 Out.write("\n")
115 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
116
117 #For App2
118 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
119 setLocationMode = open("Methods/"+"setLocationMode.groovy", "r")
120 subscribe = open("Methods/"+"subscribe.groovy", "r")
121 runIn = open("Methods/"+"runIn.groovy", "r")
122 unschedule = open("Methods/"+"unschedule.groovy", "r")
123 sendNotificationToContacts = open("Methods/"+"sendNotificationToContacts.groovy", "r")
124 sendSms = open("Methods/"+"sendSms.groovy", "r")
125 eventHandler = open("Methods/"+"eventHandler.groovy", "r")
126 schedule = open("Methods/"+"schedule.groovy", "r")
127 App2 = open("Extractor/"+"App2/App2.groovy", "r")
128 extractedObjectsApp2 = open("Extractor/"+"App2/extractedObjectsApp2.groovy", "r")
129 extractedObjectsConstructorApp2 = open("Extractor/"+"App2/extractedObjectsConstructorApp2.groovy", "r")
130 extractedFunctionsApp2 = open("Extractor/"+"App2/extractedFunctionsApp2.groovy", "r")
131
132 Out.write("//Application #2\n")
133 Out.write("class App2 {\n")
134 Out.write("\tdef reference\n")
135 Out.write("\tdef location\n")
136 Out.write("\tdef app\n")
137 Out.write("\n")
138 Out.write("\t//Extracted objects for App2\n")
139 for line in extractedObjectsApp2:
140         Out.write("\t"+line)
141 Out.write("\n")
142 Out.write("\t//Extracted objects for functions for App2\n")
143 for line in extractedFunctionsApp2:
144         Out.write("\t"+line)
145 Out.write("\n")
146 Out.write("\tApp2(Object obj) {\n")
147 Out.write("\t\treference = obj\n")
148 Out.write("\t\tlocation = obj.locationObject\n")
149 Out.write("\t\tapp = obj.appObject\n")
150 for line in extractedObjectsConstructorApp2:
151         Out.write("\t\t"+line)
152 Out.write("\t}\n")
153 Out.write("\t//Global variables for each app\n")
154 for line in GlobalVariablesEachApp:
155         Out.write("\t"+line)
156 Out.write("\n")
157 Out.write("\t//Methods\n")
158 for line in setLocationMode:
159         Out.write("\t"+line)
160 for line in subscribe:
161         Out.write("\t"+line)
162 for line in runIn:
163         Out.write("\t"+line)
164 for line in unschedule:
165         Out.write("\t"+line)
166 for line in sendNotificationToContacts:
167         Out.write("\t"+line)
168 for line in sendSms:
169         Out.write("\t"+line)
170 for line in sendPush:
171         Out.write("\t"+line)
172 for line in schedule:
173         Out.write("\t"+line)
174 Out.write("\n")
175 Start = 0
176 for line in App2:
177         if ("def " in line):
178                 Start = 1
179         if (Start):
180                 Out.write("\t"+line)
181 Out.write("}\n")
182 Out.write("\n")
183 Out.write("@Field def app1 = new App1(this)\n")
184 Out.write("@Field def app2 = new App2(this)\n")
185 Out.write("app1.installed()\n")
186 Out.write("app2.installed()\n")
187 Out.write("\n")
188 for line in eventSimulator:
189         Out.write("\t"+line)
190 Out.close()
191
192
193
194