def __init__(self, template): logger.debug("Instantiating TemplateFiller for template '" + template.name + "'") source = TemplateInliner(template).inline() self.template = template.environment.from_string(source) ast = self.template.environment.parse(source) self.prompt_visitor = PromptVisitor(ast)
def _render_arg(self, arg, context): error_msg = ( "Filters at the moment only support collections,contants, variables and _keynames. " + "But you passed something else, maybe a function? ") logger.debug("Render argument '" + str(arg) + "' within filter " + self.filter.name) if isinstance(arg, List): result = self._render_list(arg, context) elif isinstance(arg, Name): # import pdb;pdb.set_trace() result = context.resolve(arg.name) elif isinstance(arg, Const): result = arg.value elif isinstance(arg, Getitem): dict = self._render_arg(arg.node, context) key = self._render_arg(arg.arg, context) result = dict[key] elif isinstance(arg, Getattr): value = context.resolve(arg.node.name) result = value.__getattr__(arg.attr) else: print(str(arg)) raise ValueError(error_msg + "\n" + str(arg)) logger.debug("Argument resolved to: " + str(result)) return result
def apply(self, prompt, context): app = AppProject(env_vars=os.environ) logger.debug("Applying CodePath filter to project :" + app.emproject.root) project_modules = app.emproject.paths["repo_modules"].path product_modules = app.product_layout()["repo_modules"].path get_paths_func = lambda: [project_modules, product_modules] prompt.completer = PathCompleter(get_paths=get_paths_func)
def build_context(self, template, template_values): prompt = self.next_prompt(template_values) logger.debug( "About to build context starting with initial context:\n" + str(template_values)) while prompt: prompt.populate_value(template_values) prompt = self.next_prompt(template_values) return template_values
def __init__(self, ast): logger.debug("Instantiating Prompt visitor") self.ast = ast self._set_parent(self.ast, None) # need to track visited names when the user enter blank # then the variable should not added to the values and # neither should be prompted again self.names_visited = [] logger.debug("Finish Prompt visitor instantion")
def next_prompt(self, eval_context): logger.debug("Starting next prompt") prompt = self.visit(self.ast, eval_context) logger.debug("Prompt returned: " + str(prompt)) if prompt: logger.debug("Resolving prompt") prompt.resolve(eval_context) logger.debug("Returning prompt") return prompt
def _ccadmin_file_ext(self): logger.debug("Checking OS name: " + os.name) if os.name == "nt": return "bat" else: return "sh"
def _ccadmin_file(self): ccadmin_file_name = "ccadmin." + self._ccadmin_file_ext() ccadmin_path = os.path.join(self.root, ccadmin_file_name) logger.debug("ccadmin found under: " + ccadmin_path) return ccadmin_path
def _render_template(self, context): logger.debug("Start rendering template to resolve arguments") rendered_text = concat(self.template.root_render_func(context)) logger.debug("End rendering")