-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_script.py
More file actions
76 lines (61 loc) · 2.72 KB
/
install_script.py
File metadata and controls
76 lines (61 loc) · 2.72 KB
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
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File : xlwings_install.py
@Author : Billy Zhou
@Time : 2021/10/26
@Desc : None
'''
import sys
from pathlib import Path
cwdPath = Path(__file__).parents[0] # the num depend on your filepath
sys.path.append(str(cwdPath))
from src.manager.LogManager import logmgr
log = logmgr.get_logger(__name__)
import os
import xlwings as xw
from subprocess import check_output
from src.setup.conda_check import find_conda_path
from src.setup.conda_check import add_conda_path
from src.setup.conda_check import check_conda_bat
from src.setup.conda_check import check_conda_settings
from src.setup.conda_check import create_conda_env
from src.setup.xlwings_check import install_xlwings_addin
from src.setup.xlwings_check import check_xlwings_config
if __name__ == '__main__':
# init
usr_folder = Path(os.path.expanduser('~'))
xlwings_filename = 'xlwings.xlam'
xlstart_path = usr_folder.joinpath(r'AppData\Roaming\Microsoft\Excel\XLSTART')
addins_path = usr_folder.joinpath(r'AppData\Roaming\Microsoft\AddIns')
xlstart_path.mkdir(parents=True, exist_ok=True)
addins_path.mkdir(parents=True, exist_ok=True)
# find the basepath of conda
conda_basepath = find_conda_path(folder_keyword='conda')
if False:
# check and add conda_basepath to sys path
add_conda_path(conda_basepath)
# check conda.bat and update conda environment variables
check_conda_bat(conda_basepath, add_path=True)
# check and update settings in .condarc file
check_conda_settings(usr_folder, force_to_cover=True)
# check and create conda env named pyexcel
create_conda_env('pyexcel', cwdPath.joinpath('requirements_conda_pyexcel_win.yaml'), force_to_install=True)
# check and add pyexcel to sys path
add_conda_path(conda_basepath.joinpath('envs\\pyexcel'))
if True:
# check and install xlwings addins
install_xlwings_addin(xlwings_filename, xlstart_path, addins_path, force_to_shutdown=False)
# check and update xlwings configs
check_xlwings_config(usr_folder.joinpath('.xlwings').joinpath('xlwings.conf'), conda_basepath, force_to_update=True)
# check and create PERSONAL.xlsb
if not xlstart_path.joinpath('PERSONAL.xlsb').exists():
wb = xw.Book()
wb.save(str(xlstart_path.joinpath('PERSONAL.xlsb')))
wb.app.kill()
print('PERSONAL.xlsb created')
try:
print('open the XLSTART path. Please import udf_scripts in PERSONAL.xlsb')
check_output('start %windir%\\explorer.exe {}'.format(xlstart_path), shell=True)
except Exception as e:
log.error('An error occurred. {}'.format(e.args))