Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit e7dea8d

Browse files
committed
Adds basic pelican bootstrap
1 parent 21af39e commit e7dea8d

File tree

5 files changed

+380
-0
lines changed

5 files changed

+380
-0
lines changed

Makefile

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
PY?=python
2+
PELICAN?=pelican
3+
PELICANOPTS=
4+
5+
BASEDIR=$(CURDIR)
6+
INPUTDIR=$(BASEDIR)/content
7+
OUTPUTDIR=$(BASEDIR)/output
8+
CONFFILE=$(BASEDIR)/pelicanconf.py
9+
PUBLISHCONF=$(BASEDIR)/publishconf.py
10+
11+
FTP_HOST=localhost
12+
FTP_USER=anonymous
13+
FTP_TARGET_DIR=/
14+
15+
SSH_HOST=localhost
16+
SSH_PORT=22
17+
SSH_USER=root
18+
SSH_TARGET_DIR=/var/www
19+
20+
S3_BUCKET=my_s3_bucket
21+
22+
CLOUDFILES_USERNAME=my_rackspace_username
23+
CLOUDFILES_API_KEY=my_rackspace_api_key
24+
CLOUDFILES_CONTAINER=my_cloudfiles_container
25+
26+
DROPBOX_DIR=~/Dropbox/Public/
27+
28+
GITHUB_PAGES_BRANCH=gh-pages
29+
30+
DEBUG ?= 0
31+
ifeq ($(DEBUG), 1)
32+
PELICANOPTS += -D
33+
endif
34+
35+
RELATIVE ?= 0
36+
ifeq ($(RELATIVE), 1)
37+
PELICANOPTS += --relative-urls
38+
endif
39+
40+
help:
41+
@echo 'Makefile for a pelican Web site '
42+
@echo ' '
43+
@echo 'Usage: '
44+
@echo ' make html (re)generate the web site '
45+
@echo ' make clean remove the generated files '
46+
@echo ' make regenerate regenerate files upon modification '
47+
@echo ' make publish generate using production settings '
48+
@echo ' make serve [PORT=8000] serve site at http://localhost:8000'
49+
@echo ' make serve-global [SERVER=0.0.0.0] serve (as root) to $(SERVER):80 '
50+
@echo ' make devserver [PORT=8000] start/restart develop_server.sh '
51+
@echo ' make stopserver stop local server '
52+
@echo ' make ssh_upload upload the web site via SSH '
53+
@echo ' make rsync_upload upload the web site via rsync+ssh '
54+
@echo ' make dropbox_upload upload the web site via Dropbox '
55+
@echo ' make ftp_upload upload the web site via FTP '
56+
@echo ' make s3_upload upload the web site via S3 '
57+
@echo ' make cf_upload upload the web site via Cloud Files'
58+
@echo ' make github upload the web site via gh-pages '
59+
@echo ' '
60+
@echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html '
61+
@echo 'Set the RELATIVE variable to 1 to enable relative urls '
62+
@echo ' '
63+
64+
html:
65+
$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
66+
67+
clean:
68+
[ ! -d $(OUTPUTDIR) ] || rm -rf $(OUTPUTDIR)
69+
70+
regenerate:
71+
$(PELICAN) -r $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
72+
73+
serve:
74+
ifdef PORT
75+
cd $(OUTPUTDIR) && $(PY) -m pelican.server $(PORT)
76+
else
77+
cd $(OUTPUTDIR) && $(PY) -m pelican.server
78+
endif
79+
80+
serve-global:
81+
ifdef SERVER
82+
cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 $(SERVER)
83+
else
84+
cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 0.0.0.0
85+
endif
86+
87+
88+
devserver:
89+
ifdef PORT
90+
$(BASEDIR)/develop_server.sh restart $(PORT)
91+
else
92+
$(BASEDIR)/develop_server.sh restart
93+
endif
94+
95+
stopserver:
96+
$(BASEDIR)/develop_server.sh stop
97+
@echo 'Stopped Pelican and SimpleHTTPServer processes running in background.'
98+
99+
publish:
100+
$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(PUBLISHCONF) $(PELICANOPTS)
101+
102+
ssh_upload: publish
103+
scp -P $(SSH_PORT) -r $(OUTPUTDIR)/* $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR)
104+
105+
rsync_upload: publish
106+
rsync -e "ssh -p $(SSH_PORT)" -P -rvzc --delete $(OUTPUTDIR)/ $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR) --cvs-exclude
107+
108+
dropbox_upload: publish
109+
cp -r $(OUTPUTDIR)/* $(DROPBOX_DIR)
110+
111+
ftp_upload: publish
112+
lftp ftp://$(FTP_USER)@$(FTP_HOST) -e "mirror -R $(OUTPUTDIR) $(FTP_TARGET_DIR) ; quit"
113+
114+
s3_upload: publish
115+
s3cmd sync $(OUTPUTDIR)/ s3://$(S3_BUCKET) --acl-public --delete-removed --guess-mime-type
116+
117+
cf_upload: publish
118+
cd $(OUTPUTDIR) && swift -v -A https://auth.api.rackspacecloud.com/v1.0 -U $(CLOUDFILES_USERNAME) -K $(CLOUDFILES_API_KEY) upload -c $(CLOUDFILES_CONTAINER) .
119+
120+
github: publish
121+
ghp-import -m "Generate Pelican site" -b $(GITHUB_PAGES_BRANCH) $(OUTPUTDIR)
122+
git push origin $(GITHUB_PAGES_BRANCH)
123+
124+
.PHONY: html help clean regenerate serve serve-global devserver publish ssh_upload rsync_upload dropbox_upload ftp_upload s3_upload cf_upload github

develop_server.sh

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env bash
2+
##
3+
# This section should match your Makefile
4+
##
5+
PY=${PY:-python}
6+
PELICAN=${PELICAN:-pelican}
7+
PELICANOPTS=
8+
9+
BASEDIR=$(pwd)
10+
INPUTDIR=$BASEDIR/content
11+
OUTPUTDIR=$BASEDIR/output
12+
CONFFILE=$BASEDIR/pelicanconf.py
13+
14+
###
15+
# Don't change stuff below here unless you are sure
16+
###
17+
18+
SRV_PID=$BASEDIR/srv.pid
19+
PELICAN_PID=$BASEDIR/pelican.pid
20+
21+
function usage(){
22+
echo "usage: $0 (stop) (start) (restart) [port]"
23+
echo "This starts Pelican in debug and reload mode and then launches"
24+
echo "an HTTP server to help site development. It doesn't read"
25+
echo "your Pelican settings, so if you edit any paths in your Makefile"
26+
echo "you will need to edit your settings as well."
27+
exit 3
28+
}
29+
30+
function alive() {
31+
kill -0 $1 >/dev/null 2>&1
32+
}
33+
34+
function shut_down(){
35+
PID=$(cat $SRV_PID)
36+
if [[ $? -eq 0 ]]; then
37+
if alive $PID; then
38+
echo "Stopping HTTP server"
39+
kill $PID
40+
else
41+
echo "Stale PID, deleting"
42+
fi
43+
rm $SRV_PID
44+
else
45+
echo "HTTP server PIDFile not found"
46+
fi
47+
48+
PID=$(cat $PELICAN_PID)
49+
if [[ $? -eq 0 ]]; then
50+
if alive $PID; then
51+
echo "Killing Pelican"
52+
kill $PID
53+
else
54+
echo "Stale PID, deleting"
55+
fi
56+
rm $PELICAN_PID
57+
else
58+
echo "Pelican PIDFile not found"
59+
fi
60+
}
61+
62+
function start_up(){
63+
local port=$1
64+
echo "Starting up Pelican and HTTP server"
65+
shift
66+
$PELICAN --debug --autoreload -r $INPUTDIR -o $OUTPUTDIR -s $CONFFILE $PELICANOPTS &
67+
pelican_pid=$!
68+
echo $pelican_pid > $PELICAN_PID
69+
cd $OUTPUTDIR
70+
$PY -m pelican.server $port &
71+
srv_pid=$!
72+
echo $srv_pid > $SRV_PID
73+
cd $BASEDIR
74+
sleep 1
75+
if ! alive $pelican_pid ; then
76+
echo "Pelican didn't start. Is the Pelican package installed?"
77+
return 1
78+
elif ! alive $srv_pid ; then
79+
echo "The HTTP server didn't start. Is there another service using port" $port "?"
80+
return 1
81+
fi
82+
echo 'Pelican and HTTP server processes now running in background.'
83+
}
84+
85+
###
86+
# MAIN
87+
###
88+
[[ ($# -eq 0) || ($# -gt 2) ]] && usage
89+
port=''
90+
[[ $# -eq 2 ]] && port=$2
91+
92+
if [[ $1 == "stop" ]]; then
93+
shut_down
94+
elif [[ $1 == "restart" ]]; then
95+
shut_down
96+
start_up $port
97+
elif [[ $1 == "start" ]]; then
98+
if ! start_up $port; then
99+
shut_down
100+
fi
101+
else
102+
usage
103+
fi

fabfile.py

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
from fabric.api import *
2+
import fabric.contrib.project as project
3+
import os
4+
import shutil
5+
import sys
6+
import SocketServer
7+
8+
from pelican.server import ComplexHTTPRequestHandler
9+
10+
# Local path configuration (can be absolute or relative to fabfile)
11+
env.deploy_path = 'output'
12+
DEPLOY_PATH = env.deploy_path
13+
14+
# Remote server configuration
15+
production = 'root@localhost:22'
16+
dest_path = '/var/www'
17+
18+
# Rackspace Cloud Files configuration settings
19+
env.cloudfiles_username = 'my_rackspace_username'
20+
env.cloudfiles_api_key = 'my_rackspace_api_key'
21+
env.cloudfiles_container = 'my_cloudfiles_container'
22+
23+
# Github Pages configuration
24+
env.github_pages_branch = "gh-pages"
25+
26+
# Port for `serve`
27+
PORT = 8000
28+
29+
def clean():
30+
"""Remove generated files"""
31+
if os.path.isdir(DEPLOY_PATH):
32+
shutil.rmtree(DEPLOY_PATH)
33+
os.makedirs(DEPLOY_PATH)
34+
35+
def build():
36+
"""Build local version of site"""
37+
local('pelican -s pelicanconf.py')
38+
39+
def rebuild():
40+
"""`clean` then `build`"""
41+
clean()
42+
build()
43+
44+
def regenerate():
45+
"""Automatically regenerate site upon file modification"""
46+
local('pelican -r -s pelicanconf.py')
47+
48+
def serve():
49+
"""Serve site at http://localhost:8000/"""
50+
os.chdir(env.deploy_path)
51+
52+
class AddressReuseTCPServer(SocketServer.TCPServer):
53+
allow_reuse_address = True
54+
55+
server = AddressReuseTCPServer(('', PORT), ComplexHTTPRequestHandler)
56+
57+
sys.stderr.write('Serving on port {0} ...\n'.format(PORT))
58+
server.serve_forever()
59+
60+
def reserve():
61+
"""`build`, then `serve`"""
62+
build()
63+
serve()
64+
65+
def preview():
66+
"""Build production version of site"""
67+
local('pelican -s publishconf.py')
68+
69+
def cf_upload():
70+
"""Publish to Rackspace Cloud Files"""
71+
rebuild()
72+
with lcd(DEPLOY_PATH):
73+
local('swift -v -A https://auth.api.rackspacecloud.com/v1.0 '
74+
'-U {cloudfiles_username} '
75+
'-K {cloudfiles_api_key} '
76+
'upload -c {cloudfiles_container} .'.format(**env))
77+
78+
@hosts(production)
79+
def publish():
80+
"""Publish to production via rsync"""
81+
local('pelican -s publishconf.py')
82+
project.rsync_project(
83+
remote_dir=dest_path,
84+
exclude=".DS_Store",
85+
local_dir=DEPLOY_PATH.rstrip('/') + '/',
86+
delete=True,
87+
extra_opts='-c',
88+
)
89+
90+
def gh_pages():
91+
"""Publish to GitHub Pages"""
92+
rebuild()
93+
local("ghp-import -b {github_pages_branch} {deploy_path}".format(**env))
94+
local("git push origin {github_pages_branch}".format(**env))

pelicanconf.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*- #
3+
from __future__ import unicode_literals
4+
5+
AUTHOR = u'PythonBrasil'
6+
SITENAME = u'PythonBRasil[12]'
7+
SITEURL = ''
8+
9+
PATH = 'content'
10+
11+
TIMEZONE = 'America/Sao_Paulo'
12+
13+
DEFAULT_LANG = u'pt'
14+
15+
# Feed generation is usually not desired when developing
16+
FEED_ALL_ATOM = None
17+
CATEGORY_FEED_ATOM = None
18+
TRANSLATION_FEED_ATOM = None
19+
AUTHOR_FEED_ATOM = None
20+
AUTHOR_FEED_RSS = None
21+
22+
# Blogroll
23+
LINKS = (('Pelican', 'http://getpelican.com/'),
24+
('Python.org', 'http://python.org/'),
25+
('Jinja2', 'http://jinja.pocoo.org/'),
26+
('You can modify those links in your config file', '#'),)
27+
28+
# Social widget
29+
SOCIAL = (('You can add links in your config file', '#'),
30+
('Another social link', '#'),)
31+
32+
DEFAULT_PAGINATION = False
33+
34+
# Uncomment following line if you want document-relative URLs when developing
35+
#RELATIVE_URLS = True

publishconf.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*- #
3+
from __future__ import unicode_literals
4+
5+
# This file is only used if you use `make publish` or
6+
# explicitly specify it as your config file.
7+
8+
import os
9+
import sys
10+
sys.path.append(os.curdir)
11+
from pelicanconf import *
12+
13+
SITEURL = 'http://2016.pythonbrasil.org.br'
14+
RELATIVE_URLS = False
15+
16+
FEED_ALL_ATOM = 'feeds/all.atom.xml'
17+
CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'
18+
19+
DELETE_OUTPUT_DIRECTORY = True
20+
21+
# Following items are often useful when publishing
22+
23+
#DISQUS_SITENAME = ""
24+
#GOOGLE_ANALYTICS = ""

0 commit comments

Comments
 (0)