# Third party modules
import yaml
+import pytz
# Own modules
import webhooks
fileserver_dir = os.path.join(puppetlabs_cfg_dir, 'code', 'fileserver')
default_data_dir = os.sep + os.path.join('var', 'lib', 'webhooks')
+ default_tz_name = 'Europe/Berlin'
special_chars_re = re.compile(r'[^a-z0-9_\-]', re.IGNORECASE)
dev_re = re.compile(r'^dev')
self.data_dir = self.default_data_dir
self._read_stdin = True
+ self.tz_name = self.default_tz_name
super(BaseHookApp, self).__init__(
appname=appname, verbose=verbose, version=version,
self.full_name = None
self.git_ssh_url = None
self.do_sudo = True
+ self.tz = None
self.cmdline_args = None
appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
simulate=self.simulate)
+ self.tz = pytz.timezone(self.tz_name)
+
self.post_init()
return
res['fileserver_dir'] = self.fileserver_dir
res['default_data_dir'] = self.default_data_dir
res['read_stdin'] = self.read_stdin
+ res['default_tz_name'] = self.default_tz_name
return res
if os.path.isabs(pdir):
self.default_parent_dir = pdir
+ if 'tz' in config and config['tz']:
+ tz = str(config['tz']).strip()
+ if tz:
+ self.tz_name = tz
+
if 'data_dir' in config and config['data_dir'] and not self.cmdline_args.data_dir:
path = config['data_dir']
if not os.path.isabs(path):
import re
import copy
import warnings
+import time
# Third party modules
import six
import requests
+import pytz
# Own modules
from .common import pp, to_str, to_bool, is_sequence
self.forge_releases = None
self._forge_homepage_url = None
self._forge_source = None
+ self._ts_checked = None
super(ModuleInfo, self).__init__(
appname=appname, verbose=verbose, version=version,
return
self._forge_avail = to_bool(value)
+ # -------------------------------------------------------------------------
+ @property
+ def ts_checked(self):
+ """The timestamp, when this module was checked on Puppet forge."""
+ return self._ts_checked
+
+ @ts_checked.setter
+ def ts_checked(self, value):
+ if value is None:
+ self._ts_checked = None
+ return
+ self._ts_checked = float(value)
+
+ # -------------------------------------------------------------------------
+ @property
+ def date_checked(self):
+ """A string representation of the check timestamp, if such one is given."""
+ if self.ts_checked is None:
+ return None
+ dt = datetime.datetime.fromtimestamp(self.ts_checked, tz=pytz.utc)
+ return dt.strftime('%Y-%m-%d %H:%M:%S %Z')
+
+ # -------------------------------------------------------------------------
+ def set_ts_checked(self):
+ self._ts_checked = time.time()
+
# -------------------------------------------------------------------------
def __repr__(self):
return str(self)
res['forge_avail'] = self.forge_avail
res['forge_homepage_url'] = self.forge_homepage_url
res['forge_source'] = self.forge_source
+ res['ts_checked'] = self.ts_checked
+ res['date_checked'] = self.date_checked
return res
res['forge_homepage_url'] = self.forge_homepage_url
res['forge_source'] = self.forge_source
res['repo'] = self.repo
+ res['ts_checked'] = self.ts_checked
res['local_versions'] = copy.copy(self.local_versions)
res['expected_versions'] = copy.copy(self.expected_versions)
if other.repo and not self.repo:
self.repo = other.repo
+ if other.ts_checked and not self.ts_checked:
+ self.ts_checked = other.ts_checked
+
for env in other.local_versions.keys():
if env not in self.local_versions:
self.local_versions[env] = other.local_versions[env]
if 'version' in release and release['version']:
module_info.forge_releases.append(release['version'].strip())
+ module_info.set_ts_checked()
+
return module_info
# =============================================================================