From: Frank Brehm Date: Thu, 3 Jan 2019 11:24:55 +0000 (+0100) Subject: Translating lib/webhooks/puppetfile.py X-Git-Tag: 1.6.4^2~81 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=3539ee15ed93f83f92b4e5ef67d1997e9b43a76b;p=pixelpark%2Fpuppetmaster-webhooks.git Translating lib/webhooks/puppetfile.py --- diff --git a/lib/webhooks/puppetfile.py b/lib/webhooks/puppetfile.py index 605365b..cd3438b 100644 --- a/lib/webhooks/puppetfile.py +++ b/lib/webhooks/puppetfile.py @@ -15,6 +15,7 @@ import os import re import pwd import grp +import pathlib # Third party modules import six @@ -26,10 +27,15 @@ from .module_info import ModuleInfo 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): @@ -43,6 +49,7 @@ class Puppetfile(FbBaseObject): 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*$') @@ -86,12 +93,12 @@ class Puppetfile(FbBaseObject): @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) @@ -120,19 +127,22 @@ class Puppetfile(FbBaseObject): @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 @@ -143,13 +153,13 @@ class Puppetfile(FbBaseObject): 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 @@ -167,7 +177,7 @@ class Puppetfile(FbBaseObject): @property def stat(self): """The file status of the Puppetfile.""" - self.get_file_stat() + self._get_file_stat() return self._stat # ------------------------------------------------------------------------- @@ -215,6 +225,7 @@ class Puppetfile(FbBaseObject): 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 @@ -233,11 +244,11 @@ class Puppetfile(FbBaseObject): 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( @@ -245,7 +256,7 @@ class Puppetfile(FbBaseObject): 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(): diff --git a/locale/de_DE/LC_MESSAGES/puppetmaster_webhooks.po b/locale/de_DE/LC_MESSAGES/puppetmaster_webhooks.po index f7f4fe9..ed41243 100644 --- a/locale/de_DE/LC_MESSAGES/puppetmaster_webhooks.po +++ b/locale/de_DE/LC_MESSAGES/puppetmaster_webhooks.po @@ -7,8 +7,8 @@ msgid "" 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 \n" "Language: de_DE\n" "Language-Team: de_DE \n" @@ -528,6 +528,22 @@ msgstr "Ein leere Schlüssel is nicht erlaubt." 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." diff --git a/locale/en_US/LC_MESSAGES/puppetmaster_webhooks.po b/locale/en_US/LC_MESSAGES/puppetmaster_webhooks.po index 20c552c..8aaeffe 100644 --- a/locale/en_US/LC_MESSAGES/puppetmaster_webhooks.po +++ b/locale/en_US/LC_MESSAGES/puppetmaster_webhooks.po @@ -7,7 +7,7 @@ msgid "" 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 \n" "Language: en_US\n" @@ -504,6 +504,22 @@ msgstr "" 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 "" diff --git a/locale/puppetmaster_webhooks.pot b/locale/puppetmaster_webhooks.pot index 0979755..333d8e1 100644 --- a/locale/puppetmaster_webhooks.pot +++ b/locale/puppetmaster_webhooks.pot @@ -8,7 +8,7 @@ msgid "" 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 \n" "Language-Team: LANGUAGE \n" @@ -503,6 +503,22 @@ msgstr "" 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 ""