def list_verbose(self): """list available templates and their help text """ textwrapper = TextWrapper( initial_indent=" ", subsequent_indent=" ") cats = list_sorted_templates(scope=self.allowed_packages) if cats: for title, items in cats.items(): print "\n"+ title print "-" * len(title) # Hard-coded for now, since 'add' is the only one if title == 'Local Commands': print '\nadd: Allows the addition of further templates'\ ' from the following list' print ' to an existing package\n' print '\nLocal Templates' print '-----------------' for temp in items: print "\n%s: %s\n" % (temp['name'], temp['summary']) if temp['help']: wrap_help_paras(textwrapper, temp['help']) print else: print self.texts['not_here_warning'] return 0
def list_verbose(): """List templates verbosely, with full help.""" textwrapper = TextWrapper( initial_indent=" ", subsequent_indent=" ") cats = list_sorted_templates() for title, items in cats.items(): print "\n"+ title print "-" * len(title) for temp in items: print "\n%s: %s\n" % (temp['name'], temp['summary']) if temp['help']: wrap_help_paras(textwrapper, temp['help']) print
def list_verbose(self): """list available templates and their help text method must exit by raising error or calling sys.exit """ textwrapper = TextWrapper(initial_indent=" ", subsequent_indent=" ") cats = list_sorted_templates() for title, items in cats.items(): print "\n" + title print "-" * len(title) for temp in items: print "\n%s: %s\n" % (temp["name"], temp["summary"]) if temp["help"]: wrap_help_paras(textwrapper, temp["help"]) print sys.exit(0)
def list_verbose(self): """list available templates and their help text method must exit by raising error or calling sys.exit """ textwrapper = TextWrapper( initial_indent=" ", subsequent_indent=" ") cats = list_sorted_templates() for title, items in cats.items(): print "\n"+ title print "-" * len(title) for temp in items: print "\n%s: %s\n" % (temp['name'], temp['summary']) if temp['help']: wrap_help_paras(textwrapper, temp['help']) print sys.exit(0)
def check_vars(self, vars, cmd): """ Override of templer.core.base.BaseTemplate.check_vars Add the possibility to specify if a variable will be questioned in the commande prompt or not eg: class MyTemplate(AffiniticTemplate): vars = copy.deepcopy(BasicNamespace.vars) get_var(vars, 'version').questionable = False """ if not hasattr(cmd, '_deleted_once'): del vars['package'] cmd._deleted_once = True # if we need to notify users of anything before they start this # whole process, we can do it here. self.print_zopeskel_message('pre_run_msg') # Copied and modified from PasteScript's check_vars-- # the method there wasn't hookable for the things # we need -- question posing, validation, etc. # # Admittedly, this could be merged into PasteScript, # but it was decided it was easier to limit scope of # these changes to ZopeSkel, as other projects may # use PasteScript in very different ways. cmd._deleted_once = 1 # don't re-del package textwrapper = TextWrapper( initial_indent="| ", subsequent_indent="| ", ) # now, mostly copied direct from paster expect_vars = self.read_vars(cmd) if not expect_vars: # Assume that variables aren't defined return vars converted_vars = {} errors = [] config = get_zopeskel_prefs() # pastescript allows one to request more than one template (multiple # -t options at the command line) so we will get a list of templates # from the cmd's options property requested_templates = cmd.options.templates for var in expect_vars: for template in requested_templates: if config.has_option(template, var.name): var.default = config.get(template, var.name) break else: # Not found in template section, now look explicitly # in DEFAULT section if config.has_option('DEFAULT', var.name): var.default = config.get('DEFAULT', var.name) self.override_package_names_defaults(vars, expect_vars) unused_vars = vars.copy() for var in expect_vars: response = self.null_value_marker if var.name not in unused_vars: if cmd.interactive \ and (not hasattr(var, 'questionable') or var.questionable == True): prompt = var.pretty_description() while response is self.null_value_marker: response = cmd.challenge(prompt, var.default, var.should_echo) if response == '?': help = var.further_help().strip() % converted_vars print wrap_help_paras(textwrapper, help) print response = self.null_value_marker if hasattr(var, 'required') \ and var.required == True \ and response.strip() == '': print print "You must answer to this question!" print response = self.null_value_marker if response is not self.null_value_marker: try: response = var.validate(response) except ValidationException, e: print e response = self.null_value_marker elif var.default is NoDefault: errors.append('Required variable missing: %s' % var.full_description()) else: response = var.validate(var.default) else: response = var.validate(unused_vars.pop(var.name)) converted_vars[var.name] = response # if a variable has structures associated, we will insert them # in the template required_structures property at this time, let's # test first to see if we need to do anything. if var._is_structural: self._set_structure_from_var(var, str(response)) # filter the vars for mode. if var.name == 'expert_mode': expert_mode = converted_vars['expert_mode'] hidden = self._filter_for_modes(expert_mode, expect_vars) unused_vars.update(hidden) self.process_dependents_vars(vars, var, response, expect_vars)