Esempio n. 1
0
File: view.py Progetto: Giotoc/ACR
 def generate(self, acenv):
     D = acenv.doDebug
     if D:
         acenv.start("View.generate of view: %s", self.name)
     try:
         self.inputSchemas
     except:  # inputs is undefined
         acenv.generations.append({"type": "view", "name": self.name})
         self.transform(acenv)
         return
         # if D: acenv.debug("Executing with env=%s",acenv)
     self.fillInputs(acenv)
     self.fillPosts(acenv)
     self.checkConditions(acenv)
     for action in self.actions:
         if acenv.doRedirect:
             break
         if D:
             acenv.info("\033[92mdefining name='%s'\033[0m", action["name"])
         action_type = action["type"]
         path_set = action.has_key("path")
         if D:
             acenv.info("Checking condition")
         if action.has_key("condition") and not action["condition"].execute(acenv):
             if D:
                 acenv.warning("Condition is not meet")
             if action_type in WRITE_COMMANDS:
                 default = action.get("default")
                 if default:
                     if path_set:
                         if action_type == PUSH:
                             pointer = action["path"].execute(acenv)
                             if type(pointer) is not list:
                                 raise Error("NotArrayError", "Path did not return array in %s." % action["name"])
                             pointer.append(default.execute(acenv))
                             continue
                     getStorage(acenv, "rs")[action["name"]] = default.execute(acenv)
                     # else:
                     # 	getStorage(acenv,"rs")[action["name"]]={
                     # 		"status":"error",
                     # 		"error":"ConditionNotMeet",
                     # 		"message":"Condition was not meet."
                     # 	}
             continue
         if D:
             acenv.info("Condition test passed")
         component = self.app.getComponent(action["component"])
         generation = component.generate(acenv, action["config"])
         if action_type == NODE and type(generation) is dict and not generation.has_key("@status"):
             generation["@status"] = "ok"
             # if not generation:
             # 	raise Error("ComponentError","Component did not return proper value. Please contact component author.")
             # if not action["name"]:
             # 		continue
         if path_set:
             pointer = action["path"].execute(acenv)
             if action_type == PUSH:
                 if type(generation) is Tree:
                     generation.node = pointer
                     generation = generation.execute(acenv)
                 if type(pointer) not in iterators:
                     raise Error("NotArrayError", "Path did not return array %s." % action["name"])
                 if D:
                     acenv.info("Appending %s to %s", generation, action["path"])
                 pointer.append(generation)
             elif action["type"] == SET:
                 acenv.debug("Starting SET with path %s", pointer)
                 if type(pointer) not in iterators + [dict]:
                     raise Error(
                         "NotObjectError", "Path did not return object or array of objects in %s." % action["name"]
                     )
                 typePointer = type(pointer)
                 if typePointer is dict and pointer.get("@status") is not "noData":
                     if type(generation) is Tree:
                         # TODO check if it is necessary
                         generation.node = pointer
                         generation = generation.execute(acenv)
                     if D:
                         acenv.info("Setting %s to %s in %s", action["name"], generation, action["path"])
                     pointer[action["name"]] = generation
                 elif typePointer in iterators:
                     for i in pointer:
                         if type(generation) is Tree:
                             if D:
                                 acenv.debug("Setting current to %s", i)
                             generation.node = i
                             g = generation.execute(acenv)
                         else:
                             g = generation
                         if D:
                             acenv.info("Setting %s to %s in %s", action["name"], g, action["path"])
                         i[action["name"]] = g
                         # 	pointer=generation
         else:
             if type(generation) is Tree:
                 generation = generation.execute(acenv)
             if action["type"] == NODE:
                 if D:
                     acenv.info("Adding node %s with: %s", action["name"], generation)
                 # generation.name=action["name"]
                 # generation.view=self.name
                 acenv.generations[action["name"]] = generation
             elif action["type"] == SET:
                 if D:
                     acenv.info("Setting %s with: %s", action["name"], generation)
                 getStorage(acenv, "rs")[action["name"]] = generation
             else:
                 pointer = getStorage(acenv, "rs")
         if action["type"] == UNSET:
             if type(pointer) not in iterators + [dict]:
                 raise Error(
                     "NotObjectError", "Path did not return object or array of objects in %s." % action["name"]
                 )
             if type(pointer) is dict:
                 try:
                     pointer.pop(action["name"])
                 except:
                     pass
             elif type(pointer) in iterators:
                 for i in pointer:
                     i.pop(action["name"])
     if acenv.output:
         acenv.output.update(self.output)
Esempio n. 2
0
						if D: acenv.info("doing standard comparison '%s' is '%s'",fst,snd)
						ret=fst is snd
				if op=="is not":
					if D: acenv.info("'is not' found. Returning %s",not ret)
					return not ret
				else:
					if D: acenv.info("returning '%s' is '%s'='%s'",fst,snd,ret)
					return ret
			elif op=="(literal)":
				fstLetter=node[1][0]
				if fstLetter is "'":
					return node[1][1:-1]
				elif fstLetter.isdigit:
					return int(node[1])
			elif op=="(root)":# this is $
				return getStorage(acenv,node[1])
			elif op=="(node)":# this is !
				if D: acenv.debug("returning node %s",self.node)
				return self.node
			elif op=="(current)":# this is @
				if D: acenv.debug("returning current node %s",self.current)
				return self.current
			elif op=="name":
				return node[1]
			elif op==".":
				fst=node[1]
				if type(fst) is tuple:
					fst=exe(fst)
				typefst=type(fst)
				if D: acenv.debug("left is '%s'",fst)
				if node[2][0]=="*":