[Openstack] script to build epubs from openstack documentation

Cristian Falcas cristi.falcas at gmail.com
Tue Dec 31 01:19:03 UTC 2013


Hi all,

I made a small script that builds epubs from openstack documentation pages.

The most annoying problem is that the TOC is not always correctly
build (because how calibre is searching for headers and how the
openstack pages are build)

Anyway, it's readable and looks to have the correct order of pages.

You will need calibre installed and wget. Also you will have to fix
any new lines added by gmail :(.


#!/bin/bash

# sudo python -c "import sys; py3 = sys.version_info[0] > 2; u =
__import__('urllib.request' if py3 else 'urllib', fromlist=1);
exec(u.urlopen('http://status.calibre-ebook.com/linux_installer').read());
main()"

make_ebook() {
  mkdir -p ./$dir
  wget --directory-prefix=$dir --recursive --no-clobber
--page-requisites --html-extension --convert-links --domains
docs.openstack.org --no-parent -R *.pdf -nH --cut-dirs=2 $site
  [[ -f ./common/css/custom.css ]] && extra_path="common";
css="./$dir/$extra_path/css/custom.css"
  [[ -f ./content/index.html ]] && extra_path="content";
index="./$dir/$extra_path/index.html"

  echo '
body #content {margin-top: 0px;}
#header {display:none;}
#leftnavigation {display:none;}
#content {margin: 0px 0px 0px 0px;}
#toolbar {display:none;}
#legal {display:none;}' >> $css

  /opt/calibre/ebook-convert $index ./$dir.epub
--minimum-line-height=0 --smarten-punctuation --level1-toc="//h:h1"
--level2-toc="//h:h2" --level3-toc="//h:h3" --chapter="//*[name()='h1'
or name()='h2' or name()='h3']" --input-profile=default
--output-profile=nook --use-auto-toc --title=$dir --authors=openstack
}

site="http://docs.openstack.org/trunk/openstack-ops/content/section_yk2_jpr_lj.html"
dir=openstack_ops
make_ebook

site="http://docs.openstack.org/trunk/config-reference/content/config_overview.html"
dir=openstack_conf
make_ebook

site="http://docs.openstack.org/admin-guide-cloud/content/ch_getting-started-with-openstack.html"
dir=openstack_admin_guide
make_ebook

site="http://docs.openstack.org/high-availability-guide/content/ch-intro.html"
dir=openstack_high_availability
make_ebook




Best regards,
Cristian Falcas



More information about the Openstack mailing list