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 #!/usr/bin/python3
import os import os
from posixpath import splitext
import sys import sys
import shutil import shutil
import subprocess import subprocess
...@@ -131,7 +132,8 @@ def update(): ...@@ -131,7 +132,8 @@ def update():
# Updating tool by copying python files # Updating tool by copying python files
os.chdir(path) os.chdir(path)
for filename in os.listdir('repo/'): for filename in os.listdir('repo/'):
if filename[-2:] == "py": ext: str = os.path.splitext(filename)[1][1:]
if ext == "py":
if filename == "": if filename == "":
os.remove("chlog") os.remove("chlog")
shutil.copy("repo/", path) shutil.copy("repo/", path)
...@@ -139,6 +141,26 @@ def update(): ...@@ -139,6 +141,26 @@ def update():
os.chmod("chlog", 0o711) os.chmod("chlog", 0o711)
else: else:
shutil.copy(os.path.join("repo/", filename), path) 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:
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 ! ✨") 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