forked from modelica/Reference-FMUs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge_platform_binaries.py
56 lines (33 loc) · 1.55 KB
/
merge_platform_binaries.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
import shutil
import zipfile
from pathlib import Path
from tempfile import mkdtemp
from shutil import rmtree, make_archive
import os
root = Path(__file__).parent
os.makedirs(root / 'fmus-merged', exist_ok=True)
def merge_fmus(version):
for dirpath, dirnames, filenames in os.walk(root / 'fmus-linux' / version):
for filename in filenames:
tempdir = mkdtemp()
for platform in ['linux', 'windows']:
platform_fmu = root / f'fmus-{platform}' / version / filename
with zipfile.ZipFile(platform_fmu, 'r') as archive:
archive.extractall(path=tempdir)
merged_fmu = os.path.join(root, 'fmus-merged', version, filename)
make_archive(merged_fmu, 'zip', tempdir)
os.rename(merged_fmu + '.zip', merged_fmu)
rmtree(tempdir, ignore_errors=True)
for version in ['1.0/cs', '1.0/me', '2.0', '3.0']:
merge_fmus(version)
results_dir = root / 'fmus-merged' / 'results'
os.makedirs(results_dir, exist_ok=True)
# copy reference results
for model in ['BouncingBall', 'Clocks', 'Dahlquist', 'Feedthrough', 'LinearTransform', 'Resource', 'Stair', 'VanDerPol']:
shutil.copyfile(src=root / model / f'{model}_ref.csv', dst=results_dir / f'{model}_ref.csv')
# copy license and readme
for file in ['LICENSE.txt', 'README.md']:
shutil.copyfile(src=root / file, dst=root / 'fmus-merged' / file)
# make_archive(base_name=root / 'fmus-merged', format='zip', root_dir=root / 'merged')
# clean up
rmtree(os.path.join(root, 'merged'), ignore_errors=True)