Commit 47ce56b7 authored by Francesco Witz's avatar Francesco Witz
Browse files

feat: add json file copy during tool update

parent ce9fd37b
#!/usr/bin/python3
import os
from posixpath import splitext
import sys
import shutil
import subprocess
......@@ -131,7 +132,8 @@ def update():
# Updating tool by copying python files
os.chdir(path)
for filename in os.listdir('repo/'):
if filename[-2:] == "py":
ext: str = os.path.splitext(filename)[1][1:]
if ext == "py":
if filename == "chlog.py":
os.remove("chlog")
shutil.copy("repo/chlog.py", path)
......@@ -139,6 +141,26 @@ def update():
os.chmod("chlog", 0o711)
else:
shutil.copy(os.path.join("repo/", filename), path)
elif ext == "json":
if filename == "package.json":
# Update version in the installed tool package.json
with open("repo/package.json", 'r') as new_package:
data = json.load(new_package)
with open("package.json", 'r') as package:
package_json = json.load(package)
package_json["chlog-version"] = data["chlog-version"]
with open("package.json", "w") as package:
package.write(json.dumps(package_json))
elif filename == "config.json":
# First opening both actual and new config file
with open("config.json", 'r') as config_file:
config = json.load(config_file)
with open("repo/config.json", 'r') as new_config_file:
new_config = json.load(new_config_file)
# Then copying the new lines into the config file if their is any
for k, v in new_config.items():
if not k in config:
config[k] = v
print("Tool updated ! ✨")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment