-
Notifications
You must be signed in to change notification settings - Fork 0
/
embed.py
75 lines (61 loc) · 2.7 KB
/
embed.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
from pathlib import Path
import shutil, zipfile, argparse, os
dest = Path('dist')
source_dir = Path('msfs_livery_tools')
base_script = Path('livery_tools.py')
shell_script = Path('MSFS Livery Tools.bat')
site_packages = Path('venv', 'Lib', 'site-packages')
python_zip = Path('python.zip')
def data_files(folder:str, patterns:list[str])->tuple:
files = []
path = Path(folder)
for pattern in patterns:
for file in path.glob(pattern):
files.append(file)
return (folder, files)
if __name__ == '__main__':
if Path(os.getcwd()).resolve() != Path(__file__).parent.resolve():
print(f'This script should not be run out of "{Path(__file__).parent.resolve()}"!')
exit()
parser = argparse.ArgumentParser(description='Packs an MSFS Livery Tools distribution.')
parser.add_argument('python_zip', help='embed Python zip file')
args = parser.parse_args()
if dest.is_dir():
print(f'Removing "{dest}".')
shutil.rmtree(dest)
print(f'Creating destribution folder ({dest}).')
dest.mkdir()
print(f'Copying packages from "{site_packages}":')
for package in site_packages.iterdir():
if 'pip' not in package.name:
print(f'Copying package "{package.name}".')
try:
shutil.copytree(package, dest / package.name)
except NotADirectoryError:
shutil.copy(package, dest)
print('Copying source files.')
shutil.copytree(source_dir, dest / source_dir)
print('Copying resource files:')
(dest / 'resources').mkdir()
resources = [(data_files('resources', ['*.png', '*.ico', 'thumbnail.jpg']))]
resources.append((data_files('.', ['livery_tools.py', 'LICENSE', 'README.md', 'CHANGELOG.md'])))
for r in resources:
for file in r[1]:
print(f' {file} to {dest / r[0]}.')
shutil.copy(file, dest / r[0])
print('Copying base script.')
shutil.copy(base_script, dest)
print('Copying shell script.')
shutil.copy(shell_script, dest)
print('Copying tkinter and tcl packages and DLLs.')
import tkinter, _tkinter # sys.executable does not work
shutil.copytree(Path(tkinter.__file__).parent, dest / 'tkinter')
shutil.copytree(Path(tkinter.__file__).parent.parent.parent / 'tcl', dest / 'tcl')
for file in ('_tkinter.pyd', 'tcl86t.dll', 'tk86t.dll'):
shutil.copy(Path(_tkinter.__file__).parent / file, dest / file)
print('Copying idlelib package')
import idlelib
shutil.copytree(Path(idlelib.__file__).parent, dest / 'idlelib')
print('Unzipping embedable Python.')
with zipfile.ZipFile(args.python_zip, 'r') as zip_file:
zip_file.extractall(dest)