From: Frank Brehm Date: Thu, 10 Aug 2017 09:09:18 +0000 (+0200) Subject: Replacing config files X-Git-Tag: 0.1.2~129 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=766c3d6916aa68af093508f462728590222a83ea;p=pixelpark%2Fadmin-tools.git Replacing config files --- diff --git a/pp_lib/config_named_app.py b/pp_lib/config_named_app.py index 828cfad..e22b5e7 100644 --- a/pp_lib/config_named_app.py +++ b/pp_lib/config_named_app.py @@ -26,6 +26,7 @@ import datetime import textwrap import ipaddress import stat +import shutil # Third party modules import six @@ -40,7 +41,7 @@ from .cfg_app import PpCfgAppError, PpConfigApplication from .pidfile import PidFileError, InvalidPidFileError, PidFileInUseError, PidFile -__version__ = '0.6.4' +__version__ = '0.6.5' LOG = logging.getLogger(__name__) @@ -281,10 +282,14 @@ class PpConfigNamedApp(PpConfigApplication): self.temp_log_cfg_file = None self.temp_zones_cfg_file = None + self.backup_suffix = ( + '.' + datetime.datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S') + '.bak') + self.reload_necessary = False self.restart_necessary = False self.files2replace = {} + self.moved_files = {} self.acls = { 'allow-notify': ['dnsmaster.pixelpark.com'], @@ -828,6 +833,7 @@ class PpConfigNamedApp(PpConfigApplication): self.create_temp_files() self.compare_files() self.check_directories() + self.replace_configfiles() finally: if self.tempdir: @@ -1586,6 +1592,31 @@ class PpConfigNamedApp(PpConfigApplication): return True + # ------------------------------------------------------------------------- + def replace_configfiles(self): + + if not self.files2replace: + LOG.debug("No replacement of any config files necessary.") + return + + LOG.debug("Start replacing of config files ...") + + for tgt_file in self.files2replace.keys(): + + backup_file = tgt_file + self.backup_suffix + self.moved_files[tgt_file] = backup_file + + if os.path.exists(tgt_file): + LOG.info("Copying {!r} => {!r} ...".format(tgt_file, backup_file)) + if not self.simulate: + shutil.copy2(tgt_file, backup_file) + + for tgt_file in self.files2replace.keys(): + src_file = self.files2replace[tgt_file] + LOG.info("Copying {!r} => {!r} ...".format(src_file, tgt_file)) + if not self.simulate: + shutil.copy2(src_file, tgt_file) + # ============================================================================= if __name__ == "__main__":