from .xlate import XLATOR
-__version__ = '0.6.2'
+__version__ = '0.6.3'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
what=_("Target file"), f=file_tgt)
raise PpDeployZonesError(msg)
+ # Reading source file
content_src = ''
if self.verbose > 2:
LOG.debug(_("Reading {!r} ...").format(file_src))
if self.verbose > 3:
LOG.debug(_("Cleaned version of {!r}:").format(file_src) + '\n' + '\n'.join(lines_src))
+ # Reading target file
content_tgt = ''
if self.verbose > 2:
- LOG.debug("Reading {!r} ...".format(file_tgt))
+ LOG.debug(_("Reading {!r} ...").format(file_tgt))
with open(file_tgt, 'r', **self.open_args) as fh:
content_tgt = fh.read()
lines_str_tgt = self.re_block_comment.sub('', content_tgt)
if line:
lines_tgt.append(line)
if self.verbose > 3:
- LOG.debug("Cleaned version of {!r}:\n{}".format(
- file_tgt, '\n'.join(lines_tgt)))
+ LOG.debug(_("Cleaned version of {!r}:").format(file_tgt) + '\n' + '\n'.join(lines_tgt))
if len(lines_src) != len(lines_tgt):
- LOG.debug((
- "Source file {!r} has different number essential lines ({}) than "
- "the target file {!r} ({} lines).").format(
- file_src, len(lines_src), file_tgt, len(lines_tgt)))
+ LOG.debug(_(
+ "Source file {sf!r} has different number essential lines ({sl}) than "
+ "the target file {tf!r} ({tl} lines).").format(
+ sf=file_src, sl=len(lines_src), tf=file_tgt, tl=len(lines_tgt)))
return False
i = 0
while i < len(lines_src):
if lines_src[i] != lines_tgt[i]:
- LOG.debug((
- "Source file {!r} has a different content than "
- "the target file {!r}.").format(file_src, lines_tgt))
+ LOG.debug(_(
+ "Source file {sf!r} has a different content than "
+ "the target file {tf!r}.").format(sf=file_src, tf=lines_tgt))
return False
i += 1
def replace_configfiles(self):
if not self.files2replace:
- LOG.debug("No replacement of any config files necessary.")
+ LOG.debug(_("No replacement of any config files necessary."))
return
- LOG.debug("Start replacing of config files ...")
+ LOG.debug(_("Start replacing of config files ..."))
for tgt_file in self.files2replace.keys():
if os.path.exists(tgt_file):
self.moved_files[tgt_file] = backup_file
- LOG.info("Copying {!r} => {!r} ...".format(tgt_file, backup_file))
+ LOG.info(_("Copying {frm!r} => {to!r} ...").format(frm=tgt_file, to=backup_file))
if not self.simulate:
shutil.copy2(tgt_file, backup_file)
if self.verbose > 1:
- LOG.debug("All backuped config files:\n{}".format(pp(self.moved_files)))
+ LOG.debug(_("All backuped config files:") + '\n' + pp(self.moved_files))
for tgt_file in self.files2replace.keys():
src_file = self.files2replace[tgt_file]
- LOG.info("Copying {!r} => {!r} ...".format(src_file, tgt_file))
+ LOG.info(_("Copying {frm!r} => {to!r} ...").format(frm=src_file, to=tgt_file))
if not self.simulate:
shutil.copy2(src_file, tgt_file)
# -------------------------------------------------------------------------
def restore_configfiles(self):
- LOG.error("Restoring of original config files because of an exception.")
+ LOG.error(_("Restoring of original config files because of an exception."))
for tgt_file in self.moved_files.keys():
backup_file = self.moved_files[tgt_file]
- LOG.info("Moving {!r} => {!r} ...".format(backup_file, tgt_file))
+ LOG.info(_("Moving {frm!r} => {to!r} ...").format(frm=backup_file, to=tgt_file))
if not self.simulate:
if os.path.exists(backup_file):
os.rename(backup_file, tgt_file)
else:
- LOG.error("Could not find backup file {!r}.".format(backup_file))
+ LOG.error(_("Could not find backup file {!r}.").format(backup_file))
# -------------------------------------------------------------------------
def check_namedconf(self):
- LOG.info("Checking syntax correctness of named.conf ...")
+ LOG.info(_("Checking syntax correctness of named.conf ..."))
cmd = shlex.split(self.cmd_checkconf)
if 'named-checkconf' in self.cmd_checkconf and self.verbose > 2:
cmd.append('-p')
cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd))
- LOG.debug("Executing: {}".format(cmd_str))
+ LOG.debug(_("Executing: {}").format(cmd_str))
std_out = None
std_err = None
std_out, std_err = proc.communicate()
ret_val = proc.wait()
- LOG.debug("Return value: {!r}".format(ret_val))
+ LOG.debug(_("Return value: {!r}").format(ret_val))
if std_out and std_out.strip():
- s = to_str(std_out.strip())
- LOG.warn("Output on STDOUT: {}".format(s))
+ LOG.warn(_("Output on {}").format('STDOUT') + ' ' + to_str(std_out.strip()))
if std_err and std_err.strip():
- s = to_str(std_err.strip())
- LOG.warn("Output on STDERR: {}".format(s))
+ LOG.warn(_("Output on {}").format('STDERR') + ' ' + to_str(std_err.strip()))
if ret_val:
return False
def apply_config(self):
if not self.reload_necessary and not self.restart_necessary:
- LOG.info("Reload or restart of named is not necessary.")
+ LOG.info(_("Reload or restart of named is not necessary."))
return
running = self.named_running()
if not running:
- LOG.warn("Named is not running, please start it manually.")
+ LOG.warn(_("Named is not running, please start it manually."))
return
if self.restart_necessary:
# -------------------------------------------------------------------------
def named_running(self):
- LOG.debug("Checking, whether named is running ...")
+ LOG.debug(_("Checking, whether named is running ..."))
cmd = shlex.split(self.cmd_status)
cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd))
- LOG.debug("Executing: {}".format(cmd_str))
+ LOG.debug(_("Executing: {}").format(cmd_str))
std_out = None
std_err = None
std_out, std_err = proc.communicate()
ret_val = proc.wait()
- LOG.debug("Return value: {!r}".format(ret_val))
+ LOG.debug(_("Return value: {!r}").format(ret_val))
if std_out and std_out.strip():
- s = to_str(std_out.strip())
- LOG.debug("Output on STDOUT:\n{}".format(s))
+ LOG.debug(_("Output on {}").format('STDOUT') + '\n' + to_str(std_out.strip()))
if std_err and std_err.strip():
- s = to_str(std_err.strip())
- LOG.warn("Output on STDERR: {}".format(s))
+ LOG.warn(_("Output on {}").format('STDERR') + ' ' + to_str(std_err.strip()))
if ret_val:
return False
# -------------------------------------------------------------------------
def start_named(self):
- LOG.info("Starting named ...")
+ LOG.info(_("Starting {} ...").format('named'))
cmd = shlex.split(self.cmd_start)
cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd))
- LOG.debug("Executing: {}".format(cmd_str))
+ LOG.debug(_("Executing: {}").format(cmd_str))
if self.simulate:
return
std_out, std_err = proc.communicate()
ret_val = proc.wait()
- LOG.debug("Return value: {!r}".format(ret_val))
+ LOG.debug(_("Return value: {!r}").format(ret_val))
if std_out and std_out.strip():
- s = to_str(std_out.strip())
- LOG.debug("Output on STDOUT:\n{}".format(s))
+ LOG.debug(_("Output on {}").format('STDOUT') + '\n' + to_str(std_out.strip()))
if std_err and std_err.strip():
- s = to_str(std_err.strip())
- LOG.error("Output on STDERR: {}".format(s))
+ LOG.error(_("Output on {}").format('STDERR') + ' ' + to_str(std_err.strip()))
if ret_val:
return False
# -------------------------------------------------------------------------
def restart_named(self):
- LOG.info("Restarting named ...")
+ LOG.info(_("Restarting {} ...").format('named'))
cmd = shlex.split(self.cmd_restart)
cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd))
- LOG.debug("Executing: {}".format(cmd_str))
+ LOG.debug(_("Executing: {}").format(cmd_str))
if self.simulate:
return
std_out, std_err = proc.communicate()
ret_val = proc.wait()
- LOG.debug("Return value: {!r}".format(ret_val))
+ LOG.debug(_("Return value: {!r}").format(ret_val))
if std_out and std_out.strip():
- s = to_str(std_out.strip())
- LOG.debug("Output on STDOUT:\n{}".format(s))
+ LOG.debug(_("Output on {}").format('STDOUT') + '\n' + to_str(std_out.strip()))
if std_err and std_err.strip():
- s = to_str(std_err.strip())
- LOG.error("Output on STDERR: {}".format(s))
+ LOG.error(_("Output on {}").format('STDERR') + ' ' + to_str(std_err.strip()))
if ret_val:
return False
# -------------------------------------------------------------------------
def reload_named(self):
- LOG.info("Reloading named ...")
+ LOG.info(_("Reloading {} ...").format('named'))
cmd = shlex.split(self.cmd_reload)
cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd))
- LOG.debug("Executing: {}".format(cmd_str))
+ LOG.debug(_("Executing: {}").format(cmd_str))
if self.simulate:
return
std_out, std_err = proc.communicate()
ret_val = proc.wait()
- LOG.debug("Return value: {!r}".format(ret_val))
+ LOG.debug(_("Return value: {!r}").format(ret_val))
if std_out and std_out.strip():
- s = to_str(std_out.strip())
- LOG.debug("Output on STDOUT:\n{}".format(s))
+ LOG.debug(_("Output on {}").format('STDOUT') + '\n' + to_str(std_out.strip()))
if std_err and std_err.strip():
- s = to_str(std_err.strip())
- LOG.error("Output on STDERR: {}".format(s))
+ LOG.error(_("Output on {}").format('STDERR') + ' ' + to_str(std_err.strip()))
if ret_val:
return False