This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
install_custom.py
79 lines (70 loc) · 2.63 KB
/
install_custom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
@file
@brief Various function to install some application such as `pandoc <http://johnmacfarlane.net/pandoc/>`_.
"""
from __future__ import print_function
import re
import os
from ..filehelper import download, read_url
from ..loghelper.flog import unzip_files
from ..filehelper.synchelper import explore_folder_iterfile
def download_revealjs(
temp_folder=".",
unzip_to=".",
fLOG=print,
location="https://github.com/hakimel/reveal.js/releases",
clean=True):
"""
Download `reveal.js <https://github.com/hakimel/reveal.js/releases>`_ release.
and unzip it.
@param temp_folder where to download the setup
@param unzip_to where to unzip the files
@param fLOG logging function
@param install install (otherwise only download)
@param location location of reveal.js release
@param clean clean unnecessary files
@return list of downloaded and unzipped files
"""
link = location
page = read_url(link, encoding="utf8")
reg = re.compile("href=\\\"(.*?[0-9.]+?[.]zip)\\\"")
alls = reg.findall(page)
if len(alls) == 0:
raise Exception(
"unable to find a link on a .zip file on page: " +
page)
filename = alls[0].split("/")[-1]
filel = location.replace("releases", "") + "/archive/{0}".format(filename)
outfile = os.path.join(temp_folder, "reveal.js." + filename)
fLOG("download ", filel, "to", outfile)
local = download(filel, temp_folder, fLOG=fLOG)
fLOG("local file", local)
unzip_files(local, where_to=unzip_to)
# we rename
sub = [_ for _ in os.listdir(unzip_to) if "reveal" in _]
if len(sub) != 1:
raise FileNotFoundError(
"several version exists or noe of them:\n{0}".format(", ".join(sub)))
sub = sub[0]
master = os.path.join(unzip_to, sub)
if not os.path.exists(master):
raise FileNotFoundError("unable to find: " + master)
new_master = os.path.join(unzip_to, "reveal.js")
os.rename(master, new_master)
if clean:
# we clean some files
res = explore_folder_iterfile(new_master)
keep = []
for r in res:
if os.path.isdir(r):
continue
if ".gitignore" in r or ".travis.yml" in r or "index.html" in r \
or "README" in r or "CONTRIBUTING.md" in r:
os.remove(r)
elif "/test/" in r.replace("\\", "/"):
os.remove(r)
else:
keep.append(r)
# we clean the downloaded file
os.remove(local)
return keep