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 Customizes a Windows Setup for these teachings.
4"""
6import os
7import shutil
9from pyquickhelper.filehelper import remove_folder
12def last_function(innosetup, folders, verbose=False, fLOG=print):
13 """
14 Applies last modifications to the setup.
16 @param innosetup innosetup script which defines the setup
17 @param folders dictionary with keys *workspace*, *python*, *tools*, *build*, *docs*
18 @param verbose verbose
19 @param fLOG logging function
20 """
21 from pymyinstall.win_installer.win_setup_r import r_run_script
23 work = folders["workspace"]
24 python = folders["python"]
25 tools = folders["tools"]
26 build = os.path.join(folders["build"], "custom_ensae_teaching_cs")
27 docs = os.path.join(work, "docs")
28 logs = folders["logs"]
29 this = os.path.abspath(os.path.dirname(__file__))
30 doc_annee = [os.path.join(this, "..", "..", "..", "_doc", "notebooks", sub)
31 for sub in ["td1a", "td2a", "td3a", "1a", "2a", "expose"]]
33 if not os.path.exists(build):
34 os.mkdir(build)
36 # folders
37 fLOG("folders:", folders)
38 fLOG("innosetup:", innosetup)
40 # docs
41 fLOG("--- cleaning creating folder", docs)
42 if os.path.exists(docs):
43 remove_folder(docs)
44 os.mkdir(docs)
46 # RSS
47 fLOG("--- update rss.list.xml")
48 # flake8 is no happy with: from .. import __blog__
49 __blog__ = os.path.abspath(os.path.join(
50 os.path.dirname(__file__), "..", "rss_teachings.xml"))
52 rssfile = os.path.join(folders["config"], "rss_list.xml")
53 shutil.copy(__blog__, rssfile)
55 # R_install
56 fLOG("--- R install")
57 r_script = os.path.join(os.path.dirname(__file__), "R_install.r")
58 if os.path.exists(r_script):
59 r_run_script(os.path.join(tools, "R"), r_script, os.path.join(
60 logs, "r_ensae_teaching_cs.install.log.txt"))
62 # documentation
63 fLOG("--- documentation, TDs +++")
64 for dist in doc_annee:
65 end = os.path.split(dist)[-1]
66 to = os.path.join(docs, end)
67 if not os.path.exists(to):
68 os.mkdir(to)
69 for ipy in os.listdir(dist):
70 if ipy.endswith("ipynb"):
71 if verbose:
72 fLOG("copy ", ipy)
73 full = os.path.join(dist, ipy)
74 shutil.copy(full, to)
76 # others packages not from Microsoft
77 from pymyinstall import ModuleInstall
78 from pymyinstall.win_installer.win_packages import win_install_package_other_python, is_package_installed
80 # modules
81 modules = [ModuleInstall("pyquickhelper", "pip"),
82 ModuleInstall("pyensae", "pip"),
83 ModuleInstall("pyrsslocal", "pip"),
84 ModuleInstall("code_beatrix", "pip"),
85 ModuleInstall("pymmails", "pip"),
86 ModuleInstall("pymyinstall", "pip"),
87 ModuleInstall("ensae_teaching_cs", "pip"),
88 ModuleInstall("actuariat_python", "pip"),
89 ]
91 # new packages
92 fLOG("--- download new packages")
93 pack = []
94 for mod in modules:
95 mname = mod.mname if mod.mname is not None else mod.name
96 if not is_package_installed(python, [mod.name, mname]):
97 fLOG("download:", mod.name)
98 p = mod.download(temp_folder=build)
99 pack.append((p, mod))
101 # install packages
102 fLOG("--- install packages")
103 for p, mod in pack:
104 fLOG("install", os.path.split(p)[-1])
105 win_install_package_other_python(python, p, verbose=verbose, fLOG=fLOG)
107 # remove unnecessary folders
108 fLOG("--- remove too big folfers")
109 to_remove = []
110 for rem in to_remove:
111 sub = os.path.join(python, rem)
112 if os.path.exists(sub):
113 fLOG("remove", sub)
114 remove_folder(sub)
116 # modifies the setup
117 fLOG("--- modifies the setup")
118 with open(innosetup, "r", encoding="utf8") as f:
119 content = f.read()
120 with open(innosetup, "w", encoding="utf8") as f:
121 f.write(content)