From c85d6d3d51460c031a36a5c1221329199c2076ba Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 7 Aug 2017 11:31:45 +0200 Subject: [PATCH] Adding generating temporary objects. --- pp_lib/config_named_app.py | 40 +++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/pp_lib/config_named_app.py b/pp_lib/config_named_app.py index b339779..20fa72e 100644 --- a/pp_lib/config_named_app.py +++ b/pp_lib/config_named_app.py @@ -20,6 +20,7 @@ import textwrap import socket import pwd import grp +import tempfile # Third party modules import six @@ -34,7 +35,7 @@ from .cfg_app import PpCfgAppError, PpConfigApplication from .pidfile import PidFileError, InvalidPidFileError, PidFileInUseError, PidFile -__version__ = '0.4.2' +__version__ = '0.4.3' LOG = logging.getLogger(__name__) @@ -154,6 +155,12 @@ class PpConfigNamedApp(PpConfigApplication): self.zones = [] self.pidfile = None + self.tempdir = None + self.temp_named_conf = None + self.temp_acl_cfg_file = None + self.temp_log_cfg_file = None + self.temp_zones_cfg_file = None + description = textwrap.dedent('''\ Generation of configuration of named (the BIND 9 name daemon). ''').strip() @@ -499,10 +506,41 @@ class PpConfigNamedApp(PpConfigApplication): return try: + self.get_api_zones() + self.init_temp_objects() + finally: + if self.tempdir: + LOG.debug("Destroying temporary directory {!r} ...".format(self.tempdir.name)) + self.tempdir.cleanup() + self.tempdir = None self.pidfile = None + # ------------------------------------------------------------------------- + def init_temp_objects(self): + """Init temporary objects and properties.""" + + self.tempdir = tempfile.TemporaryDirectory( + prefix=(self.appname + '.'), suffix='.tmp.d' + ) + LOG.debug("Temporary directory: {!r}.".format(self.tempdir.name)) + + self.temp_named_conf = os.path.join( + self.tempdir.name, self.default_named_conf) + self.temp_acl_cfg_file = os.path.join( + self.tempdir.name, self.default_named_acl_cfg_file) + self.temp_log_cfg_file = os.path.join( + self.tempdir.name, self.default_named_log_cfg_file) + self.temp_zones_cfg_file = os.path.join( + self.tempdir.name, self.default_named_zones_cfg_file) + + if self.verbose > 1: + LOG.debug("Temporary named.conf: {!r}".format(self.temp_named_conf)) + LOG.debug("Temporary ACL conf: {!r}".format(self.temp_acl_cfg_file)) + LOG.debug("Temporary LOG conf: {!r}".format(self.temp_log_cfg_file)) + LOG.debug("Temporary zones conf: {!r}".format(self.temp_zones_cfg_file)) + # ------------------------------------------------------------------------- def get_api_zones(self): -- 2.39.5