Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2@file
3@brief Various functions to install `reveal.js <https://github.com/hakimel/reveal.js/releases>`_.
4"""
5from __future__ import print_function
6import re
7import os
8import sys
10from .install_custom import download_page, download_file
11from ..installhelper.install_cmd_helper import unzip_files
13if sys.version_info[0] == 2:
14 FileNotFoundError = Exception
17def download_revealjs(
18 temp_folder=".",
19 unzip_to=".",
20 fLOG=print,
21 force_download=False,
22 location="https://github.com/hakimel/reveal.js/releases",
23 clean=True,
24 version=None):
25 """
26 Download `reveal.js <https://github.com/hakimel/reveal.js/releases>`_ release.
27 and unzip it.
29 @param temp_folder where to download the setup
30 @param unzip_to where to unzip the files
31 @param fLOG logging function
32 @param install install (otherwise only download)
33 @param force_download force the downloading of pandoc
34 @param location location of reveal.js release
35 @param clean clean unnecessary files
36 @param version version to download (unused)
37 @return list of downloaded and unzipped files
38 """
39 if version is not None:
40 raise ValueError("cannot specify a version")
41 link = location
42 page = download_page(link)
43 reg = re.compile("href=\\\"(.*?[.]zip)\\\"")
44 alls = reg.findall(page)
45 if len(alls) == 0:
46 raise Exception(
47 "unable to find a link on a .zip file on page: " +
48 page)
50 filename = alls[0].split("/")[-1]
51 filel = location.replace("releases", "").rstrip(
52 "/") + "/archive/{0}".format(filename)
53 outfile = os.path.join(temp_folder, "reveal.js." + filename)
54 version = ".".join(filel.split("/")[-1].split(".")[:-1])
55 fLOG("[pymy] download ", filel, "to", outfile, "version", version)
56 local = download_file(filel, outfile)
57 res = unzip_files(local, whereTo=unzip_to, fLOG=fLOG)
59 master = os.path.join(unzip_to, "reveal.js-%s" % version)
60 if not os.path.exists(master):
61 raise FileNotFoundError("unable to find: " + master)
62 new_master = os.path.join(unzip_to, "reveal.js")
64 os.rename(master, new_master)
65 res = [r.replace(master, new_master) for r in res]
67 keep = []
68 for r in res:
69 if os.path.isdir(r):
70 continue
71 if ".gitignore" in r or ".travis.yml" in r or "index.html" in r \
72 or "README" in r or "CONTRIBUTING.md" in r:
73 os.remove(r)
74 elif "/test/" in r.replace("\\", "/"):
75 os.remove(r)
76 else:
77 keep.append(r)
79 return keep