MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / patch

Method patch

src/ifcpatch/ifcpatch/recipes/Ifc2Sql.py:157–244  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

155 (mysql doesn't convert them automatically, unlike sqlite)"""
156
157 def patch(self) -> None:
158 if self.sql_type == "sqlite":
159 database = Path(self.database)
160 if database.is_dir():
161 database = database / DEFAULT_DATABASE_NAME
162 elif not database.parent.exists():
163 database.parent.mkdir(parents=True, exist_ok=True)
164 else:
165 # Assume it's a filepath - existing or not.
166 pass
167
168 if database.suffix.lower() not in (".sqlite", ".db", ".ifcsqlite"):
169 database = database.with_suffix(database.suffix + ".sqlite")
170 database = str(database)
171 elif self.sql_type == "mysql":
172 database = self.database
173 else:
174 assert False
175
176 self.schema = ifcopenshell.schema_by_name(self.file.schema_identifier)
177
178 if self.sql_type == "sqlite":
179 self.db = sqlite3.connect(database)
180 self.c = self.db.cursor()
181 self.file_patched = database
182 elif self.sql_type == "mysql":
183 self.db = mysql.connector.connect(
184 host=self.host, user=self.username, password=self.password, database=database
185 )
186 self.c = self.db.cursor()
187 self.file_patched = None
188 else:
189 assert False
190
191 self.check_existing_ifc_database()
192 self.create_id_map()
193 self.create_metadata()
194
195 if self.should_get_psets:
196 self.create_pset_table()
197
198 if self.should_get_geometry:
199 self.create_geometry_table()
200 self.create_geometry()
201
202 if self.full_schema:
203 ifc_classes = [
204 d.name() for d in self.schema.declarations() if isinstance(d, ifcopenshell.ifcopenshell_wrapper.entity)
205 ]
206 else:
207 ifc_classes = self.file.wrapped_data.types()
208
209 for ifc_class in ifc_classes:
210 declaration = self.schema.declaration_by_name(ifc_class)
211
212 if self.should_skip_geometry_data:
213 if ifcopenshell.util.schema.is_a(declaration, "IfcRepresentation") or ifcopenshell.util.schema.is_a(
214 declaration, "IfcRepresentationItem"

Callers 4

get_ifc_sqliteFunction · 0.95
executeFunction · 0.95
test_runMethod · 0.95

Calls 15

create_id_mapMethod · 0.95
create_metadataMethod · 0.95
create_pset_tableMethod · 0.95
create_geometry_tableMethod · 0.95
create_geometryMethod · 0.95
create_sqlite_tableMethod · 0.95
create_mysql_tableMethod · 0.95
insert_dataMethod · 0.95
lowerMethod · 0.80
schema_by_nameMethod · 0.80
connectMethod · 0.80

Tested by 3

get_ifc_sqliteFunction · 0.76
test_runMethod · 0.76