initial commit
This commit is contained in:
@@ -6,12 +6,16 @@ import sys
|
||||
from .. import utils
|
||||
|
||||
|
||||
def install(appname, config, upgrade):
|
||||
def install(appname, config, upgrade, restore):
|
||||
"""Install an application."""
|
||||
if (config.has_option(appname, "enabled") and
|
||||
not config.getboolean(appname, "enabled")):
|
||||
return
|
||||
utils.printcolor("Installing {}".format(appname), utils.MAGENTA)
|
||||
|
||||
if not restore:
|
||||
utils.printcolor("Installing {}".format(appname), utils.MAGENTA)
|
||||
else:
|
||||
utils.printcolor("Restoring {}".format(appname), utils.MAGENTA)
|
||||
try:
|
||||
script = importlib.import_module(
|
||||
"modoboa_installer.scripts.{}".format(appname))
|
||||
@@ -19,7 +23,7 @@ def install(appname, config, upgrade):
|
||||
print("Unknown application {}".format(appname))
|
||||
sys.exit(1)
|
||||
try:
|
||||
getattr(script, appname.capitalize())(config, upgrade).run()
|
||||
getattr(script, appname.capitalize())(config, upgrade, restore).run()
|
||||
except utils.FatalError as inst:
|
||||
utils.printcolor(u"{}".format(inst), utils.RED)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -20,10 +20,11 @@ class Installer(object):
|
||||
with_db = False
|
||||
config_files = []
|
||||
|
||||
def __init__(self, config, upgrade):
|
||||
def __init__(self, config, upgrade, restore):
|
||||
"""Get configuration."""
|
||||
self.config = config
|
||||
self.upgrade = upgrade
|
||||
self.restore = restore
|
||||
if self.config.has_section(self.appname):
|
||||
self.app_config = dict(self.config.items(self.appname))
|
||||
self.dbengine = self.config.get("database", "engine")
|
||||
|
||||
@@ -168,7 +168,7 @@ def copy_from_template(template, dest, context):
|
||||
fp.write(ConfigFileTemplate(buf).substitute(context))
|
||||
|
||||
|
||||
def check_config_file(dest, interactive=False, upgrade=False, backup=False):
|
||||
def check_config_file(dest, interactive=False, upgrade=False, backup=False, restore=False):
|
||||
"""Create a new installer config file if needed."""
|
||||
isPresent = True
|
||||
if os.path.exists(dest):
|
||||
@@ -183,6 +183,12 @@ def check_config_file(dest, interactive=False, upgrade=False, backup=False):
|
||||
printcolor(
|
||||
"Your configuration file hasn't been found. A new one will be generated. "
|
||||
"Please edit it with correct password for the databases !", RED)
|
||||
elif restore:
|
||||
printcolor(
|
||||
"You cannot restore an existing installation without a "
|
||||
f"configuration file. (file : {dest} has not been found...", RED)
|
||||
sys.exit(1)
|
||||
|
||||
printcolor(
|
||||
"Configuration file {} not found, creating new one."
|
||||
.format(dest), YELLOW)
|
||||
|
||||
Reference in New Issue
Block a user