import os
import shutil
+from pathlib import Path
+
from email.mime.text import MIMEText
from email import charset
from fb_tools.errors import FbAppError
from fb_tools.xlate import format_list
from fb_tools import MailAddress
+from fb_tools.argparse_actions import DirectoryOptionAction
# Own modules
from .. import __version__ as GLOBAL_VERSION
-from .. import DEFAULT_CONFIG_DIR, DEFAULT_ENVIRONMENTS_ROOT_DIR
+from .. import DEFAULT_CONFIG_DIR
from .. import DEFAULT_TERMINAL_WIDTH, DEFAULT_TERMINAL_HEIGHT
from .. import pp
_ = XLATOR.gettext
ngettext = XLATOR.ngettext
-__version__ = '0.4.0'
+__version__ = '0.4.1'
# =============================================================================
charset.add_charset('utf-8', charset.SHORTEST, charset.QP)
- default_env_root_dir = DEFAULT_ENVIRONMENTS_ROOT_DIR
-
# -------------------------------------------------------------------------
def __init__(
self, appname=None, verbose=0, version=GLOBAL_VERSION, base_dir=None, quiet=False,
additional_stems=None, additional_cfgdirs=None, cfg_encoding=DEFAULT_ENCODING,
config_dir=DEFAULT_CONFIG_DIR):
- self._env_root_dir = self.default_env_root_dir
+ self._env_root_dir = DpxPuppetConfig.default_env_root_dir
+ self._var_dir = DpxPuppetConfig.default_var_dir
self.environments = []
super(BaseDPXPuppetApplication, self).__init__(
@env_root_dir.setter
def env_root_dir(self, value):
if value is None:
- self._env_root_dir = None
+ if hasattr(self, 'cfg') and self.cfg:
+ self._env_root_dir = self.cfg.env_root_dir
+ else:
+ self._env_root_dir = DpxPuppetConfig.default_env_root_dir
return
val = Path(value)
raise ValueError(msg)
self._env_root_dir = val
+ # -------------------------------------------------------------------------
+ @property
+ def var_dir(self):
+ """The root directory of all puppet environments."""
+ return self._var_dir
+
+ @var_dir.setter
+ def var_dir(self, value):
+ if value is None:
+ if hasattr(self, 'cfg') and self.cfg:
+ self._var_dir = self.cfg.var_dir
+ else:
+ self._var_dir = DpxPuppetConfig.default_var_dir
+ return
+
+ val = Path(value)
+ if not val.is_absolute():
+ msg = _("Path {!r} for the var directory must be an absolute path.").format(value)
+ raise ValueError(msg)
+ self._var_dir = val
+
# -------------------------------------------------------------------------
def as_dict(self, short=True):
"""
res['default_env_root_dir'] = self.default_env_root_dir
res['env_root_dir'] = self.env_root_dir
+ res['var_dir'] = self.env_root_dir
return res
+ # -------------------------------------------------------------------------
+ def init_arg_parser(self):
+ """
+ Public available method to initiate the argument parser.
+ """
+
+ puppet_group = self.arg_parser.add_argument_group(_('Common options for Puppet'))
+
+ help_txt = _(
+ "The directory containing the checked out r10k directories. Default: {!r}.").format(
+ DpxPuppetConfig.default_env_root_dir)
+ puppet_group.add_argument(
+ '--env-root-dir', dest='env_root_dir', metavar=_('DIRECTORY'),
+ action=DirectoryOptionAction, must_exists=True, help=help_txt,
+ )
+
+ help_txt = _(
+ "The directory containing variable data from DPX puppet tools. "
+ "Cache files for the forge information are read and written from the sub "
+ "directory {fd!r} below it. iCaching Git repositories are cloned in the "
+ "sub directory {gd!r} below it. Default: {vd!r}.").format(
+ vd=str(DpxPuppetConfig.default_var_dir), fd='forge', gd='git')
+ puppet_group.add_argument(
+ '--var-dir', dest='var_dir', metavar=_('DIRECTORY'),
+ action=DirectoryOptionAction, must_exists=True, help=help_txt,
+ )
+
+ mail_group = self.arg_parser.add_argument_group(_('Mailing options'))
+
+ mail_from = DpxPuppetConfig.default_mail_from_complete
+ mail_method = DpxPuppetConfig.default_mail_method
+ mail_server = DpxPuppetConfig.default_mail_server
+ smtp_port = DpxPuppetConfig.default_smtp_port
+
+ if self.cfg:
+ mail_from = self.cfg.mail_from
+ mail_method = self.cfg.mail_method
+ mail_server = self.cfg.mail_server
+ smtp_port = self.cfg.smtp_port
+
+ mail_group.add_argument(
+ '--from', '--mail-from',
+ metavar=_("ADDRESS"), dest="mail_from",
+ help=_(
+ "Sender mail address for mails generated by this script. "
+ "Default: {!r}").format(mail_from),
+ )
+
+ mail_group.add_argument(
+ '--recipients', '--mail-recipients',
+ metavar=_("ADDRESS"), nargs='+', dest="mail_recipients",
+ help=_("Mail addresses of all recipients for mails generated by this script.")
+ )
+
+ mail_group.add_argument(
+ '--cc', '--mail-cc',
+ metavar=_("ADDRESS"), nargs='*', dest="mail_cc",
+ help=_("Mail addresses of all CC recipients for mails generated by this script.")
+ )
+
+ mail_group.add_argument(
+ '--reply-to', '--mail-reply-to',
+ metavar=_("ADDRESS"), dest="mail_reply_to",
+ help=_("Reply mail address for mails generated by this script.")
+ )
+
+ methods = DpxPuppetConfig.valid_mail_methods
+ method_list = format_list(methods, do_repr=True)
+ mail_group.add_argument(
+ '--mail-method',
+ metavar=_("METHOD"), choices=methods, dest="mail_method",
+ help=_(
+ "Method for sending the mails generated by this script. "
+ "Valid values: {v}, default: {d!r}.").format(
+ v=method_list, d=mail_method)
+ )
+
+ mail_group.add_argument(
+ '--mail-server',
+ metavar=_("SERVER"), dest="mail_server",
+ help=_(
+ "Mail server for submitting generated by this script if "
+ "the mail method of this script is 'smtp'. Default: {!r}.").format(mail_server)
+ )
+
+ mail_group.add_argument(
+ '--smtp-port',
+ metavar=_("PORT"), type=int, dest='smtp_port', what="SMTP",
+ action=PortOptionAction,
+ help=_(
+ "The port to use for submitting generated by this script if "
+ "the mail method of this script is 'smtp'. Default: {}.").format(smtp_port)
+ )
+
+ super(BaseDPXPuppetApplication, self).init_arg_parser()
+
# -------------------------------------------------------------------------
def post_init(self):
"""
else:
LOG.debug(_("Don't using a logfile."))
+ var_dir = getattr(self.args, 'var_dir', None)
+ if var_dir:
+ self.var_dir = var_dir
+ else:
+ self.var_dir = self.cfg.var_dir
+
+ env_root_dir = getattr(self.args, 'env_root_dir', None)
+ if env_root_dir:
+ self.env_root_dir = env_root_dir
+ else:
+ self.env_root_dir = self.cfg.env_root_dir
+
v = getattr(self.args, 'mail_method', None)
if v:
self.cfg.mail_method = v
self.cfg.reply_to = v
- # -------------------------------------------------------------------------
- def init_arg_parser(self):
- """
- Public available method to initiate the argument parser.
- """
-
- super(BaseDPXPuppetApplication, self).init_arg_parser()
-
- mail_group = self.arg_parser.add_argument_group(_('Mailing options'))
-
- mail_from = DpxPuppetConfig.default_mail_from_complete
- mail_method = DpxPuppetConfig.default_mail_method
- mail_server = DpxPuppetConfig.default_mail_server
- smtp_port = DpxPuppetConfig.default_smtp_port
-
- if self.cfg:
- mail_from = self.cfg.mail_from
- mail_method = self.cfg.mail_method
- mail_server = self.cfg.mail_server
- smtp_port = self.cfg.smtp_port
-
- mail_group.add_argument(
- '--from', '--mail-from',
- metavar=_("ADDRESS"), dest="mail_from",
- help=_(
- "Sender mail address for mails generated by this script. "
- "Default: {!r}").format(mail_from),
- )
-
- mail_group.add_argument(
- '--recipients', '--mail-recipients',
- metavar=_("ADDRESS"), nargs='+', dest="mail_recipients",
- help=_("Mail addresses of all recipients for mails generated by this script.")
- )
-
- mail_group.add_argument(
- '--cc', '--mail-cc',
- metavar=_("ADDRESS"), nargs='*', dest="mail_cc",
- help=_("Mail addresses of all CC recipients for mails generated by this script.")
- )
-
- mail_group.add_argument(
- '--reply-to', '--mail-reply-to',
- metavar=_("ADDRESS"), dest="mail_reply_to",
- help=_("Reply mail address for mails generated by this script.")
- )
-
- methods = DpxPuppetConfig.valid_mail_methods
- method_list = format_list(methods, do_repr=True)
- mail_group.add_argument(
- '--mail-method',
- metavar=_("METHOD"), choices=methods, dest="mail_method",
- help=_(
- "Method for sending the mails generated by this script. "
- "Valid values: {v}, default: {d!r}.").format(
- v=method_list, d=mail_method)
- )
-
- mail_group.add_argument(
- '--mail-server',
- metavar=_("SERVER"), dest="mail_server",
- help=_(
- "Mail server for submitting generated by this script if "
- "the mail method of this script is 'smtp'. Default: {!r}.").format(mail_server)
- )
-
- mail_group.add_argument(
- '--smtp-port',
- metavar=_("PORT"), type=int, dest='smtp_port', what="SMTP",
- action=PortOptionAction,
- help=_(
- "The port to use for submitting generated by this script if "
- "the mail method of this script is 'smtp'. Default: {}.").format(smtp_port)
- )
-
# -------------------------------------------------------------------------
def perform_arg_parser(self):
from pathlib import Path
# Third party modules
-from fb_tools.argparse_actions import DirectoryOptionAction
# Own modules
from .. import pp, DEFAULT_VAR_DIR
_ = XLATOR.gettext
ngettext = XLATOR.ngettext
-__version__ = '0.6.3'
+__version__ = '0.6.4'
# =============================================================================
write_cache_group.add_argument(
'-W', '--no-write-cache', dest='no_write_cache', action="store_true", help=help_txt)
- help_txt = _(
- "The directory containing variable data from DPX puppet tools, Default: {vd!r}. "
- "Cache files for the forge information are read and written from the sub "
- "directory {sd!r} below it.").format(vd=str(DEFAULT_VAR_DIR), sd='forge')
- forge_group.add_argument(
- '--dir', '--var-dir', dest='var_dir', metavar=_('DIRECTORY'),
- action=DirectoryOptionAction, must_exists=True, help=help_txt,
- )
-
help_txt = _("Show more details of the forge module.")
forge_group.add_argument(
'-D', '--details', dest="details", action="store_true", help=help_txt)
if no_write_cache:
self.write_cache = False
- var_dir = getattr(self.args, 'var_dir', None)
- if var_dir:
- if self.wite_cache:
- if not os.access(str(var_dir), os.W_OK):
- msg = _("The given var directory {!r} is not writeable.").format(
- str(var_dir))
- LOG.error(msg)
- self.exit(1)
- else:
- var_dir = self.cfg.var_dir
+ if self.write_cache:
+ if not os.access(str(self.var_dir), os.W_OK):
+ msg = _("The var directory {!r} is not writeable.").format(str(self.var_dir))
+ LOG.error(msg)
+ self.exit(1)
self.details = getattr(self.args, 'details', False)
self.module_info = ForgeModuleInfo(
appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
- full_name=self.module_name, var_dir=var_dir, initialized=True,)
+ full_name=self.module_name, var_dir=self.var_dir, initialized=True,)
LOG.debug(_("Finished creating a {} object.").format('ForgeModuleInfo'))