[DEV] change the configuration file

This commit is contained in:
Edouard DUPIN 2019-07-31 00:43:56 +02:00
parent 78f559ec21
commit 3f51e9e35c
2 changed files with 41 additions and 5 deletions

View File

@ -30,8 +30,9 @@ class Config():
self.load()
def load(self):
config_property = tools.file_read_data(env.get_island_path_config())
# set it deprecated at 2020/07
def load_old(self):
config_property = tools.file_read_data(env.get_island_path_config_old())
element_config = config_property.split("\n")
for line in element_config:
if len(line) == 0 \
@ -48,9 +49,39 @@ class Config():
debug.warning("island config error: can not parse: '" + str(line) + "'")
return True
def convert_config_file(self):
debug.warning("INTERNAL: Convert your configuration file: " + str(env.get_island_path_config_old()) + " -> " + str(env.get_island_path_config()))
self.load_old()
self.store()
tools.remove_file(env.get_island_path_config_old())
def load(self):
# transform the old format of configuration (use json now ==> simple
if os.path.exists(env.get_island_path_config_old()) == True:
self.convert_config_file()
if os.path.exists(env.get_island_path_config()) == False:
return True
self._volatiles = []
with open(env.get_island_path_config()) as json_file:
data = json.load(json_file)
if "repo" in data.keys():
self._repo = data["repo"]
if "branch" in data.keys():
self._branch = data["branch"]
if "manifest_name" in data.keys():
self._manifest_name = data["manifest_name"]
return True
return False
def store(self):
data = "repo=" + self._repo + "\nbranch=" + self._branch + "\nfile=" + self._manifest_name
tools.file_write_data(env.get_island_path_config(), data)
data = {}
data["repo"] = self._repo
data["branch"] = self._branch
data["manifest_name"] = self._manifest_name
with open(env.get_island_path_config(), 'w') as outfile:
json.dump(data, outfile, indent=4)
return True
return False
def set_manifest(self, value):
self._repo = value

View File

@ -102,7 +102,8 @@ else:
pass
island_path_user_config = os.path.join(island_root_path, get_system_config_name())
island_path = os.path.join(island_root_path, "." + get_system_base_name())
island_path_config = os.path.join(island_path, "config.txt")
island_path_config_old = os.path.join(island_path, "config.txt")
island_path_config = os.path.join(island_path, "config.json")
island_path_manifest = os.path.join(island_path, "manifest")
##
@ -121,6 +122,10 @@ def get_island_path_config():
global island_path_config
return island_path_config
def get_island_path_config_old():
global island_path_config_old
return island_path_config_old
def get_island_path_manifest():
global island_path_manifest
return island_path_manifest