class PortalPolicy(PlonePackage): summary = "A policy package following the Simples Consultoria standards" help = "A package that will manage a Plone installation" category = "Simples Consultoria - Plone" _template_dir = "templates/policy" vars = copy.deepcopy(PlonePackage.vars) vars.append( BooleanVar( 'add_profile_init_content', title='Register an Initial Content Profile', description='''Should this package register an Initial Content GS Profile ''', modes=(EXPERT, ), default=True, structures={ 'False': None, 'True': 'gs_nested_init_content' }, ), ) get_var(vars, 'version').default = gen_version() get_var(vars, 'add_profile').structures = { 'False': None, 'True': ['gs_nested_default', 'gs_nested_policy'] }
class NestedNamespace(BasicNamespace): _template_dir = 'templates/nested_namespace' summary = "A basic Python project with a nested namespace (2 dots in name)" ndots = 2 help = """ This creates a Python project without any Zope or Plone features. """ required_templates = [] use_cheetah = True vars = copy.deepcopy(BasicNamespace.vars) get_var(vars, 'namespace_package').default = 'my' vars.insert(2, VAR_NS2) get_var(vars, 'package').default = 'example'
class PloneTheme(PlonePackage): summary = "A theme package following the Simples Consultoria standards" help = "A package that will configure a Plone theme installation" category = "Simples Consultoria - Themes" _template_dir = "templates/plonetheme" vars = copy.deepcopy(PlonePackage.vars) get_var(vars, 'plone_version').modes = (EXPERT, ) get_var(vars, 'keywords').default = 'plone theme simples_consultoria' def check_vars(self, vars, cmd): responses = super(PloneTheme, self).check_vars(vars, cmd) return responses
class DotDotPackage(BasicNamespace): """ This creates a nested namespace Python package with two dots in the name. """ _template_dir = 'templates/dotdotpackage' summary = "A nested namespace Python package (2 dots in name)" help = """ This creates a nested namespace Python package with two dots in the name. """ required_templates = [] use_cheetah = True vars = copy.deepcopy(BasicNamespace.vars) get_var(vars, 'package').default = 'example' def check_vars(self, myvars, cmd): myvars = super(DotDotPackage, self).check_vars(myvars, cmd) add_invisible_vars(myvars) return myvars def pre(self, command, output_dir, vars): if '.' in vars['egg']: # Taken from http://code.google.com/p/wsgitemplates/ namespace = [] for i in range(len(vars['egg'].split('.')) - 1): namespace.append(".".join(vars['egg'].split('.')[0:i + 1])) vars['namespace'] = "\n namespace_packages=%s," % namespace else: vars['namespace'] = "" super(DotDotPackage, self).pre(command, output_dir, vars) def run(self, command, output_dir, vars): templates.Template.run(self, command, output_dir, vars)
class Diazo(PlonePackage): summary = "Create a Diazo theme based on beyondskins.responsive." help = """This template allows you to create a Diazo theme based on beyondskins.responsive""" category = "Simples Consultoria - Themes" _template_dir = "templates/diazo" vars = copy.deepcopy(PlonePackage.vars) get_var(vars, 'plone_version').modes = (EXPERT, ) get_var(vars, 'keywords').default = 'plone theme simples_consultoria' def check_vars(self, vars, cmd): responses = super(Diazo, self).check_vars(vars, cmd) return responses
class PlonePackage(NestedPackage): summary = "A Plone package template for Simples Consultoria's projects" help = """This is a base template for Simples Consultoria's Plone projects that use a nested namespace (two dots in the name). """ category = "Simples Consultoria - Plone" _template_dir = "templates/plone_package" default_required_structures = ['bootstrap', 'egg_docs_ex', 'plone_testing_base', 'plone_package' ] vars = copy.deepcopy(base_vars()) vars.extend(copy.deepcopy(gs_vars)) vars.append( StringVar( 'plone_version', 'Plone version', default='4.1', modes=(EASY, EXPERT), ) ) get_var(vars, 'keywords').default = 'python plone zope simples_consultoria' def add_plone_testing(self, version): ''' Adds the default testing configuration for the package ''' def sanitize(version): version = version[:3].replace('.', '') return version structure = 'plone_testing_%s' % sanitize(version) if self.has_structure(structure): self.required_structures.append(structure) def has_profile(self, resp): ''' Return true if we have any GS profile ''' return (resp.get('add_profile',False) or resp.get('add_profile_uninstall',False) or resp.get('add_profile_init_content',False)) def check_vars(self, vars, cmd): resp = super(PlonePackage, self).check_vars(vars, cmd) self.add_plone_testing(resp['plone_version']) resp['has_profile'] = self.has_profile(resp) resp['add_profile_init_content'] = resp.get('add_profile_init_content', False) return resp
def test_get_vars(self): """ get_vars is not a method of BaseTemplate, but we've got a nice set of variables all set up in here, so let's use it """ var = get_var(self.vars, 'basic_var') self.assertEqual(var.name, 'basic_var') self.assertEqual(var.title, 'Basic Title') self.assertEqual(var.description, 'This is a basic variable') self.assertEqual(var.modes, (EXPERT, EASY)) self.assertEqual(var.default, 'foo')
def process_dependents_vars(self, vars, changed_var, changed_var_value, expect_vars): """ Process some changes on vars that need to know the value of precedent var """ if changed_var.name == 'hoster': if changed_var_value == 'github': host = 'github.com' elif changed_var_value == 'bitbucket': host = 'bitbucket.org' url = 'https://%s/affinitic/%s' % (host, vars['project']) get_var(expect_vars, 'url').default = url
def base_vars(): ''' Base variables for our templates ''' vars = copy.deepcopy(NestedNamespace.vars) get_var(vars, 'author').default = D.get('author') get_var(vars, 'author_email').default = D.get('email') get_var(vars, 'url').default = D.get('url') get_var(vars, 'keywords').default = 'python simples_consultoria' get_var(vars, 'namespace_package').default = 'sc' get_var(vars, 'namespace_package2').default = 'project' get_var(vars, 'package').default = 'package' get_var(vars, 'license_name').default = 'GPL' return vars
class Dexterity(Plone): _template_dir = 'templates/dexterity' summary = 'A Plone project that uses Dexterity content types' help = HELP_TEXT post_run_msg = POST_RUN_TEXT required_templates = ['plone_basic'] default_required_structures = [ 'egg_docs', 'bootstrap', ] category = "Plone Development" use_cheetah = True use_local_commands = SUPPORTS_LOCAL_COMMANDS vars = copy.deepcopy(Plone.vars) vars.insert( 1, StringVar( 'title', title='Project Title', description='Title of the project', modes=(EASY, EXPERT), default='Example Name', help=""" This becomes the title of the project. It is used in the GenericSetup registration for the project and, as such, appears in Plone's Add/Remove products form. """, )) #add_profile should always default to True for dexterity packages get_var(vars, 'add_profile').default = True #add_profile need not appear as a question for dexterity packages get_var(vars, 'add_profile').modes = (EXPERT, ) def pre(self, command, output_dir, vars): super(Dexterity, self).pre(command, output_dir, vars) vars['use_localcommands'] = self.use_local_commands
def __init__(self, *args, **kw): super(AffiniticBaseTemplate, self).__init__(*args, **kw) # Add new var self.vars.insert(3, StringChoiceVar( 'hoster', title='Web hosting service', description='If public, choose github. If private, choose bitbucket (github/bitbucket)', default='github', choices=('github', 'bitbucket'), )) # Change existing vars get_var(self.vars, 'version').default = '0.1' get_var(self.vars, 'version').questionable = False get_var(self.vars, 'author').default = 'Affinitic' get_var(self.vars, 'author').questionable = False get_var(self.vars, 'author_email').default = '*****@*****.**' get_var(self.vars, 'author_email').questionable = False get_var(self.vars, 'description').required = True get_var(self.vars, 'long_description').questionable = False get_var(self.vars, 'keywords').default = 'Affinitic' get_var(self.vars, 'keywords').questionable = False get_var(self.vars, 'license_name').questionable = False get_var(self.vars, 'zip_safe').questionable = False get_var(self.vars, 'url').default = 'https://github.com/affinitic/' # Remove unwanted vars for var in self.vars[:]: if var.name == 'expert_mode': self.vars.remove(var)