A Plone CLI for creating Plone packages
The Plone CLI is meant for developing Plone packages, we will not add functions to install or run Plone in production. For this we should build another package, let's say *plonectl which will provide installing and deployment functions. It also support's GIT by default, to keep track of changes one is doing with the templates.*
We install plonecli in the global user site-packages, so that we can use it in multible projects.
Versions newer than 0.1.1b4 are installable like any other package with pip:
$ pip install plonecli --user
$ plonecli -l
To upgrade plonecli just do:
$ pip install -U plonecli --user
Note: Make sure that the install directory is in $PATH ( e.g. export PATH=$PATH:$HOME/.local/bin/ )
NOTE: We are now using a the ORIGINAL version of the CLICK library, please uninstall plonecli-click before you install the new version of plonecli.
If would like to use plonecli with pipenv, you can do it as follow:
$ mkdir cli
$ cd cli
$ pipenv install plonecli
$ pipenv shell
$ plonecli -l
To enable auto completion plonecli provides the plonecli_autocomplete.sh script, put the following bash command into your bashrc:
If you installed plonecli in user global packages:
$ . ~/.local/bin/plonecli_autocomplete.sh
If you installed plonecli in a virtualenv it's:
$ . /path/to/your/virtualenv/bin/plonecli_autocomplete.sh
If you used pipenv to install plonecli, you have to find out the path to the virtualenv before:
$ pipenv --virtualenv
/home/maik/.local/share/virtualenvs/pe-WnXOnVWH
. /home/maik/.local/share/virtualenvs/pe-WnXOnVWH/bin/plonecli_autocomplete.sh
Full documentation for end users can be found in the "docs" folder, this will be available in the Plone docs at some point.
Note: you can set default answers for mr.bob questions, see bobtemplates.plone README.
$ plonecli --help
Usage: plonecli [OPTIONS] COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]...
Plone Command Line Interface (CLI)
Options:
-l, --list-templates
-V, --versions
-h, --help Show this message and exit.
Commands:
build Bootstrap and build the package
buildout Run the package buildout
config Configure mr.bob global settings
create Create a new Plone package
debug Run the Plone client in debug mode
requirements Install the local package requirements
serve Run the Plone client in foreground mode
test Run the tests in your package
virtualenv Create/update the local virtual environment...
$ plonecli -l
Available mr.bob templates:
- addon
- behavior
- content_type
- portlet
- theme
- theme_barceloneta
- view
- viewlet
- vocabulary
- buildout
- theme_package [deprecated] >> Please use the theme_barceloneta subtemplate!
$ plonecli create addon src/collective.todo
You can add different features thru subtemplates. You can use them also multible time to create different features of the same typ, like two different content types.
$ cd collective.todo
$ plonecli add behavior
$ plonecli add content_type
$ plonecli add theme
$ plonecli add view
$ plonecli add viewlet
$ plonecli add vocabulary
$ plonecli build
This will run:
$ virtualenv . $ ./bin/pip install -r requirements.txt --upgrade $ ./bin/buildout
in your target directory.
You can always run the 3 steps explicit by using virtualenv
,``requirements``, buildout
instead of build.
If you want to reset your build use the --clean
option on build.
This will clear your virtualenv before installing the requirements and also running buildout with -n
to get the newest versions.
$ plonecli serve
$ plonecli test
or run specific tests:
$ plonecli test -t test_the_thing
or run all tests including Robot tests:
$ plonecli test --all
You can combine the steps above like this:
$ plonecli create addon src/collective.todo build test --all serve
$ git clone https://github.com/plone/plonecli/
$ cd plonecli
$ virtualenv .
$ source bin/activate
$ pip install -r requirements.txt
$ python setup.py develop
$ plonecli --help
You can run the tests using the following command:
$ tox
or by installing py.test and run the test directly without tox:
$ py.test test/
or a single test:
$ py.test test/ -k test_get_package_root
All mr.bob templates can be registered for plonecli by adding an entry_point to your setup.py.
Here are the entry_points of the bobtemplates.plone package:
entry_points={
'mrbob_templates': [
'plone_addon = bobtemplates.plone.bobregistry:plone_addon',
'plone_buildout = bobtemplates.plone.bobregistry:plone_buildout', # NOQA E501
'plone_theme_package = bobtemplates.plone.bobregistry:plone_theme_package', # NOQA E501
'plone_content_type = bobtemplates.plone.bobregistry:plone_content_type', # NOQA E501
'plone_theme = bobtemplates.plone.bobregistry:plone_theme',
'plone_vocabulary = bobtemplates.plone.bobregistry:plone_vocabulary', # NOQA E501
],
},
The entry_point name is used as the global template name for mr.bob. You also need to provide a bobregistry.py file with a method for each entry_point, it should be named after the entry_point name:
# -*- coding: utf-8 -*-
class RegEntry(object):
def __init__(self):
self.template = ''
self.plonecli_alias = ''
self.depend_on = None
self.deprecated = False
self.info = ''
# standalone template
def plone_addon():
reg = RegEntry()
reg.template = 'bobtemplates.plone:addon'
reg.plonecli_alias = 'addon'
return reg
# sub template
def plone_theme():
reg = RegEntry()
reg.template = 'bobtemplates.plone:theme'
reg.plonecli_alias = 'theme'
reg.depend_on = 'plone_addon'
return reg
For every template you add a line to the entry_points and define a method in the bobregistry.py, which will return a registry object with some properties.
template
- contains the name of the actual mr.bob template.plonecli_alias
- defines the name under which the template will be used inside ploneclidepend_on
:- for a standalone template, the depend_on property is None
- for a sub template, the depend_on contains the name of the parent standalone template, usualy addon.
deprecated
- boolean saying whether this templates is deprecated and will be removed in future releasesinfo
- message that will be shown next to the template when the template is deprecated
- Issue Tracker: https://github.com/plone/plonecli/issues
- Source Code: https://github.com/plone/plonecli
This project is licensed under the BSD license.