This repository has been archived by the owner on Feb 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmerge_platform_binaries.py
56 lines (33 loc) · 1.65 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 zipfile
from tempfile import mkdtemp
from shutil import rmtree
import shutil
import os
repo_dir = os.path.dirname(__file__)
test_fmus_version = '0.0.2'
def merge(fmi_version, fmi_types):
for fmi_type in fmi_types:
platforms_dir = os.path.join(repo_dir, 'fmus', fmi_version, fmi_type)
_, platforms, _ = next(os.walk(platforms_dir))
version_dir = os.path.join(repo_dir, 'fmus', fmi_version, fmi_type, platforms[0], 'Test-FMUs', test_fmus_version)
_, model_names, _ = next(os.walk(version_dir))
for model_name in model_names:
tempdir = mkdtemp()
for platform in platforms:
platform_fmu = os.path.join(repo_dir, 'fmus', fmi_version, fmi_type, platform, 'Test-FMUs', test_fmus_version, model_name, model_name + '.fmu')
if not os.path.isfile(platform_fmu):
continue
with zipfile.ZipFile(platform_fmu, 'r') as archive:
archive.extractall(path=tempdir)
if len(fmi_types) > 1:
merged_fmu = os.path.join(repo_dir, 'merged', fmi_version, fmi_type, model_name + '.fmu')
else:
merged_fmu = os.path.join(repo_dir, 'merged', fmi_version, model_name + '.fmu')
os.makedirs(os.path.dirname(merged_fmu), exist_ok=True)
shutil.make_archive(merged_fmu, 'zip', tempdir)
os.rename(merged_fmu + '.zip', merged_fmu)
rmtree(tempdir, ignore_errors=True)
merge('1.0', ['cs', 'me'])
merge('2.0', ['cs'])
merge('3.0', ['cs'])
shutil.make_archive(os.path.join(repo_dir, 'merged_fmus'), 'zip', os.path.join(repo_dir, 'merged'))