Last active
May 15, 2021 19:42
-
-
Save TestPrab/c1981bda0b5c9c75fef67627db1e7000 to your computer and use it in GitHub Desktop.
Module Loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os.path | |
| import zipfile | |
| import tempfile | |
| import v2 | |
| import v3 | |
| from xml.dom import minidom | |
| def load_project(filepath): | |
| filepath=extract_project(filepath) | |
| if os.path.isfile(os.path.join(filepath, "bcf.version")): | |
| version_path = os.path.join(filepath, "bcf.version") | |
| versionid = get_version(version_path) | |
| if versionid == "2.1": | |
| from src.bcf.bcf.v2.bcfxml import BcfXml | |
| bcfxml=BcfXml() | |
| bcfxml.filepath=filepath | |
| return bcfxml | |
| else: | |
| return v3.bcfxml | |
| def get_version(version_path): | |
| xmlparse = minidom.parse(version_path) | |
| version_el = xmlparse.getElementsByTagName("Version")[0] | |
| version = version_el.getAttribute("VersionId") | |
| return version | |
| def extract_project(filepath): | |
| if not filepath: | |
| return | |
| zip_file = zipfile.ZipFile(filepath) | |
| filepath = tempfile.mkdtemp() | |
| zip_file.extractall(filepath) | |
| return filepath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment