class test_StringVar(unittest.TestCase): """ verify functionality of the StringVar variable class """ def setUp(self): self.svar = StringVar('name', 'description') def testValidation(self): """ check to see that validation returns appropriate values: string should have no spaces at front or back unicode strings and regular strings should pass through unchanged non-string values raise validation errors """ val = 'george' self.assertEqual(val, self.svar.validate(val)) val = u'george' self.assertEqual(val, self.svar.validate(val)) val = ' hello ' validated = self.svar.validate(val) self.assertNotEqual(validated[0], ' ') self.assertNotEqual(validated[-1], ' ') self.failUnless(validated in val) for val in (0, True): self.assertRaises(ValidationException, self.svar.validate, val)
class EEA(BasicZope): """ EEA ZopeSkel templates """ _template_dir = 'templates/eea' summary = "EEA-based package" help = "" category = "EEA" required_templates = [] use_local_commands = True use_cheetah = True variables = copy.deepcopy(BasicZope.vars) variables.insert( 1, StringVar('title', title='Project Title', description='Title of the project', modes=(EASY, EXPERT), default='EEA Dummy Package', 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. """)) variables.insert( 2, StringVar('ctype', title='Archetypes Content-Type', description='Archetypes Content-Type Class', modes=(EASY, EXPERT), default='DummyDocument', help="This creates an archetypes content-type.")) variables.insert( 3, StringVar( 'folderish', title='Is folderish', description='Is this content-type folderish?', modes=(EASY, EXPERT), default='True', help="This creates an archetypes content-type folderish or not")) get_var(variables, 'namespace_package').default = 'eea' get_var(variables, 'package').default = 'example' get_var(variables, 'description').default = 'EEA Package' get_var(variables, 'license_name').default = 'GPL version 2' get_var(variables, 'author').default = 'European Environment Agency' get_var(variables, 'author_email').default = '*****@*****.**' get_var(variables, 'keywords').default = 'eea zope plone python' get_var(variables, 'url').default = 'https://eea.github.io' def pre(self, command, output_dir, variables): """ Pre """ variables['ctype'] = variables['ctype'].title().replace(" ", "") variables['ctype_module'] = variables['ctype'].lower()
class CSDjangoProject(BaseTemplate): _template_dir = 'templates/cs_django_project' summary = 'A basic Django Project' use_cheetah = True vars = copy.deepcopy(BaseTemplate.vars) vars += [ StringVar('package', 'Enter the package name (no spaces, no dashes, no dots'), StringVar('version', 'Version (like 0.1)'), StringVar('description', 'One-line description of the package'), StringVar('keywords', 'Space-separated keywords/tags'), StringVar('author', 'Author name'), StringVar('author_email', 'Author email'), StringVar('url', 'URL of homepage'), StringVar('license_name', 'License name'), StringVar( 'zip_safe', 'True/False: if the package can be distributed as a .zip file', default=False), ] get_var(vars, 'version').default = '1.0' get_var(vars, 'version').modes = () get_var(vars, 'description').default = 'Django project. ' get_var(vars, 'description').modes = () get_var(vars, 'keywords').default = 'django' get_var(vars, 'keywords').modes = () get_var(vars, 'author').default = '' get_var(vars, 'author').modes = () get_var(vars, 'author_email').default = '' get_var(vars, 'author_email').modes = () get_var(vars, 'url').default = 'http://code.codesyntax.com/private/' get_var(vars, 'url').modes = () get_var(vars, 'license_name').default = 'GPL' get_var(vars, 'license_name').modes = () get_var(vars, 'zip_safe').default = 'False' get_var(vars, 'zip_safe').modes = ()
class Plone3Portlet(PloneApp): _template_dir = 'templates/plone3_portlet' summary = "A Plone 3 portlet" help = """ This creates a Plone project for a portlet. """ required_templates = ['nested_namespace'] use_cheetah = True vars = copy.deepcopy(PloneApp.vars) get_var(vars, 'namespace_package').default = 'collective' get_var(vars, 'namespace_package2').default = 'portlet' vars.append( StringVar( 'portlet_name', title='Portlet Name', description='Name of portlet (human readable)', modes=(EASY,EXPERT), default='Example Portlet', help=""" This becomes the human-readable title of the portlet. It gets generated in the GenericSetup profile file for the portlet. It appears in the Plone UI when managing portlets. """ ) ) vars.append( DottedVar( 'portlet_type_name', title='Portlet Type Name', description='Name of portlet type (actual name)', modes=(EASY, EXPERT), default='ExamplePortlet', help=""" This becomes the actual name of the portlet. It is not displayed in the Plone UI, but is the name it is registered under, and is used as the class name for the portlet, and is used in the generated GenericSetup profile. """ ) ) def pre(self, command, output_dir, vars): vars['zip_safe'] = False vars['portlet_filename'] = vars['portlet_type_name'].lower() vars['dotted_name'] = "%s.%s.%s" % (vars['namespace_package'], vars['namespace_package2'], vars['package']) super(Plone3Portlet, self).pre(command, output_dir, vars)
class Archetype(Plone): _template_dir = 'templates/archetype' summary = 'A Plone project that uses Archetypes content types' help = """ This creates a Plone project that uses Archetypes content types. It has local commands that will allow you to add content types and to add fields to your new content types. """ post_run_msg = """ There is a local command to add individual Archetype content types and to add fields to those content types. See the instructions above on how to use this command. """ required_templates = ['plone'] use_cheetah = True use_local_commands = True 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. """)) #zope2product should always defaults to True get_var(vars, 'zope2product').default = True #add_profile should always default to True for archetype packages get_var(vars, 'add_profile').default = True #add_profile need not appear as a question for archetype packages get_var(vars, 'add_profile').modes = (EXPERT, ) def post(self, command, output_dir, vars): # Remove tests.py -- we already have a tests/ package path = os.path.join(output_dir, vars['namespace_package'], vars['package']) os.remove(os.path.join(path, 'tests.py')) super(Archetype, self).post(command, output_dir, vars)
class Zope2Buildout(abstract_buildout.AbstractBuildout): _template_dir = 'templates/zope2_buildout' summary = "A buildout for a blank (non-Silva, non-Plone) Zope 2 instance" help = """ This template creates a buildout that does not contain Plone or Silva information. It is intended for people using Zope 2 directly. If you would like to use Plone or Silva, you should use the appropriate buildouts. """ post_run_msg = """ Generation finished. You probably want to run python bootstrap.py and then edit buildout.cfg before running bin/buildout -v". See README.txt for details. """ required_templates = [] use_cheetah = True vars = copy.deepcopy(abstract_buildout.AbstractBuildout.vars) vars.extend([ abstract_buildout.VAR_Z2_INSTALL, StringVar('zope2_version', title='Zope 2 Version', description='Version of Zope 2 to fetch, if needed', modes=(EASY, EXPERT), page='Main', default='2.11.1', help=""" If a version of Zope needs to be pulled down, this option lets you specify the version. """), abstract_buildout.VAR_ZOPE_USER, abstract_buildout.VAR_ZOPE_PASSWD, abstract_buildout.VAR_HTTP, abstract_buildout.VAR_DEBUG_MODE, abstract_buildout.VAR_VERBOSE_SEC, ])
def setUp(self): """ set up some basics for the coming tests """ self.vars = [ var('basic_var', 'This is a basic variable', title="Basic Title", default="foo", modes=(EXPERT, EASY)), BooleanVar('bool_var', 'This is a boolean variable', title="Boolean Title", default=False, page='Main', modes=(EASY)), StringVar('str_var', 'This is a string variable', title="String Title", default="string", page='Carl', modes=(EXPERT)), TextVar('txt_var', 'This is a text variable', page='Martin', title="Text Title", default="text", modes=()), DottedVar('dot_var', 'This is a dotted variable', title="Dotted Title", default="dotted.variable") ] self.template = BaseTemplate('my_name') create = get_commands()['create'].load() command = create('create') command.parse_args(['-t','archetype']) self.command = command
import copy from zopeskel.base import BaseTemplate from zopeskel.base import var, EASY, EXPERT from zopeskel.vars import StringVar, BooleanVar, IntVar, OnOffVar, BoundedIntVar VAR_PLONEVER = StringVar('plone_version', title='Plone Version', description='Plone version # to install', default='3.3.6', modes=(EASY, EXPERT), page='Main', help=""" This is the version of Plone that will be used for this buildout. You should enter the version number you wish to use. """) VAR_Z2_INSTALL = StringVar( 'zope2_install', title='Zope2 Install Path', description='Path to Zope2 installation; leave blank to fetch one!', default='', modes=(EASY, EXPERT), page='Main', help=""" This is the file path to the Zope 2 installation. You can enter this path to use a pre-existing installation, or you can leave it blank, and the current Zope 2 will be downloaded and installed in your new buildout. """)
def setUp(self): self.svar = StringVar('name', 'description')
class BasicNamespace(BaseTemplate): _template_dir = 'templates/basic_namespace' summary = "A basic Python project with a namespace package" ndots = 1 help = """ This creates a Python project without any Zope or Plone features. """ category = "Core Python" required_templates = [] use_cheetah = True vars = copy.deepcopy(BaseTemplate.vars) vars += [ DottedVar( 'namespace_package', title='Namespace Package Name', description='Name of outer namespace package', default='plone', modes=(EXPERT,), page='Namespaces', help=""" This is the name of the outer package (Python folder) for this project. For example, in 'Products.PloneFormGen', this would be 'Products'. This will often be (for Plone products) 'Products'; it may also be the name of your company/project, or a common-style name like (for Plone products) 'collective'. Note that, for some templates, there may be two namespaces, rather than one (to create eggs with names like 'plone.app.blog')--in this case, this would be 'plone', the first of the enclosing namespaces. """ ), DottedVar( 'package', title='Package Name', description='Name of the inner namespace package', default='example', modes=(EXPERT,), page='Namespaces', help=""" This is the name of the innermost package (Python folder) for this project. For example, in 'Products.PloneFormGen', this would be 'PloneFormGen'. Note that, for some templates, there may be only a package name without a namespace package around it--in this case, this would be just the name of the package. """ ), StringVar( 'version', title='Version', description='Version number for project', default='1.0', modes=(EASY, EXPERT), page='Metadata', help=""" This becomes the version number of the created package. It will be set in the egg's setup.py, and may be referred to in other places in the generated project. """ ), StringVar( 'description', title='Description', description='One-line description of the project', default='', modes=(EASY, EXPERT), page='Metadata', help=""" This should be a single-line description of your project. It will be used in the egg's setup.py, and, for Zope/Plone projects, may be used in the GenericSetup profile description. """ ), TextVar( 'long_description', title='Long Description', description='Multi-line description (in ReST)', default='', modes=(), page='Metadata', help=""" This should be a full description for your project. It will be used in the egg's setup.py. It should be entered in 'restructured text' format; for information, see http://docutils.sourceforge.net/rst.html). """ ), StringVar( 'author', title='Author', description='Name of author for project', modes=(), page='Metadata', help=""" This should be the name of the author of this project. It will be used in the egg's setup.py, and, for some templates, in the generated documentation/README files. """ ), StringVar( 'author_email', title='Author Email', description='Email of author for project', modes=(), page='Metadata', help=""" This should be the name of the author of this project. It will be used in the egg's setup.py, and, for some templates, in the generated documentation/README files. """ ), StringVar('keywords', title='Keywords', description='List of keywords, space-separated', modes=(), page='Metadata', help=""" This should be the list of keywords for this project. This will be used in the egg's setup.py (and, if this egg is later published on PyPI, will be used to categorize the project). """ ), StringVar( 'url', title='Project URL', description='URL of the homepage for this project', modes=(), page='Metadata', default='http://svn.plone.org/svn/collective/', help=""" This should be a URL for the homepage for this project (if applicable). It will be used in the egg's setup.py. """ ), StringVar( 'license_name', title='Project License', description='Name of license for the project', default='GPL', modes=(), page='Metadata', help=""" The license that this project is issued under. It will be used in the egg's setup.py. Common choices here are 'GPL' (for the GNU General Public License), 'ZPL' (for the Zope Public License', and 'BSD' (for the BSD license). """ ), BooleanVar( 'zip_safe', title='Zip-Safe?', description='Can this project be used as a zipped egg? (true/false)', default=False, modes=(), page='Metadata', help=""" Some eggs can be used directly by Python in zipped format; others must be unzipped so that their contents can be properly used. Zipped eggs are smaller and may be easier to redistribute. Most Zope/Plone projects cannot be used in zipped format; if unsure, the safest answer is False. """ ), ] def check_vars(self, vars, command): if not command.options.no_interactive and \ not hasattr(command, '_deleted_once'): del vars['package'] command._deleted_once = True return super(BasicNamespace, self).check_vars(vars, command)
class StandardHosting(abstract_buildout.AbstractBuildout): _template_dir = "templates/plone_hosting" use_cheetah = True summary = "Plone hosting: buildout with ZEO and Plone versions below 3.2" required_templates = [] help = """ This template helps you to create an entire zope hosting setup, including ZEO and a single Zope client instance. If you desire, it can also install and set up the Varnish Caching/Proxy Server. Please Note: Due to changes in the packaging of Plone, this template is not suitable for versions of Plone beyond 3.1.7. If you are trying to use a later version of plone, you will need to edit the buildout resulting from this template in order to have it work correctly. Information related to these issues may be found here: http://plone.org/documentation/kb/repair-a-plone-3.1-buildout and here: http://plone.org/products/zopeskel/issues/25 """ vars = copy.deepcopy(abstract_buildout.AbstractBuildout.vars) vars = [ abstract_buildout.VAR_ZOPE_USER, abstract_buildout.VAR_ZOPE_PASSWD, IntVar( "base_port", title="Base Port #", description="# to use as base for Zope/ZEO/proxy ports", modes=(EASY, EXPERT), page="Main", default=8000, help=""" For standardization, rather than selecting ports for Zope, ZEO, and a proxy individually, these are tied together numerically. ZEO port = Base + 0 | Proxy port = Base + 1 | HTTP port = Base + 10 If the ports specified by any of these numbers are already in use or otherwise unavailable, this template will inform you of the problem and exit with an error. If this happens, please try another number for 'Base Port #' """, ), BooleanVar( "proxy", title="Install proxy server?", description="Should a proxy server be installed?", default=False, help=""" If you ask for a proxy server to be installed, this template will include the Varnish Caching/Proxy server. If you wish to use a different proxy server, please answer False and install your own. """, ), StringVar( "plone", title="Plone Version", description="Version to install (2.5, 2.5.1, 3.0, 3.0.1, etc)", default="3.1.7", help=""" You can use this template to install any version of Plone from 2.5 on. Versions of Plone more recent than 3.1.7 will require some editing of the generated configuration files. Please see the long description of this template (run 'zopskel --list') for more details. In general it is advisable to use the most recent version of Plone. You can find a list of stable Plone releases at http://plone.org/products/plone/releases/ """, ), BooleanVar( "buildout", title="Run Buildout?", description="Should bin/buildout command be executed?", default=True, help=""" Would you like this template to automatically run the buildut command as soon as it finishes creating the required files? Please note that if you've chosen to build a version of Plone more recent than 3.1.7 running buildout will fail unless you make changes to the generated configuration files. Please see the long description of this package (run 'zopeskel --list') for more details. If you intend on adding any specific third-party products or modifying the buildout in any way, you should answer 'False'. Then make your modifications and run `python bootstrap.py` followed by `bin/buildout`. """, ), ] def _buildout(self, output_dir): olddir = os.getcwd() try: os.chdir(output_dir) print "Bootstrapping the buildout" subprocess.call([sys.executable, "bootstrap.py"]) print "Configuring the buildout" subprocess.call(["bin/buildout", "-n"]) finally: os.chdir(olddir) def _checkPortAvailable(self, port): s = socket.socket() try: s.connect(("127.0.0.1", port)) except socket.error, e: s.close() if e.args[0] == errno.ECONNREFUSED: return raise BadCommand("Error checking port availability: %s" % e.args[1]) s.close() raise BadCommand("Port %s is already in use" % port)
def cleanupStylsheets(skinsdir, targets=TARGET_STYLESHEETS): for dirpath, dirnames, filenames in os.walk(skinsdir): for target in [t for t in targets if t in filenames]: print "Removing %s from %s%s" % (target, dirpath, os.sep) os.remove(os.path.join(dirpath, target)) theme_vars = [ StringVar( 'skinname', title='Skin Name', description='Name of the theme (human facing, added to portal_skins)', modes=(EASY, EXPERT), page='Main', help=""" This becomes the theme name (eg "My Theme"). It appears as the skin name choice in portal_skins, and is generated into the GenericSetup profile. """), StringVar('skinbase', title='Skin Base', description='Name of the theme from which this is copied', modes=(EXPERT, ), page='Main', default='Plone Default', help=""" Themes can descend from other themes--by choosing a base theme here, your new theme will use the same skinpath ordering as this theme, except your theme-specific folders will appear at the top (right below 'custom').