mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-10 01:17:42 +01:00
Moved restore config to cli.py
- cbpi is now checking if a zip is existing to restore the config during start. - If zip is there, content is checked prior to restore - if required content is found, config folder is removed and zip is extracted. - afterwards zip is removed - cbpi is starting with restored config Version -> 4.0.0.38
This commit is contained in:
parent
bd2cb1b497
commit
8459ad63d5
3 changed files with 42 additions and 5 deletions
|
@ -1 +1 @@
|
||||||
__version__ = "4.0.0.37"
|
__version__ = "4.0.0.38"
|
||||||
|
|
39
cbpi/cli.py
39
cbpi/cli.py
|
@ -15,6 +15,7 @@ import shutil
|
||||||
import yaml
|
import yaml
|
||||||
import click
|
import click
|
||||||
from subprocess import call
|
from subprocess import call
|
||||||
|
import zipfile
|
||||||
|
|
||||||
from jinja2 import Template
|
from jinja2 import Template
|
||||||
|
|
||||||
|
@ -102,6 +103,11 @@ def clear_db():
|
||||||
os.remove(os.path.join(".", "craftbeerpi.db"))
|
os.remove(os.path.join(".", "craftbeerpi.db"))
|
||||||
print("database Cleared")
|
print("database Cleared")
|
||||||
|
|
||||||
|
def recursive_chown(path, owner, group):
|
||||||
|
for dirpath, dirnames, filenames in os.walk(path):
|
||||||
|
shutil.chown(dirpath, owner, group)
|
||||||
|
for filename in filenames:
|
||||||
|
shutil.chown(os.path.join(dirpath, filename), owner, group)
|
||||||
|
|
||||||
def check_for_setup():
|
def check_for_setup():
|
||||||
if os.path.exists(os.path.join(".", "config", "config.yaml")) is False:
|
if os.path.exists(os.path.join(".", "config", "config.yaml")) is False:
|
||||||
|
@ -116,6 +122,39 @@ def check_for_setup():
|
||||||
print("Please run 'cbpi setup' before starting the server ")
|
print("Please run 'cbpi setup' before starting the server ")
|
||||||
print("***************************************************")
|
print("***************************************************")
|
||||||
return False
|
return False
|
||||||
|
backupfile = os.path.join(".", "restored_config.zip")
|
||||||
|
if os.path.exists(os.path.join(backupfile)) is True:
|
||||||
|
print("***************************************************")
|
||||||
|
print("Found backup of config. Starting restore")
|
||||||
|
required_content=['dashboard/', 'recipes/', 'upload/', 'config.json', 'config.yaml']
|
||||||
|
zip=zipfile.ZipFile(backupfile)
|
||||||
|
zip_content_list = zip.namelist()
|
||||||
|
zip_content = True
|
||||||
|
print("Checking content of zip file")
|
||||||
|
for content in required_content:
|
||||||
|
try:
|
||||||
|
check = zip_content_list.index(content)
|
||||||
|
except:
|
||||||
|
zip_content = False
|
||||||
|
|
||||||
|
if zip_content == True:
|
||||||
|
print("Found correct content. Starting Restore process")
|
||||||
|
output_path = pathlib.Path(os.path.join(".", 'config'))
|
||||||
|
print("Removing old config folder")
|
||||||
|
shutil.rmtree(output_path, ignore_errors=True)
|
||||||
|
print("Extracting zip file to config folder")
|
||||||
|
zip.extractall(output_path)
|
||||||
|
print("Changing owner and group of config folder recursively to pi:pi")
|
||||||
|
recursive_chown(output_path, "pi", "pi")
|
||||||
|
print("Removing backup file")
|
||||||
|
os.remove(backupfile)
|
||||||
|
else:
|
||||||
|
print("Wrong Content in zip file. No restore possible")
|
||||||
|
print("Removing zip file")
|
||||||
|
os.remove(backupfile)
|
||||||
|
print("***************************************************")
|
||||||
|
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -74,13 +74,11 @@ class SystemController:
|
||||||
except:
|
except:
|
||||||
zip_content = False
|
zip_content = False
|
||||||
if zip_content == True:
|
if zip_content == True:
|
||||||
output_path = pathlib.Path(os.path.join(".", 'config'))
|
|
||||||
shutil.rmtree(output_path, ignore_errors=True)
|
|
||||||
zip.extractall(output_path)
|
|
||||||
self.recursive_chown(output_path, "pi", "pi")
|
|
||||||
self.cbpi.notify("Success", "Config backup has been uploaded", NotificationType.SUCCESS)
|
self.cbpi.notify("Success", "Config backup has been uploaded", NotificationType.SUCCESS)
|
||||||
|
self.cbpi.notify("Action Required!", "Please restart the server", NotificationType.WARNING)
|
||||||
else:
|
else:
|
||||||
self.cbpi.notify("Error", "Wrong content type. Upload failed", NotificationType.ERROR)
|
self.cbpi.notify("Error", "Wrong content type. Upload failed", NotificationType.ERROR)
|
||||||
|
os.remove(self.path)
|
||||||
except:
|
except:
|
||||||
self.cbpi.notify("Error", "Config backup upload failed", NotificationType.ERROR)
|
self.cbpi.notify("Error", "Config backup upload failed", NotificationType.ERROR)
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue