|
1 | 1 | """bim2sim library""" |
2 | | - |
3 | | -import os |
4 | | -import re |
5 | | -import sys |
6 | | - |
7 | | -import tempfile |
8 | | -from os.path import expanduser |
| 2 | +from importlib.metadata import version |
9 | 3 |
|
10 | 4 | from bim2sim.kernel.decision.console import ConsoleDecisionHandler |
11 | 5 | from bim2sim.kernel.decision.decisionhandler import DecisionHandler |
12 | 6 | from bim2sim.project import Project |
13 | 7 |
|
14 | | -VERSION = '0.1-dev' |
| 8 | + |
| 9 | +try: |
| 10 | + __version__ = version("bim2sim") |
| 11 | +except Exception: |
| 12 | + __version__ = "unknown" |
15 | 13 |
|
16 | 14 |
|
17 | 15 | def run_project(project: Project, handler: DecisionHandler): |
18 | 16 | """Run project using decision handler.""" |
19 | 17 | return handler.handle(project.run(), project.loaded_decisions) |
20 | | - |
21 | | - |
22 | | -def _debug_run_hvac(): |
23 | | - """Create example project and copy ifc if necessary""" |
24 | | - path_base = os.path.abspath(os.path.join(os.path.dirname(__file__), "..\\..")) |
25 | | - rel_example = 'ExampleFiles/KM_DPM_Vereinshaus_Gruppe62_Heizung_with_pumps.ifc' |
26 | | - path_ifc = os.path.normpath(os.path.join(path_base, rel_example)) |
27 | | - path_example = _get_debug_project_path('hvac') |
28 | | - |
29 | | - if Project.is_project_folder(path_example): |
30 | | - project = Project(path_example) |
31 | | - else: |
32 | | - project = Project.create(path_example, path_ifc, 'hkesim', ) |
33 | | - |
34 | | - # setup_defualt(project.config['Frontend']['use']) |
35 | | - run_project(project, ConsoleDecisionHandler()) |
36 | | - |
37 | | - |
38 | | -def _get_debug_project_path(aux): |
39 | | - path_file = "debug_dir.user" |
40 | | - try: |
41 | | - f = open(path_file) |
42 | | - path_example = f.read() |
43 | | - f.close() |
44 | | - except IOError: |
45 | | - path_example = str(input("Specify debug root path (Leave blank for '" + expanduser('~') |
46 | | - + "'). This value will be remembered in '" + path_file + "': ")) |
47 | | - if len(path_example) == 0: |
48 | | - path_example = expanduser('~') |
49 | | - f = open(path_file, 'a') |
50 | | - f.write(path_example) |
51 | | - f.close() |
52 | | - |
53 | | - if not path_example.endswith("/"): |
54 | | - path_example += "/" |
55 | | - |
56 | | - max_number = 0 |
57 | | - for item in os.listdir(path_example): |
58 | | - m = re.search('testproject_%s([0-9]+)' % aux, item) |
59 | | - if m: |
60 | | - max_number = max(int(m.group(1)), max_number) |
61 | | - |
62 | | - return path_example + "testproject_%s" % aux + str(max_number + 1) |
63 | | - |
64 | | - |
65 | | -def _debug_run_bps(): |
66 | | - """Create example project and copy ifc if necessary""" |
67 | | - path_base = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) |
68 | | - |
69 | | - # rel_example = 'ExampleFiles/AC20-FZK-Haus.ifc' |
70 | | - # rel_example = 'ExampleFiles/KM_DPM_Vereinshaus_Gruppe62_Architektur_spaces.ifc' |
71 | | - rel_example = 'ExampleFiles/AC20-Institute-Var-2.ifc' |
72 | | - path_ifc = os.path.normpath(os.path.join(path_base, rel_example)) |
73 | | - path_example = _get_debug_project_path('bps') |
74 | | - |
75 | | - if Project.is_project_folder(path_example): |
76 | | - project = Project(path_example) |
77 | | - else: |
78 | | - project = Project.create(path_example, path_ifc, 'teaser', ) |
79 | | - |
80 | | - run_project(project, ConsoleDecisionHandler()) |
81 | | - |
82 | | - |
83 | | -def _debug_run_bps_ep(): |
84 | | - """Create example project and copy ifc if necessary""" |
85 | | - path_base = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) |
86 | | - |
87 | | - rel_example = 'ExampleFiles/AC20-FZK-Haus.ifc' |
88 | | - # rel_example = 'ResultFiles/AC20-FZK-Haus_with_SB44.ifc' # aktuell |
89 | | - # rel_example = 'ResultFiles/Proposal_1_Storey_SpaceBoundaries_with_SB.ifc' |
90 | | - # rel_example = 'ResultFiles/2020-10-15-KHH-Test_with_SB.ifc' |
91 | | - # rel_example = 'ExampleFiles/AC20-Institute-Var-2.ifc' |
92 | | - # rel_example = 'ExampleFiles/DigitalHub_Architektur2_2020_Achse_tragend_V2.ifc' # ok |
93 | | - rel_example = 'ResultFiles/FM_ARC_DigitalHub_with_SB89.ifc' |
94 | | - # ok |
95 | | - # rel_example = 'ExampleFiles/AC-20-Smiley-West-10-Bldg.ifc' |
96 | | - path_ifc = os.path.normpath(os.path.join(path_base, rel_example)) |
97 | | - |
98 | | - path_example = _get_debug_project_path('bps_ep') |
99 | | - |
100 | | - if Project.is_project_folder(path_example): |
101 | | - project = Project(path_example) |
102 | | - else: |
103 | | - project = Project.create(path_example, path_ifc, 'energyplus', ) |
104 | | - |
105 | | - run_project(project, ConsoleDecisionHandler()) |
106 | | - |
107 | | - |
108 | | -def _test_run_bps_ep(rel_path, temp_project=False): |
109 | | - """Create example project and copy ifc if necessary. Added for EnergyPlus integration tests""" |
110 | | - path_base = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) |
111 | | - |
112 | | - path_ifc = os.path.normpath(os.path.join(path_base, rel_path)) |
113 | | - |
114 | | - if not temp_project: |
115 | | - path_example = _get_debug_project_path('bps_ep') |
116 | | - else: |
117 | | - path_example = tempfile.mkdtemp() |
118 | | - |
119 | | - old_stderr = sys.stderr |
120 | | - working_dir = os.getcwd() |
121 | | - success = False |
122 | | - if Project.is_project_folder(path_example): |
123 | | - project = Project(path_example) |
124 | | - else: |
125 | | - project = Project.create(path_example, path_ifc, 'energyplus', ) |
126 | | - |
127 | | - try: |
128 | | - print("Project directory: " + path_example) |
129 | | - os.chdir(path_example) |
130 | | - if Project.is_project_folder(path_example): |
131 | | - project = Project(path_example) |
132 | | - else: |
133 | | - project = Project.create(path_example, path_ifc, 'energyplus', ) |
134 | | - |
135 | | - #HACK: We have to remember stderr because eppy resets it currently. |
136 | | - success = run_project(project, ConsoleDecisionHandler()) |
137 | | - finally: |
138 | | - os.chdir(working_dir) |
139 | | - sys.stderr = old_stderr |
140 | | - return success |
141 | | - |
142 | | - |
143 | | -def _debug_run_hvac_aixlib(): |
144 | | - """Create example project and copy ifc if necessary""" |
145 | | - path_base = os.path.abspath(os.path.join(os.path.dirname(__file__), "..\\..")) |
146 | | - rel_example = 'ExampleFiles/KM_DPM_Vereinshaus_Gruppe62_Heizung_with_pumps.ifc' |
147 | | - path_ifc = os.path.normpath(os.path.join(path_base, rel_example)) |
148 | | - path_example = _get_debug_project_path('aix') |
149 | | - |
150 | | - if Project.is_project_folder(path_example): |
151 | | - project = Project(path_example) |
152 | | - else: |
153 | | - project = Project.create(path_example, path_ifc, 'aixlib', ) |
154 | | - |
155 | | - project.run() |
156 | | - |
0 commit comments