Skip to main content

Code Commit Push Publish engine.

Project description

Code Commit Push Publish

Live and die by documentation.

Matthew Ginnard


pip install c2p2


pip install git+


Fork c2p2_template

The easiest way to start is to fork this template:

Templates API

The application looks for templates inside SOURCE_FOLDER, so we need to add them. Minimal list of files required is:

- site
    - engine
        - templates
            - 404.html
            - 500.html
            - index.html
            - page.html
            - label.html
            - sitemap.xml

index.html, page.html, label.html and sitemap.xml receives, beside tornado standart template context, variable c, that uses to access a list of pages and labels, for example:

{{ }}
{{ }}
{{ }}
{{ c.label }}
{% for page in c.pages %}
{{ c.pages['<page_slug>'] }}
{{ c.pages.for_label('<label_slug>') }} is available only in page.html. It returns current page object.

Page object has next attributes:
  • uri
  • html
  • created
  • modified
  • title
  • meta
  • labels

page.meta returns PageMeta object, where all variables specified in the top of the page is available.

created: 2015-10-10T00:00
show_comments: true
labels: Label1
// page.html
{{ }} -> '2015-10-10T00:00'
{{ }} -> '2015-10-10T00:00'
{{ }} -> 'Label1'
{{'labels') }} -> 'Label1'
{{'labels') }} -> ['Label1', 'Label2']
{{ }} -> true
{{ }} -> None

page.labels returns list of Label objects connected to the page:

{% for label in %}{{ label.title }}{% end %}
Label object has next attributes:
  • title
  • slug

c.pages returns an iterable that allows to get all pages list. In label.html it return only pages belong to the label. You also can get any page by uri using c.pages.

{% for page in c.pages %}{{ page.title }}{% end %}

{{ c.pages['2010/09/blog-post'].html }}

{{ c.pages.for_label('default') }}

Running the server

To run the application use site/engine/

import os.path

from c2p2 import app
from c2p2.settings import settings

rel = lambda p: os.path.join(os.path.dirname(os.path.realpath(__file__)), p)

if __name__ == '__main__':
    settings.SOURCE_FOLDER = rel('..')


There are 4 ways to set settings:
  • default settings (see c2p2/
  • environment variables with C2P2_ prefix: export C2P2_PORT=5000
  • command line arguments ( --PORT=5000)
  • also you can change them directly settings.PORT = 5000 in site/engine/
Available settings:
  • DEBUG: Enable tornado debug mode
  • PORT: Port the app listening to
  • SOURCE_FOLDER: Path to folder that contains pages source
  • UPDATE_TIMEOUT: Number of seconds to rescan source folder. 0 - disable
  • GITHUB_VALIDATE_IP: Enable GitHub ip validation
  • GITHUB_SECRET: GitHub web hook secret, optional
  • GITHUB_BRANCH: GitHub branch to watch

Questions and Answers

Run locally

cd site
virtualenv venv --no-site-packages -p /usr/local/bin/python3.5
source venv/bin/activate
pip install c2p2
python engine/

Open http://localhost:5000 in browser.

Update site if md file was changed without server restart (watch md files)


Update site on GitHub push

Create a new GitHub hook for your repository:
  • url:
  • secret: should be equal to GITHUB_SECRET setting value

Production configuration

Example settings:
  • DEBUG=false
  • GITHUB_SECRET=<webhook secret>
  • GITHUB_BRANCH=master

Example supervisor configuration:

command=/home/deploy/mysite/venv/bin/python engine/

Example nginx configuration:

upstream mysite {

server {
    listen   80;

    # If you need to restrict access
    # auth_basic "Restricted";
    # auth_basic_user_file /etc/nginx/.htpasswd;


    location / {
        proxy_cache off;
        proxy_pass http://mysite;

    location ~* \.(?:css|png|jpe?g|gif|ico|zip|txt)$ {
        root /home/deploy/mysite;
        log_not_found off;

    error_page 500 502 503 504 /home/deploy/mysite/engine/templates/500.html;
    error_page 400 402 403 404 /home/deploy/mysite/engine/templates/400.html;

Favicon and robots.txt

Just add favicon.ico and robots.txt to root folder of your site.

Custom md directives

It is possible to register custom md directives:

from c2p2.utils import ExtensionsRegistry



python -m unittest c2p2.tests


If you want to contribute to this project, please perform the following steps:

# Fork this repository
$ virtualenv .env --no-site-packages -p /usr/local/bin/python3.5
$ source .env/bin/activate
$ python install
$ pip install -r requirements.txt

$ git branch feature_branch master
# Implement your feature and tests
$ git add . && git commit
$ git push -u origin feature_branch
# Send me a pull request for your feature branch

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

c2p2-0.1.3.tar.gz (13.1 kB view hashes)

Uploaded source

Built Distribution

c2p2-0.1.3-py2.py3-none-any.whl (14.7 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page