Skip to content

Commit

Permalink
add encoding when reading/patching qgis file
Browse files Browse the repository at this point in the history
  • Loading branch information
KatKatKateryna committed Oct 29, 2023
1 parent 1a42669 commit ba8bf0d
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions patch_version.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,65 @@
import re
import sys


def patch_installer(tag):
"""Patches the installer with the correct connector version and specklepy version"""
iss_file = "speckle-sharp-ci-tools/qgis.iss"
metadata = "metadata.txt"
plugin_start_file = "speckle_qgis.py"

#conda_file = "speckle_arcgis_installer/conda_clone_activate.py"
#toolbox_install_file = "speckle_arcgis_installer/toolbox_install.py"
#toolbox_manual_install_file = "speckle_arcgis_installer/toolbox_install_manual.py"

#py_tag = get_specklepy_version()
try:
with open(iss_file, "r") as file:
lines = file.readlines()
new_lines = []
for i, line in enumerate(lines):
if "#define AppVersion " in line:
if "#define AppVersion " in line:
line = f'#define AppVersion "{tag.split("-")[0]}"\n'
if "#define AppInfoVersion " in line:
if "#define AppInfoVersion " in line:
line = f'#define AppInfoVersion "{tag}"\n'
new_lines.append(line)
with open(iss_file, "w") as file:
file.writelines(new_lines)
print(f"Patched installer with connector v{tag} ")
file.close()
except: pass

except:
pass

with open(metadata, "r") as file:
lines = file.readlines()
new_lines = []
for i, line in enumerate(lines):
if "version=" in line:
line = f'version={tag}\n'#.split("-")[0]
if "experimental=" in line:
if "version=" in line:
line = f"version={tag}\n" # .split("-")[0]
if "experimental=" in line:
if "-" in tag:
line = f'experimental=True\n'#.split("-")[0]
elif len(tag.split("."))==3 and tag!="0.0.99":
line = f'experimental=False\n'#.split("-")[0]
line = f"experimental=True\n" # .split("-")[0]
elif len(tag.split(".")) == 3 and tag != "0.0.99":
line = f"experimental=False\n" # .split("-")[0]
new_lines.append(line)
with open(metadata, "w") as file:
file.writelines(new_lines)
print(f"Patched metadata v{tag} ")
file.close()


with open(plugin_start_file, "r") as file:
with open(plugin_start_file, "r", encoding="utf8") as file:
lines = file.readlines()
for i, line in enumerate(lines):
if 'self.version = ' in line:
lines[i] = lines[i].split("\"")[0] + "\"" + tag.split('-')[0] + "\"" + lines[i].split("\"")[2]
if "self.version = " in line:
lines[i] = (
lines[i].split('"')[0]
+ '"'
+ tag.split("-")[0]
+ '"'
+ lines[i].split('"')[2]
)
break
with open(plugin_start_file, "w") as file:
file.writelines(lines)
print(f"Patched GIS start file with connector v{tag} and specklepy ")
file.close()

r'''
r"""
def whlFileRename(fileName: str):
with open(fileName, "r") as file:
lines = file.readlines()
Expand All @@ -76,7 +77,7 @@ def whlFileRename(fileName: str):
whlFileRename(conda_file)
whlFileRename(toolbox_install_file)
whlFileRename(toolbox_manual_install_file)
'''
"""


def main():
Expand All @@ -88,9 +89,9 @@ def main():
raise ValueError(f"Invalid tag provided: {tag}")

print(f"Patching version: {tag}")
#patch_connector(tag.split("-")[0]) if I need to edit a connector file
# patch_connector(tag.split("-")[0]) if I need to edit a connector file
patch_installer(tag)


if __name__ == "__main__":
main()
main()

0 comments on commit ba8bf0d

Please sign in to comment.