Skip to content

Commit

Permalink
Copy dashboard files from config folder to config/dashboard when upgr…
Browse files Browse the repository at this point in the history
…ading to version 4.0.7. Detect missing or empty dashboard file in config/dashboard.
  • Loading branch information
phylax2020 committed Jan 5, 2023
1 parent 6a356c6 commit 0c957de
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cbpi/configFolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import zipfile
from pathlib import Path
import glob

import json

class ConfigFolder:
def __init__(self, configFolderPath, logsFolderPath):
Expand Down Expand Up @@ -121,9 +121,23 @@ def check_for_setup(self):
# 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'))):
dashboard_1_path = os.path.join(self.configFolderPath, 'dashboard', 'cbpi_dashboard_1.json')
if (not (os.path.isfile(dashboard_1_path))) or self.check_for_empty_dashboard_1(dashboard_1_path):
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)))
dashboardFile = os.path.basename(file)
print(f"Copy dashboard json file {dashboardFile} from config to config/dashboard folder")
shutil.move(file, os.path.join(self.configFolderPath, 'dashboard', dashboardFile))

def check_for_empty_dashboard_1(self, dashboard_1_path):
try:
with open(dashboard_1_path, 'r') as f:
data = json.load(f)
if (len(data['elements']) == 0): # there may exist some pathes but pathes without elements in dashboard is not very likely
return True
else:
return False
except: # file missing or bad json format
return True

def inform_missing_content(self, whatsmissing : str):
if whatsmissing == "":
Expand Down

0 comments on commit 0c957de

Please sign in to comment.