diff options
author | Pacien TRAN-GIRARD | 2017-05-11 21:28:27 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2017-05-11 21:28:27 +0200 |
commit | 4aea92c4f85fceb4e2a920f7a8beb37ce7d8c04c (patch) | |
tree | 2bf50e1f7b3abb3393388897bb93fc40778f73bb | |
parent | 2b03edb2f8172b131602171dca3f19186906e967 (diff) | |
download | desktop-utilities-4aea92c4f85fceb4e2a920f7a8beb37ce7d8c04c.tar.gz |
Add pelican compile and dev-server convenience scripts
-rwxr-xr-x | pelican-compile.sh | 46 | ||||
-rwxr-xr-x | pelican-dev.sh | 103 |
2 files changed, 149 insertions, 0 deletions
diff --git a/pelican-compile.sh b/pelican-compile.sh new file mode 100755 index 0000000..ac3d478 --- /dev/null +++ b/pelican-compile.sh | |||
@@ -0,0 +1,46 @@ | |||
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" | ||
23 | echo "This compiles the pelican site in the current directory," | ||
24 | echo "using ./pelicanconf.py as configuration file," | ||
25 | echo " ./content as input directory," | ||
26 | echo " ./output as output directory (overwriting it)." | ||
27 | exit 3 | ||
28 | } | ||
29 | |||
30 | function compile(){ | ||
31 | echo "Compiling" | ||
32 | shift | ||
33 | rm -r $OUTPUTDIR | ||
34 | $PELICAN $INPUTDIR -o $OUTPUTDIR -s $CONFFILE $PELICANOPTS | ||
35 | } | ||
36 | |||
37 | ### | ||
38 | # MAIN | ||
39 | ### | ||
40 | |||
41 | if [[ $1 == "help" ]]; then | ||
42 | usage | ||
43 | else | ||
44 | compile | ||
45 | fi | ||
46 | |||
diff --git a/pelican-dev.sh b/pelican-dev.sh new file mode 100755 index 0000000..2661df3 --- /dev/null +++ b/pelican-dev.sh | |||
@@ -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 | mkdir -p $OUTPUTDIR && 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 | ||