Skip to content

Commit

Permalink
work on #280, quater
Browse files Browse the repository at this point in the history
  • Loading branch information
servoz committed Nov 4, 2023
1 parent 242c48f commit 7cf927f
Showing 1 changed file with 58 additions and 7 deletions.
65 changes: 58 additions & 7 deletions populse_mia/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,28 @@ def _verify_miaConfig(dialog=None):
else:
mia_home_properties_path = yaml.load(stream)

if mia_home_properties_path is None or not isinstance(
mia_home_properties_path, dict
):
raise yaml.YAMLError(
"\nThe '{}' file seems to be "
"corrupted...\n".format(dot_mia_config)
)

# if (DEV_MODE and "properties_dev_path"
# not in mia_home_properties_path):
# raise yaml.YAMLError(
# "\nNo properties path found in {}..."
# "\n".format(dot_mia_config)
# )
#
# elif (not DEV_MODE and "properties_user_path"
# not in mia_home_properties_path):
# raise yaml.YAMLError(
# "\nNo properties path found in {}..."
# "\n".format(dot_mia_config)
# )

except yaml.YAMLError:
print(
"\n ~/.populse_mia/configuration.yml cannot be read,"
Expand Down Expand Up @@ -850,6 +872,12 @@ def _verify_miaConfig(dialog=None):
**mia_home_properties_path_new,
}

key_to_keep = ("properties_dev_path", "properties_user_path")

for k in mia_home_properties_path:
if k not in key_to_keep:
del mia_home_properties_path[k]

with open(dot_mia_config, "w", encoding="utf8") as configfile:
yaml.dump(
mia_home_properties_path,
Expand Down Expand Up @@ -916,14 +944,18 @@ def _verify_miaConfig(dialog=None):
os.path.expanduser("~"), ".populse_mia", "configuration.yml"
)

try:
if not os.path.exists(os.path.dirname(dot_mia_config)):
os.mkdir(os.path.dirname(dot_mia_config))
print(
"\nThe {0} directory is created "
"...".format(os.path.dirname(dot_mia_config))
)
if not os.path.exists(os.path.dirname(dot_mia_config)):
os.mkdir(os.path.dirname(dot_mia_config))
print(
"\nThe {0} directory is created "
"...".format(os.path.dirname(dot_mia_config))
)
Path(os.path.join(dot_mia_config)).touch()

if not os.path.exists(dot_mia_config):
Path(os.path.join(dot_mia_config)).touch()

try:
# Just to check if dot_mia_config file is well readable/writeable
with open(dot_mia_config, "r") as stream:
if version.parse(yaml.__version__) > version.parse("5.1"):
Expand All @@ -934,6 +966,25 @@ def _verify_miaConfig(dialog=None):
else:
mia_home_properties_path = yaml.load(stream)

if mia_home_properties_path is None:
raise yaml.YAMLError(
"\nThe '{}' file seems to be "
"corrupted...\n".format(dot_mia_config)
)

if DEV_MODE and "properties_dev_path" not in mia_home_properties_path:
raise yaml.YAMLError(
"\nNo properties path found in {}...\n".format(dot_mia_config)
)

elif (
not DEV_MODE
and "properties_user_path" not in mia_home_properties_path
):
raise yaml.YAMLError(
"\nNo properties path found in {}...\n".format(dot_mia_config)
)

with open(dot_mia_config, "w", encoding="utf8") as configfile:
yaml.dump(
mia_home_properties_path,
Expand Down

0 comments on commit 7cf927f

Please sign in to comment.