import re
import pwd
import grp
+import pathlib
# Third party modules
import six
from .module_list import ModuleInfoDict
-__version__ = '1.0.1'
+from .xlate import XLATOR
+
+__version__ = '1.1.1'
LOG = logging.getLogger(__name__)
+_ = XLATOR.gettext
+ngettext = XLATOR.ngettext
+
# =============================================================================
class PuppetfileError(FbBaseObjectError):
default_environment = 'production'
default_env_root_dir = os.sep + os.path.join("etc", "puppetlabs", "code", "environments")
+ default_env_root_dir = pathlib.Path(os.sep) / "etc" / "puppetlabs" / "code" / "environments"
re_comment = re.compile(r'^\s*#')
re_comma_at_end = re.compile(r',\s*$')
@env_root_dir.setter
def env_root_dir(self, value):
if value is None:
- msg = "The root directory of all puppet environments may not be None."
+ msg = _("The root directory of all puppet environments may not be None.")
raise TypeError(msg)
- val = str(value)
- if not os.path.isabs(val):
- msg = (
+ val = pathlib.Path(value)
+ if not val.is_absolute():
+ msg = _(
"Path {!r} for the root directory of all puppet environments must "
"be an absolute path.").format(value)
raise ValueError(msg)
@property
def env_dir(self):
"""The directory containing the r10k environmenmt."""
- edir = os.path.normpath(os.path.join(self.env_root_dir, self.environment))
- if os.path.exists(edir):
- return os.path.abspath(edir)
- return edir
+ return self.env_root_dir.joinpath(self.environment).resolve()
+
+ # -------------------------------------------------------------------------
+ @property
+ def file_path(self):
+ """The Puppetfile as a pathlib.Path object."""
+ return self.env_dir / 'Puppetfile'
# -------------------------------------------------------------------------
@property
- def filename(self):
- """The filename of the Puppetfile."""
- return os.path.join(self.env_dir, 'Puppetfile')
+ def filename(self):
+ """The complete path of the Puppetfile as a str object."""
+ return str(self.file_path)
# -------------------------------------------------------------------------
- def get_file_stat(self, forced=False):
+ def _get_file_stat(self, forced=False):
if self._stat is not None and not forced:
return
self._stat = None
return
- self._stat = os.stat(self.filename)
+ self._stat = self.file_path.stat()
# -------------------------------------------------------------------------
@property
def exists(self):
"""A flag, whether the Puppetfile exists."""
- return os.path.exists(self.filename)
+ return self.file_path.exists()
# -------------------------------------------------------------------------
@property
@property
def stat(self):
"""The file status of the Puppetfile."""
- self.get_file_stat()
+ self._get_file_stat()
return self._stat
# -------------------------------------------------------------------------
res['environment'] = self.environment
res['env_dir'] = self.env_dir
res['filename'] = self.filename
+ res['file_path'] = self.file_path
res['exists'] = self.exists
res['readable'] = self.readable
res['stat'] = self.stat
LOG.debug("Searching {!r} ...".format(self.filename))
if not self.exists:
- msg = "Puppetfile {!r} does not exists.".format(self.filename)
+ msg = _("Puppetfile {!r} does not exists.").format(self.filename)
raise PuppetfileError(msg)
if not self.readable:
- msg = "Puppetfile {!r} is not readable.".format(self.filename)
+ msg = _("Puppetfile {!r} is not readable.").format(self.filename)
raise PuppetfileError(msg)
modules = ModuleInfoDict(
LOG.debug("Reading {!r} ...".format(self.filename))
- with open(self.filename, 'r', **self.open_args) as fh:
+ with self.file_path.open('r', **self.open_args) as fh:
prev_line = ''
for line in fh.readlines():
msgstr ""
"Project-Id-Version: puppetmaster_webhooks 1.3.1\n"
"Report-Msgid-Bugs-To: frank.brehm@pixelpark.com\n"
-"POT-Creation-Date: 2019-01-03 11:58+0100\n"
-"PO-Revision-Date: 2019-01-02 11:25+0100\n"
+"POT-Creation-Date: 2019-01-03 12:21+0100\n"
+"PO-Revision-Date: 2019-01-03 12:25+0100\n"
"Last-Translator: Frank Brehm <frank.brehm@pixelpark.com>\n"
"Language: de_DE\n"
"Language-Team: de_DE <LL@li.org>\n"
msgid "Object {{!r}} is not a {} object."
msgstr "Das Objekt {{!r}} ist kein {}-Objekt."
+#: lib/webhooks/puppetfile.py:96
+msgid "The root directory of all puppet environments may not be None."
+msgstr "Das Root-Verzeichnis aller Puppet-Umgebungen darf nicht None sein."
+
+#: lib/webhooks/puppetfile.py:101
+msgid "Path {!r} for the root directory of all puppet environments must be an absolute path."
+msgstr "Der Pfad {!r} zum Root-Verzeichnis aller Puppet-Umgebungen muss ein absoluter Pfad sein."
+
+#: lib/webhooks/puppetfile.py:247
+msgid "Puppetfile {!r} does not exists."
+msgstr "Das Puppetfile {!r} existiert nicht."
+
+#: lib/webhooks/puppetfile.py:251
+msgid "Puppetfile {!r} is not readable."
+msgstr "Das Puppetfile {!r} kann nicht gelesen werden."
+
#: lib/webhooks/show_modules.py:59
msgid "Returns a list with all used Puppet modules."
msgstr "Gibt eine Liste mit allen Puppet-Modulen zurück."
msgstr ""
"Project-Id-Version: puppetmaster_webhooks 1.3.1\n"
"Report-Msgid-Bugs-To: frank.brehm@pixelpark.com\n"
-"POT-Creation-Date: 2019-01-03 11:58+0100\n"
+"POT-Creation-Date: 2019-01-03 12:21+0100\n"
"PO-Revision-Date: 2018-12-28 09:57+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en_US\n"
msgid "Object {{!r}} is not a {} object."
msgstr ""
+#: lib/webhooks/puppetfile.py:96
+msgid "The root directory of all puppet environments may not be None."
+msgstr ""
+
+#: lib/webhooks/puppetfile.py:101
+msgid "Path {!r} for the root directory of all puppet environments must be an absolute path."
+msgstr ""
+
+#: lib/webhooks/puppetfile.py:247
+msgid "Puppetfile {!r} does not exists."
+msgstr ""
+
+#: lib/webhooks/puppetfile.py:251
+msgid "Puppetfile {!r} is not readable."
+msgstr ""
+
#: lib/webhooks/show_modules.py:59
msgid "Returns a list with all used Puppet modules."
msgstr ""
msgstr ""
"Project-Id-Version: puppetmaster_webhooks 1.4.4\n"
"Report-Msgid-Bugs-To: frank.brehm@pixelpark.com\n"
-"POT-Creation-Date: 2019-01-03 11:58+0100\n"
+"POT-Creation-Date: 2019-01-03 12:21+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <frank.brehm@pixelpark.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
msgid "Object {{!r}} is not a {} object."
msgstr ""
+#: lib/webhooks/puppetfile.py:96
+msgid "The root directory of all puppet environments may not be None."
+msgstr ""
+
+#: lib/webhooks/puppetfile.py:101
+msgid "Path {!r} for the root directory of all puppet environments must be an absolute path."
+msgstr ""
+
+#: lib/webhooks/puppetfile.py:247
+msgid "Puppetfile {!r} does not exists."
+msgstr ""
+
+#: lib/webhooks/puppetfile.py:251
+msgid "Puppetfile {!r} is not readable."
+msgstr ""
+
#: lib/webhooks/show_modules.py:59
msgid "Returns a list with all used Puppet modules."
msgstr ""