コード例 #1
0
    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)),
            DottedVar('egg', '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', 'package'])
        command.interactive = False
        self.command = command
        self.orig_dir = os.getcwd()
        self.temp_dir = tempfile.mkdtemp()
        cd(self.temp_dir)
コード例 #2
0
 def setUp(self):
     """ set up some basics for the coming tests
     """
     self.template = BaseTemplate('my_name')
     self.license_vars = {
         'author': 'Frank Herbert',
         'author_email': '*****@*****.**',
         'license_name': 'GPL',
         'project': 'my.package',
     }
     create = get_commands()['create'].load()
     command = create('create')
     command.parse_args(['-t', 'nested_namespace'])
     self.command = command
     self.command.interactive = False
     self.tempdir = tempfile.mkdtemp()
コード例 #3
0
 def check_vars(self, vars, cmd):
     result = BaseTemplate.check_vars(self, vars, cmd)
     if not vars['zope_password']:
         # for this to work you'll need pwgen installed
         passwd = run_cmd('pwgen -acn 9 1')
         if not passwd:
             passwd = 'admin'
         result['zope_password'] = passwd
     if not vars['staff_password']:
         # for this to work you'll need pwgen installed
         passwd = run_cmd('pwgen -acn 9 1')
         if not passwd:
             passwd = 'changeme'
         result['staff_password'] = passwd
     if int(result['plone_version'].split('.')[0]) < 4:
         self.required_structures.append('bootstrap')
     if vars['unified_buildout']:
         self.required_structures.append('unified')
     if vars['include_content']:
         self.required_structures.append('content_pkg')
     if vars['include_policy']:
         self.required_structures.append('policy_pkg')
     if vars['include_theme']:
         self.required_structures.append('theme_pkg')
     # XXX: var.structures can't handle this case yet
     if vars['project_name']:
         self.required_structures.append('buildouthttp')
     return result
コード例 #4
0
ファイル: template.py プロジェクト: sixfeetup/sixieskel.karl
 def check_vars(self, vars, cmd):
     result = BaseTemplate.check_vars(self, vars, cmd)
     # Add a db password for the project user
     passwd = run_cmd('pwgen -acn 9 1')
     if not passwd:
         passwd = 'admin'
     result['db_password'] = passwd
     # XXX: var.structures can't handle this case yet
     if vars['project_name']:
         self.required_structures.append('buildouthttp')
     return result
コード例 #5
0
 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', 'nested_namespace'])
     self.command = command
コード例 #6
0
 def setUp(self):
     """ set up some basics for the coming tests
     """
     self.template = BaseTemplate('my_name')
     self.license_vars = {
         'author': 'Frank Herbert',
         'author_email': '*****@*****.**',
         'license_name': 'GPL',
         'project': 'my.package',
     }
     command = CreateDistroCommand()
     command.parse_args(['-t', 'nested_namespace'])
     self.command = command
     self.command.interactive = False
     self.tempdir = tempfile.mkdtemp()
コード例 #7
0
ファイル: test_base.py プロジェクト: affinitic/templer.core
 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')
     command = CreateDistroCommand()
     command.parse_args(['-t', 'nested_namespace'])
     self.command = command
コード例 #8
0
class test_base_template(unittest.TestCase):
    """ test for methods on the base template class
    """

    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', 'nested_namespace'])
        self.command = command

    def test_filter_for_modes(self):
        """ _filter_for_modes should return a dictionary of var names to
            be hidden from view dependent on the running mode of zopeskel
            and the modes property of each variable
        """
        easy_vars = [var.name for var in self.vars
                     if EASY not in var.modes]
        expert_vars = [var.name for var in self.vars
                       if EXPERT not in var.modes]

        expert_mode = EASY
        hidden = self.template._filter_for_modes(expert_mode, self.vars)

        self.assertEqual(len(hidden), 2)
        for varname in hidden.keys():
            self.assertTrue(varname in easy_vars,
                            "missing easy var: %s" % varname)

        expert_mode = EXPERT
        hidden = self.template._filter_for_modes(expert_mode, self.vars)

        self.assertEqual(len(hidden), 2)
        for varname in hidden.keys():
            self.assertTrue(varname in expert_vars,
                            "missing expert var: %s" % varname)

    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 test_pages(self):
        """ pagaes provide discreet sets of template questions for web GUI
        """

        class MyTemplate(BaseTemplate):
            vars = BaseTemplate.vars + self.vars

        template = MyTemplate('some_name')
        pages = template.pages
        self.assertEqual(len(pages), 4)

        page = pages.pop(0)
        self.assertEqual(page['name'], 'Begin')
        questions = page['vars']
        self.assertEqual(len(questions), 1)
        self.assertEqual(questions[0].name, 'expert_mode')
        page = pages.pop(0)
        self.assertEqual(page['name'], 'Main')
        questions = page['vars']
        self.assertEqual(len(questions), 3)
        self.assertEqual(questions[0].name, 'basic_var')
        self.assertEqual(questions[1].name, 'bool_var')
        self.assertEqual(questions[2].name, 'dot_var')

        page = pages.pop(0)
        self.assertEqual(page['name'], 'Carl')
        questions = page['vars']
        self.assertEqual(len(questions), 1)
        self.assertEqual(questions[0].name, 'str_var')

        page = pages.pop(0)
        self.assertEqual(page['name'], 'Martin')
        questions = page['vars']
        self.assertEqual(len(questions), 1)
        self.assertEqual(questions[0].name, 'txt_var')

    def test_get_position_in_stack(self):
        """ verify that the position of a template can be reliably found
        """
        stack = self.template.get_template_stack(self.command)
        self.assertRaises(
            ValueError, self.template.get_position_in_stack, stack)

        new_template = NestedNamespace('joe')
        self.assertEqual(
            new_template.get_position_in_stack(stack), len(stack) - 1)

    def test_get_template_stack(self):
        """ verify that running this command against a create command
            with the argument '-t nested_namespace' returns the expected vals
        """
        stack = self.template.get_template_stack(self.command)
        self.assertEqual(len(stack), 1)

        self.assertFalse(self.template.__class__ in
                    [t.__class__ for t in stack], "%s" % stack)
        new_template = NestedNamespace('joe')
        self.assertTrue(new_template.__class__ in
                        [t.__class__ for t in stack], "%s" % stack)

        errmsg = "%s does not appear to be a subclass of %s"
        for c in [t.__class__ for t in stack]:
            self.assertTrue(isinstance(new_template, c),
                            errmsg % (new_template, c))

    def test_should_print_subcommands(self):
        """ Subcommands should be printed after the template runs
        """
        b_template = BasicNamespace('tom')
        n_template = NestedNamespace('bob')
        # pretend the nested_namespace template provides localcommands (it
        # doesn't have to actually provide them, just claim that it does)
        n_template.use_local_commands = True

        self.assertFalse(b_template.should_print_subcommands(self.command))
        self.assertTrue(n_template.should_print_subcommands(self.command))
コード例 #9
0
class PackageTemplate(BaseTemplate):
    _template_dir = 'templates/basic_namespace'
    summary = "A Python package template for templer"
    help = """
This creates a Python project without any Zope or Plone features.
"""
    category = "Core Python"

    required_templates = []
    default_required_structures = [
        'egg_docs',
    ]
    use_cheetah = True

    vars = copy.deepcopy(BaseTemplate.vars)
    vars += [
        DottedVar('egg',
                  title='Package',
                  description='Package name (for namespace support use dots.)',
                  default='',
                  modes=(EASY, ),
                  page='Namespaces',
                  help="""
Choose the name of your package.

If you want to use dots in the package name (namespaces), just provide them
directly in the name. For example: my.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.
"""),
        StringChoiceVar('license_name',
                        title='Project License',
                        description='Name of license for the project',
                        default='GPL',
                        modes=(),
                        page='Metadata',
                        choices=LICENSE_CATEGORIES.keys(),
                        structures=LICENSE_DICT,
                        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', or 'BSD' (for the BSD license).

%s

""" % BaseTemplate('null').readable_license_options()),
        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 pre(self, command, output_dir, vars):
        #        egg_var = get_var(vars, 'egg')
        #        egg_var = str(egg_var)
        #        vars['segs']
        #        egg_var.split('.')
        #        namespace = []
        #
        #        for i in range(len(vars['segs']) - 1):
        #            namespace.append(".".join(vars['segs'][0:i+1]))
        #
        #        vars['namespace'] = namespace

        super(PackageTemplate, self).pre(command, output_dir, vars)

    def run(self, command, output_dir, vars):
        templates.Template.run(self, command, output_dir, vars)

    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(PackageTemplate, self).check_vars(vars, command)
コード例 #10
0
ファイル: test_licenses.py プロジェクト: Vinsurya/Plone
class TestLicenses(unittest.TestCase):
    """ verify that all licenses are registered, findable and output correctly
    """

    def setUp(self):
        """ set up some basics for the coming tests
        """
        self.template = BaseTemplate('my_name')
        self.license_vars = {
            'author': 'Frank Herbert',
            'author_email': '*****@*****.**',
            'license_name': 'GPL',
            'project': 'my.package',
        }
        create = get_commands()['create'].load()
        command = create('create')
        command.parse_args(['-t', 'nested_namespace'])
        self.command = command
        self.command.interactive = False
        self.tempdir = tempfile.mkdtemp()

    def tearDown(self):
        """ remove temporary directory """
        shutil.rmtree(self.tempdir, ignore_errors=True)
        self.tempdir = None

    def test_entry_point_list(self):
        """ verify that all selectable licenses have entry points
        """
        selectable_licenses = [k.lower() for k in LICENSE_CATEGORIES.keys()]
        all_structures = [ep.name for ep\
                          in self.template.all_structure_entry_points()]
        for license in selectable_licenses:
            self.assertTrue(license in all_structures)

    def test_license_structure(self):
        """ verify that all license structures are well formed
        """
        this_year = datetime.date.today().year
        for this_license in LICENSE_EXPECTATIONS.keys():
            self.license_vars['license_name'] = this_license
            try:
                # base template requires no structures, we should only get
                # license structure
                my_license = self.template.load_structure(
                    self.license_vars['license_name'])
            except IndexError:
                self.fail('unable to find %s license structure' % this_license)

            my_license().write_files(self.command,
                                     self.tempdir,
                                     self.license_vars)

            top = os.listdir(self.tempdir)
            self.assertTrue('docs' in top,
                            'failed to write the docs directory')
            expected = LICENSE_EXPECTATIONS[this_license]
            docs = os.listdir(os.path.join(self.tempdir, 'docs'))
            for filename in expected:
                self.assertTrue(filename in docs,
                                '%s not found in docs dir' % filename)

            bpfh = open(os.path.join(self.tempdir, 'docs', expected[0]), 'r')
            bp = bpfh.read()
            self.assertTrue(self.license_vars['author'] in bp,
                            'Author not in license boilerplate')
            self.assertTrue(self.license_vars['project'] in bp,
                            'Project name not in license boilerplate')
            self.assertTrue(str(this_year) in bp,
                            'Current year not in license boilerplate')
            # clean up
            bpfh.close()
            shutil.rmtree(self.tempdir, ignore_errors=True)
            self.tempdir = tempfile.mkdtemp()
コード例 #11
0
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 = []
    default_required_structures = [
        'egg_docs',
    ]
    use_cheetah = True
    vars = copy.deepcopy(BaseTemplate.vars)
    vars += [
        DottedVar('namespace_package',
                  title='Namespace Package Name',
                  description='Name of outer namespace package',
                  default='my',
                  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.
"""),
        StringChoiceVar('license_name',
                        title='Project License',
                        description='Name of license for the project',
                        default='GPL',
                        modes=(),
                        page='Metadata',
                        choices=LICENSE_CATEGORIES.keys(),
                        structures=LICENSE_DICT,
                        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', or 'BSD' (for the BSD license).

%s

""" % BaseTemplate('null').readable_license_options()),
        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)
コード例 #12
0
class TestLicenses(unittest.TestCase):
    """ verify that all licenses are registered, findable and output correctly
    """
    def setUp(self):
        """ set up some basics for the coming tests
        """
        self.template = BaseTemplate('my_name')
        self.license_vars = {
            'author': 'Frank Herbert',
            'author_email': '*****@*****.**',
            'license_name': 'GPL',
            'project': 'my.package',
        }
        create = get_commands()['create'].load()
        command = create('create')
        command.parse_args(['-t', 'nested_namespace'])
        self.command = command
        self.command.interactive = False
        self.tempdir = tempfile.mkdtemp()

    def tearDown(self):
        """ remove temporary directory """
        shutil.rmtree(self.tempdir, ignore_errors=True)
        self.tempdir = None

    def test_entry_point_list(self):
        """ verify that all selectable licenses have entry points
        """
        selectable_licenses = [k.lower() for k in LICENSE_CATEGORIES.keys()]
        all_structures = [ep.name for ep\
                          in self.template.all_structure_entry_points()]
        for license in selectable_licenses:
            self.assertTrue(license in all_structures)

    def test_license_structure(self):
        """ verify that all license structures are well formed
        """
        this_year = datetime.date.today().year
        for this_license in LICENSE_EXPECTATIONS.keys():
            self.license_vars['license_name'] = this_license
            try:
                # base template requires no structures, we should only get
                # license structure
                my_license = self.template.load_structure(
                    self.license_vars['license_name'])
            except IndexError:
                self.fail('unable to find %s license structure' % this_license)

            my_license().write_files(self.command, self.tempdir,
                                     self.license_vars)

            top = os.listdir(self.tempdir)
            self.assertTrue('docs' in top,
                            'failed to write the docs directory')
            expected = LICENSE_EXPECTATIONS[this_license]
            docs = os.listdir(os.path.join(self.tempdir, 'docs'))
            for filename in expected:
                self.assertTrue(filename in docs,
                                '%s not found in docs dir' % filename)

            bpfh = open(os.path.join(self.tempdir, 'docs', expected[0]), 'r')
            bp = bpfh.read()
            self.assertTrue(self.license_vars['author'] in bp,
                            'Author not in license boilerplate')
            self.assertTrue(self.license_vars['project'] in bp,
                            'Project name not in license boilerplate')
            self.assertTrue(
                str(this_year) in bp,
                'Current year not in license boilerplate')
            # clean up
            bpfh.close()
            shutil.rmtree(self.tempdir, ignore_errors=True)
            self.tempdir = tempfile.mkdtemp()
コード例 #13
0
class PackageTemplate(BaseTemplate):
    _outer_template_dir = 'templates/outer'
    _inner_template_dir = 'templates/inner'
    summary = "A Python package template for templer"
    help = """
This creates a Python project without any Zope or Plone features.
"""
    category = "Core Python"

    required_templates = []
    default_required_structures = [
        'egg_docs',
    ]
    use_cheetah = True

    vars = copy.deepcopy(BaseTemplate.vars)
    vars += [
        DottedVar('egg',
                  title='Package',
                  description='Package name (for namespace support use dots.)',
                  default='',
                  modes=(EASY, ),
                  page='Namespaces',
                  help="""
Choose the name of your package.

If you want to use dots in the package name (namespaces), just provide them
directly in the name. For example: my.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.
"""),
        StringChoiceVar('license_name',
                        title='Project License',
                        description='Name of license for the project',
                        default='GPL',
                        modes=(),
                        page='Metadata',
                        choices=LICENSE_CATEGORIES.keys(),
                        structures=LICENSE_DICT,
                        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', or 'BSD' (for the BSD license).

%s

""" % BaseTemplate('null').readable_license_options()),
        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 pre(self, command, output_dir, vars):
        """The namespace string for insertion into setup.py needs to
           be calculated, and inserted into the vars for use in
           setup.py_tmpl.
        """
        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(PackageTemplate, self).pre(command, output_dir, vars)

    def post(self, command, output_dir, vars):
        cwd = os.getcwd()
        os.chdir(vars['egg'])
        os.chdir('src')
        for i in range(len(vars['egg'].split('.'))):
            segs = vars['egg'].split('.')[0:i + 1]
            try:
                os.mkdir(os.path.join(*vars['egg'].split('.')[0:i + 1]))
            except OSError:
                pass
            segs.append("__init__.py")
            init = None
            if i != len(vars['egg'].split('.')) - 1:
                init = open(os.path.join(*segs), "w")
                init.write(
                    "__import__('pkg_resources').declare_namespace(__name__)")
            if not init is None:
                init.close()
        os.chdir(cwd)
        super(PackageTemplate, self).post(command, output_dir, vars)

    def run(self, command, output_dir, vars):
        self._template_dir = self._outer_template_dir
        templates.Template.run(self, command, output_dir, vars)
        output_dir = os.path.join(*([vars['egg'], 'src'] +
                                    vars['egg'].split('.')))

        self._template_dir = self._inner_template_dir
        _old_required_structures = self.required_structures
        self.required_structures = []
        templates.Template.run(self, command, output_dir, vars)
        self.required_structures = _old_required_structures

    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(PackageTemplate, self).check_vars(vars, command)
コード例 #14
0
 def check_vars(self, vars, cmd):
     result = BaseTemplate.check_vars(self, vars, cmd)
     if vars['project_name']:
         self.required_structures.append('buildouthttp')
     return result