Skip to content

Commit

Permalink
added project json key rewriting and addition (#122)
Browse files Browse the repository at this point in the history
* added project json key rewriting and addition

* deleted obsolete imports

* @wip generalize find key function

* fixed it

* bugfixed multiple core entries

* Apply suggestions from code review

Co-authored-by: Jan Max Meyer <[email protected]>

* added recommendations

* deleted comments

* deleted obsolete level in findkey

* resolved conflicts

---------

Co-authored-by: Jan Max Meyer <[email protected]>
  • Loading branch information
Grashalmbeisser and phorward authored Apr 11, 2024
1 parent 4fca024 commit 49aaf77
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/viur_cli/conf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import json
from pprint import pprint

import click
import requests
import difflib
from .utils import *
from .version import __version__ as cli_version


PROJECT_CONFIG_FILE = "project.json"
PROJECT_CONFIG_VERSION = "2.0.0"
LAST_VERSION = ""
Expand Down Expand Up @@ -86,7 +89,30 @@ def delete(self):
except:
raise click.ClickException(click.style(f"{configname} not found", fg="red"))

def find_key(self, dictionary, target_key, target):
if target_key in dictionary:
value = dictionary.pop(target_key)
if not target:
self[target_key] = value
else:
self.setdefault(target, {})[target_key] = value
else:
for value in list(dictionary.values()):
if isinstance(value, dict):
self.find_key(value, target_key, target)

def migrate(self):

if "application_name" not in self["default"]:
self.find_key(self, target_key="application_name", target="default")
if "application_name" in self:
del self["application_name"]

#check if core is in any profile
if "core" not in self:
self.find_key(self, target_key="core", target=None)


if old_format := self["default"].get("format"):
self["format"] = old_format
del self["default"]["format"]
Expand Down Expand Up @@ -159,10 +185,11 @@ def migrate(self):
)

if response == "yes":
del self["default"]["builds"]["vi"]
self["default"]["builds"].pop("vi", None)
echo_info("You are using the ViUR Admin")
elif response == "no":
del self["default"]["builds"]["admin"]

self["default"]["builds"].pop("admin", None)
echo_info("You are using the Vi Administration")
"""
Fetch the version of the 'viur-core' package.
Expand All @@ -174,10 +201,10 @@ def migrate(self):
try:
result = os.popen('pip list --format=json').read()
core_version = [x for x in json.loads(result) if x["name"] == "viur-core"][0]["version"]
self["default"]["core"] = core_version
self["core"] = core_version

except:
self["default"]["core"] = "submodule"
self["core"] = "submodule"

# conf updates must increase format version
self.save()
Expand Down

0 comments on commit 49aaf77

Please sign in to comment.