from six.moves.urllib.parse import urlunsplit
# Own modules
-from .common import pp, compare_fqdn, to_str
+from .common import pp, compare_fqdn, to_str, to_bool
from .common import RE_DOT_AT_END
from .pdns_app import PpPDNSAppError, PpPDNSApplication
from .pidfile import PidFileError, InvalidPidFileError, PidFileInUseError, PidFile
-__version__ = '0.4.1'
+__version__ = '0.4.2'
LOG = logging.getLogger(__name__)
self.tempdir = None
self.temp_zones_cfg_file = None
self.keep_tempdir = False
+ self.keep_backup = False
self.backup_suffix = (
'.' + datetime.datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S') + '.bak')
super(PpDeployZonesApp, self).init_arg_parser()
+ self.arg_parser.add_argument(
+ '-B', '--backup', dest="keep_backup", action='store_true',
+ help=("Keep a backup file for each changed configuration file."),
+ )
+
self.arg_parser.add_argument(
'-K', '--keep-tempdir', dest='keep_tempdir', action='store_true',
help=(
if self.args.keep_tempdir:
self.keep_tempdir = True
+ if self.args.keep_backup:
+ self.keep_backup = True
+
# -------------------------------------------------------------------------
def perform_config(self):
if section_name.lower() == 'app':
self._check_path_config(section, section_name, 'pidfile', 'pidfile_name', True)
+ if 'keep-backup' in section:
+ self.keep_backup = to_bool(section['keep-backup'])
+ if 'keep_backup' in section:
+ self.keep_backup = to_bool(section['keep_backup'])
if section_name.lower() == 'named':
self.set_named_options(section, section_name)
backup_file = self.moved_files[tgt_file]
LOG.debug("Searching for {!r}.".format(backup_file))
if os.path.exists(backup_file):
- LOG.info("Removing {!r} ...".format(backup_file))
- if not self.simulate:
- os.remove(backup_file)
+ if self.keep_backup:
+ LOG.info("Keep existing backup file {!r}.".format(backup_file))
+ else:
+ LOG.info("Removing {!r} ...".format(backup_file))
+ if not self.simulate:
+ os.remove(backup_file)
# -----------------------
def emit_rm_err(function, path, excinfo):