Coverage for src/pymyinstall/installcustom/install_custom_revealjs.py: 90%
41 statements
« prev ^ index » next coverage.py v7.1.0, created at 2023-07-19 01:47 +0200
« prev ^ index » next coverage.py v7.1.0, created at 2023-07-19 01:47 +0200
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 pattern="https://github.com/hakimel/reveal.js/archive/refs/tags/%s.zip",
23 location="https://github.com/hakimel/reveal.js/releases",
24 clean=True,
25 version="4.4.0"):
26 """
27 Download `reveal.js <https://github.com/hakimel/reveal.js/releases>`_ release.
28 and unzip it.
30 @param temp_folder where to download the setup
31 @param unzip_to where to unzip the files
32 @param fLOG logging function
33 @param install install (otherwise only download)
34 @param force_download force the downloading of pandoc
35 @param pattern url pattern if version is specified
36 @param location location of reveal.js release
37 @param clean clean unnecessary files
38 @param version version to download (unused)
39 @return list of downloaded and unzipped files
40 """
41 if version is None:
42 link = location
43 page = download_page(link)
44 reg = re.compile("href=\\\"(.*?[.]zip)\\\"")
45 alls = reg.findall(page)
46 if len(alls) == 0:
47 raise ValueError(
48 f"Unable to find a link on a .zip file on page: {page!r}.")
49 filename = alls[0].split("/")[-1]
50 filel = location.replace("releases", "").rstrip(
51 "/") + "/archive/{0}".format(filename)
52 else:
53 filel = pattern % version
54 filename = filel.split("/")[-1]
56 outfile = os.path.join(temp_folder, "reveal.js." + filename)
57 version = ".".join(filel.split("/")[-1].split(".")[:-1])
58 fLOG("[pymy] download ", filel, "to", outfile, "version", version)
59 local = download_file(filel, outfile)
60 res = unzip_files(local, whereTo=unzip_to, fLOG=fLOG)
62 master = os.path.join(unzip_to, "reveal.js-%s" % version)
63 if not os.path.exists(master):
64 raise FileNotFoundError("unable to find: " + master)
65 new_master = os.path.join(unzip_to, "reveal.js")
67 os.rename(master, new_master)
68 res = [r.replace(master, new_master) for r in res]
70 keep = []
71 for r in res:
72 if os.path.isdir(r):
73 continue
74 if ".gitignore" in r or ".travis.yml" in r or "index.html" in r \
75 or "README" in r or "CONTRIBUTING.md" in r:
76 os.remove(r)
77 elif "/test/" in r.replace("\\", "/"):
78 os.remove(r)
79 else:
80 keep.append(r)
82 return keep