moves cbpi_dashboard_*.json to dashboard folder.

if the file cbpi_dashboard_1.json doesnt exist in the dashboard folder
every cbpi_dashboard_*.json file from the config folder is moved to the dashboard folder.
This also removes the empty default cbpi_dashboard_1.json file from the template folder,
because the file is not needed for cbpi to function and can be created when editing the dashboard online.
This commit is contained in:
prash3r 2022-10-02 18:32:40 +02:00
parent 8c8d09ed72
commit 2a0daf354c
3 changed files with 9 additions and 8 deletions

View file

@ -1,3 +0,0 @@
{
"elements": []
}

View file

@ -1,3 +0,0 @@
{
"elements": []
}

View file

@ -96,13 +96,13 @@ class ConfigFolder:
['config.json', 'file'],
['craftbeerpi.service', 'file'],
['chromium.desktop', 'file'],
['dashboard/cbpi_dashboard_1.json', 'file'],
['dashboard/widgets', 'folder'],
['dashboard', 'folder'],
['dashboard/widgets', 'folder'],
['fermenterrecipes', 'folder'],
[self.logsFolderPath, 'folder'],
['recipes', 'folder'],
['upload', 'folder']
#['dashboard/cbpi_dashboard_1.json', 'file'] no need to check - can be created with online editor
]
for checking in required_config_content:
if self.inform_missing_content(self.check_for_file_or_folder(os.path.join(self.configFolderPath, checking[0]), checking[1])):
@ -118,6 +118,13 @@ class ConfigFolder:
print("***************************************************")
return False
# if cbpi_dashboard_1.json doesnt exist at the new location (configFolderPath/dashboard)
# we move every cbpi_dashboard_n.json file from the old location (configFolderPath) there.
# this could be a config zip file restore from version 4.0.7.a4 or prior.
if not (os.path.isfile(os.path.join(self.configFolderPath, 'dashboard', 'cbpi_dashboard_1.json'))):
for file in glob.glob(os.path.join(self.configFolderPath, 'cbpi_dashboard_*.json')):
shutil.move(file, os.path.join(self.configFolderPath, 'dashboard', os.path.basename(file)))
def inform_missing_content(self, whatsmissing : str):
if whatsmissing == "":
return False