+import os
readyToReturn = 0
ToReturn = ""
def GetToken(f):
global readyToReturn
global ToReturn
- Skip = ["(", "\"", ":", ",", "{", "}", ")", '\n', '\t', ' ', "/"]
+ Skip = ['\n', '\t', ' ']
+ Special = ["(", "\"", ":", ",", "{", "}", ")", "/", "*"]
S = ""
if (readyToReturn):
readyToReturn = 0
ToReturn = ""
c = f.read(1)
while(True):
- if (c in Skip):
+ if (c in Special):
if (S != ""):
- if (c == "{" or c == "}"):
- readyToReturn = 1
- ToReturn = c
- return S
- else:
- return S
-
+ readyToReturn = 1
+ ToReturn = c
+ return S
else:
- if (c == "{" or c == "}"):
- return c
- else:
- c = f.read(1)
- continue
+ return c
+ elif (c in Skip):
+ if (S != ""):
+ return S
+ else:
+ c = f.read(1)
+ continue
S += c
c = f.read(1)
if not c:
return "EOF"
-
-
-
-
-
-F = open("Extractor/App.groovy", "r")
-Out = open("Extractor/ExtractedObjects.groovy", "w+")
-Temp = GetToken(F)
-Objects = []
-Functions = []
-
-
-while (Temp != "EOF"):
- #Extract the global objects for input
- if (Temp == "input"):
- Object = ""
- Type = ""
- Temp = GetToken(F) #name or "name"
- #input name: "name", type: "type",...
- if (Temp == "name"):
- Temp = GetToken(F) #"name"
- Object = Temp
- GetToken(F) #type
- Temp = GetToken(F) #"type"
- Type = Temp
- #input "name", "type",...
- else:
- Object = Temp
- Temp = GetToken(F) #"type"
- Type = Temp
+def ExtractFunctions(F, appName):
+ Temp = GetToken(F)
+ while (Temp != "EOF"):
+ if (Temp == "def" or Temp == "private"):
+ Temp = GetToken(F)
+ NameofFunc = Temp
+ if (GetToken(F) != "="): #We have a function to create object for
+ if (appName == "App1"):
+ extractedFunctionsApp1.write("//Global Object for functions in subscribe method!\n")
+ extractedFunctionsApp1.write("def %s = this.&" % NameofFunc)
+ extractedFunctionsApp1.write("%s\n" % NameofFunc)
+ else:
+ extractedFunctionsApp2.write("//Global Object for functions in subscribe method!\n")
+ extractedFunctionsApp2.write("def %s = this.&" % NameofFunc)
+ extractedFunctionsApp2.write("%s\n" % NameofFunc)
Temp = GetToken(F)
- Title = ""
- Required = ""
- Multiple = ""
- while (Temp != "input" and Temp != "}"):
- if (Temp == "title"):
- Temp = GetToken(F)
- Title = Temp
- elif (Temp == "required"):
- Temp = GetToken(F)
- Required = Temp
- elif (Temp == "multiple"):
- Temp = GetToken(F)
- Multiple = Temp
- Temp = GetToken(F)
- if (Type == "capability.lock"):
- if (Title != ""):
- print(Object+", "+Title)
- if (Multiple != "" and Multiple == "true"):
- g = raw_input("Enter the number of locks to control: (1, 2, or 3)\n")
- Out.write("//Global Object for class lock!\n")
- Out.write("@Field def %s = new locking(" % Object)
- Out.write("%s)\n" % g)
- elif (Multiple == "" or Multiple == "false"):
- Out.write("//Global Object for class lock!\n")
- Out.write("@Field def %s = new locking(1)\n" % Object)
- #elif (Type == "capability.alarm"):
-
- #elif (Type == "capability.battery"):
-
- #elif (Type == "capability.beacon"):
-
- #elif (Type == "capability.carbonMonoxideDetector"):
-
- #elif (Type == "capability.colorControl"):
-
- elif (Type == "capability.contactSensor"):
- if (Title != ""):
- print(Object+", "+Title)
- if (Multiple != "" and Multiple == "true"):
- g = raw_input("Enter the number of contactSensors to monitor: (1, 2, or 3)\n")
- Out.write("//Global Object for class contactSensor!\n")
- Out.write("@Field def %s = new contacting(" % Object)
- Out.write("%s)\n" % g)
- elif (Multiple == "" or Multiple == "false"):
- Out.write("//Global Object for class contactSensor!\n")
- Out.write("@Field def %s = new contacting(1)\n" % Object)
- #elif (Type == "capability.doorControl"):
-
- #elif (Type == "capability.energyMeter"):
-
- #elif (Type == "capability.illuminanceMeasurement"):
-
- #elif (Type == "capability.accelerationSensor"):
-
- #elif (Type == "capability.motionSensor"):
-
- #elif (Type == "capability.musicPlayer"):
-
- #elif (Type == "capability.powerMeter"):
-
- #elif (Type == "capability.presenceSensor"):
-
- #elif (Type == "capability.relativeHumidityMeasurement"):
-
- #elif (Type == "capability.relaySwitch"):
-
- #elif (Type == "capability.sleepSensor"):
-
- #elif (Type == "capability.smokeDetector"):
-
- #elif (Type == "capability.stepSensor"):
-
- elif (Type == "capability.switch"):
- if (Title != ""):
- print(Object+", "+Title)
- if (Multiple != "" and Multiple == "true"):
- g = raw_input("Enter the number of switches to control: (1, 2, or 3)\n")
- Out.write("//Global Object for class switch!\n")
- Out.write("@Field def %s = new switching(" % Object)
- Out.write("%s)\n" % g)
- elif (Multiple == "" or Multiple == "false"):
- Out.write("//Global Object for class switch!\n")
- Out.write("@Field def %s = new switching(1)\n" % Object)
- #elif (Type == "capability.switchLevel"):
-
- #elif (Type == "capability.temperatureMeasurement"):
- #elif (Type == "capability.thermostat"):
-
- #elif (Type == "capability.valve"):
-
- #elif (Type == "capability.waterSensor"):
-
- #elif (Type == "capability.touchSensor"):
-
- #elif (Type == "capability.imageCapture"):
-
- #elif (Type == "device.mobilePresence"):
- #elif (Type == "device.aeonKeyFob"):
- elif (Type == "mode"):
- if (Title != ""):
- print(Object+", "+Title)
- g = raw_input("Enter the mode: ")
- Out.write("//Global variable for mode!\n")
- Out.write("@Field def %s = " % Object)
- Out.write("\"%s\"\n" % g)
- #elif (Type == "decimal"):
+#Extract objects to call functions from App1
+F1 = open("Extractor/App1/App1.groovy", "r")
+extractedFunctionsApp1 = open("Extractor/App1/extractedFunctionsApp1.groovy", "w+")
+ExtractFunctions(F1, "App1")
+F1.close()
+
+#Extract objects to call functions from App2
+F2 = open("Extractor/App2/App2.groovy", "r")
+extractedFunctionsApp2 = open("Extractor/App2/extractedFunctionsApp2.groovy", "w+")
+ExtractFunctions(F2, "App2")
+F2.close()
+
+
+#Save the extracted methods and app1 in a same file to extract information
+extractorFile = open("Extractor/extractorFile.groovy", "w+")
+Extractor = open("Extractor/Extractor.groovy", "r")
+F1 = open("Extractor/App1/App1.groovy", "r")
+
+extractorFile.write("////////////////////\n")
+extractorFile.write("@Field App\n")
+extractorFile.write("App = \"App1\"")
+extractorFile.write("\n")
+for line in Extractor:
+ extractorFile.write(line)
+extractorFile.write("\n\n")
+for line in F1:
+ extractorFile.write(line)
+extractorFile.close()
+Extractor.close()
+F1.close()
+#Run the file to extract the objects
+os.system("groovy Extractor/extractorFile.groovy")
+
+
+#Save the extracted methods and app2 in a same file to extract information
+extractorFile = open("Extractor/extractorFile.groovy", "w+")
+Extractor = open("Extractor/Extractor.groovy", "r")
+F2 = open("Extractor/App2/App2.groovy", "r")
+
+extractorFile.write("////////////////////\n")
+extractorFile.write("@Field App\n")
+extractorFile.write("App = \"App2\"")
+extractorFile.write("\n")
+for line in Extractor:
+ extractorFile.write(line)
+extractorFile.write("\n\n")
+for line in F2:
+ extractorFile.write(line)
+#Run the file to extract the objects
+extractorFile.close()
+Extractor.close()
+F2.close()
+os.system("groovy Extractor/extractorFile.groovy")
- #elif (Type == "text"):
-
- elif (Type == "number"):
- if (Title != ""):
- print(Object+", "+Title)
- g = raw_input("Enter the number: ")
- Out.write("//Global variable for number!\n")
- Out.write("@Field def %s = " % Object)
- Out.write("%s\n" % g)
- #elif (Type == "time"):
- #elif (Type == "enum"):
-
- #elif (Type == "bool"):
-
- elif (Type == "phone"):
- if (Title != ""):
- print(Object+", "+Title)
- g = raw_input("Enter the number to send notification to:\n")
- Out.write("//Global variable for phone number!\n")
- Out.write("@Field def %s = " % Object)
- Out.write("%s\n" % g)
- elif (Type == "contact"):
- if (Title != ""):
- print(Object+", "+Title)
- g = raw_input("Enter the name of the recipients:\n")
- Out.write("//Global variable for recipients!\n")
- g = g.split()
- Out.write("@Field def %s = " % Object)
- Out.write("%s\n" % g)
- #Extract the global object for functions
- elif (Temp == "def"):
- Temp = GetToken(F)
- NameofFunc = Temp
- if (GetToken(F) != "="): #We have a function to create object for
- Out.write("//Global Object for functions in subscribe method!\n")
- Out.write("@Field def %s = this.&" % NameofFunc)
- Out.write("%s\n" % NameofFunc)
- if (Temp != "input"):
- Temp = GetToken(F)
-F.close()
-Out.close()