review fix
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import random
|
||||
import string
|
||||
|
||||
from constants import DEFAULT_BACKUP_DIRECTORY
|
||||
|
||||
|
||||
def make_password(length=16):
|
||||
"""Create a random password."""
|
||||
@@ -444,7 +446,7 @@ ConfigDictTemplate = [
|
||||
"values": [
|
||||
{
|
||||
"option": "default_path",
|
||||
"default": "./modoboa_backup/"
|
||||
"default": DEFAULT_BACKUP_DIRECTORY
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
1
modoboa_installer/constants.py
Normal file
1
modoboa_installer/constants.py
Normal file
@@ -0,0 +1 @@
|
||||
DEFAULT_BACKUP_DIRECTORY = "./modoboa_backup/"
|
||||
@@ -9,18 +9,19 @@ import datetime
|
||||
|
||||
from .. import database
|
||||
from .. import utils
|
||||
from ..constants import DEFAULT_BACKUP_DIRECTORY
|
||||
|
||||
|
||||
class Backup:
|
||||
"""
|
||||
Backup structure ( {optional} ):
|
||||
{{backup_folder}}
|
||||
{{backup_directory}}
|
||||
||
|
||||
||--> installer.cfg
|
||||
||--> custom
|
||||
|--> { (copy of) /etc/amavis/conf.d/99-custom }
|
||||
|--> { (copy of) /etc/postfix/custom_whitelist.cidr }
|
||||
|--> { (copy of) dkim folder }
|
||||
|--> { (copy of) dkim directory }
|
||||
|--> {dkim.pem}...
|
||||
|--> { (copy of) radicale home_dir }
|
||||
||--> databases
|
||||
@@ -50,22 +51,22 @@ class Backup:
|
||||
if not path_exists:
|
||||
if not self.silent_backup:
|
||||
create_dir = input(
|
||||
f"\"{path}\" doesn't exists, would you like to create it ? [Y/n]\n").lower()
|
||||
f"\"{path}\" doesn't exists, would you like to create it? [Y/n]\n").lower()
|
||||
|
||||
if self.silent_backup or (not self.silent_backup and (create_dir == "y" or create_dir == "yes")):
|
||||
if self.silent_backup or (not self.silent_backup and create_dir.startswith("y")):
|
||||
pw = pwd.getpwnam("root")
|
||||
utils.mkdir_safe(path, stat.S_IRWXU |
|
||||
stat.S_IRWXG, pw[2], pw[3])
|
||||
else:
|
||||
utils.printcolor(
|
||||
"Error, backup dir not present.", utils.RED
|
||||
"Error, backup directory not present.", utils.RED
|
||||
)
|
||||
return False
|
||||
|
||||
if len(os.listdir(path)) != 0:
|
||||
if not self.silent_backup:
|
||||
delete_dir = input(
|
||||
"Warning : backup folder is not empty, it will be purged if you continue... [Y/n]\n").lower()
|
||||
"Warning : backup directory is not empty, it will be purged if you continue... [Y/n]\n").lower()
|
||||
|
||||
if self.silent_backup or (not self.silent_backup and (delete_dir == "y" or delete_dir == "yes")):
|
||||
try:
|
||||
@@ -99,7 +100,7 @@ class Backup:
|
||||
if self.config.has_option("backup", "default_path"):
|
||||
path = self.config.get("backup", "default_path")
|
||||
else:
|
||||
path = f"./modoboa_backup/"
|
||||
path = DEFAULT_BACKUP_DIRECTORY
|
||||
date = datetime.datetime.now().strftime("%m_%d_%Y_%H_%M")
|
||||
path = os.path.join(path, f"backup_{date}")
|
||||
self.validate_path(path)
|
||||
@@ -112,7 +113,7 @@ class Backup:
|
||||
user_value = None
|
||||
while user_value == "" or user_value is None or not self.validate_path(user_value):
|
||||
utils.printcolor(
|
||||
"Enter backup path, please provide an empty folder.", utils.MAGENTA)
|
||||
"Enter backup path (it must be an empty directory)", utils.MAGENTA)
|
||||
utils.printcolor("CTRL+C to cancel", utils.MAGENTA)
|
||||
user_value = utils.user_input("-> ")
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ class Restore:
|
||||
"Provided path is not a directory !", utils.RED)
|
||||
sys.exit(1)
|
||||
|
||||
modobasql_file = os.path.join(restore, "databases/modoboa.sql")
|
||||
if not os.path.isfile(modobasql_file):
|
||||
modoba_sql_file = os.path.join(restore, "databases/modoboa.sql")
|
||||
if not os.path.isfile(modoba_sql_file):
|
||||
utils.printcolor(
|
||||
modobasql_file + " not found, please check your backup", utils.RED)
|
||||
modoba_sql_file + " not found, please check your backup", utils.RED)
|
||||
sys.exit(1)
|
||||
|
||||
# Everything seems allright here, proceding...
|
||||
|
||||
@@ -172,9 +172,9 @@ def copy_from_template(template, dest, context):
|
||||
|
||||
def check_config_file(dest, interactive=False, upgrade=False, backup=False, restore=False):
|
||||
"""Create a new installer config file if needed."""
|
||||
isPresent = True
|
||||
is_present = True
|
||||
if os.path.exists(dest):
|
||||
return isPresent
|
||||
return is_present
|
||||
if upgrade:
|
||||
printcolor(
|
||||
"You cannot upgrade an existing installation without a "
|
||||
|
||||
4
run.py
4
run.py
@@ -123,10 +123,10 @@ def main(input_args):
|
||||
sys.exit(1)
|
||||
|
||||
utils.printcolor("Welcome to Modoboa installer!\n", utils.GREEN)
|
||||
is_config_file_availible = utils.check_config_file(
|
||||
is_config_file_available = utils.check_config_file(
|
||||
args.configfile, args.interactive, args.upgrade, args.backup, is_restoring)
|
||||
|
||||
if is_config_file_availible and args.backup:
|
||||
if is_config_file_available and args.backup:
|
||||
utils.printcolor("No config file found,", utils.RED)
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user