From: Frank Brehm Date: Fri, 24 Aug 2018 12:54:04 +0000 (+0200) Subject: Cosmetics X-Git-Tag: 0.9.10^2~1 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=6495c004742d23516117becbcc63ac9edf210b87;p=pixelpark%2Fpuppetmaster-webhooks.git Cosmetics --- diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index 418c395..e36d8f2 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.9.8' +__version__ = '0.9.9' # vim: ts=4 et list diff --git a/lib/webhooks/deploy.py b/lib/webhooks/deploy.py index 723c7b3..fdbd0fd 100644 --- a/lib/webhooks/deploy.py +++ b/lib/webhooks/deploy.py @@ -6,6 +6,7 @@ @copyright: © 2017 by Frank Brehm, Berlin @summary: The module for the deploy application object. """ +from __future__ import absolute_import # Standard modules import os @@ -17,13 +18,12 @@ import pipes # Third party modules # Own modules -import webhooks +from . import __version__ -from webhooks.common import pp, to_str +from .common import pp, to_str -from webhooks.base_app import BaseHookApp +from .base_app import BaseHookApp -__version__ = webhooks.__version__ LOG = logging.getLogger(__name__) DEFAULT_PARENT_DIR = '/etc/puppetlabs/code/fileserver' diff --git a/lib/webhooks/lock_handler.py b/lib/webhooks/lock_handler.py index 2be98b6..f0e6475 100644 --- a/lib/webhooks/lock_handler.py +++ b/lib/webhooks/lock_handler.py @@ -33,9 +33,9 @@ from .obj import BaseObject from .handler import BaseHandlerError, BaseHandler -__version__ = '0.2.2' +__version__ = '0.2.3' -log = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) # Module variables DEFAULT_LOCKRETRY_DELAY_START = 0.1 @@ -329,9 +329,9 @@ class LockObject(BaseObject): msg = "Closing file descriptor {} ...".format(self.fd) if self.silent: if self.verbose >= 2: - log.debug(msg) + LOG.debug(msg) else: - log.debug(msg) + LOG.debug(msg) os.close(self.fd) self._fd = None @@ -340,9 +340,9 @@ class LockObject(BaseObject): msg = "Automatic removing of {!r} ...".format(self.lockfile) if self.silent: if self.verbose >= 2: - log.debug(msg) + LOG.debug(msg) else: - log.info(msg) + LOG.info(msg) if not self.simulate: os.remove(self.lockfile) @@ -363,7 +363,7 @@ class LockObject(BaseObject): """ msg = "Refreshing atime and mtime of {!r} to the current timestamp.".format(self.lockfile) - log.debug(msg) + LOG.debug(msg) if not self.simulate: os.utime(self.lockfile, None) @@ -778,9 +778,9 @@ class LockHandler(BaseHandler): lockfile = os.path.normpath(os.path.join(self.lockdir, lockfile)) lockdir = os.path.dirname(lockfile) - log.debug("Trying to lock lockfile {!r} ...".format(lockfile)) + LOG.debug("Trying to lock lockfile {!r} ...".format(lockfile)) if self.verbose > 1: - log.debug("Using lock directory {!r} ...".format(lockdir)) + LOG.debug("Using lock directory {!r} ...".format(lockdir)) if not os.path.isdir(lockdir): raise LockdirNotExistsError(lockdir) @@ -788,7 +788,7 @@ class LockHandler(BaseHandler): if not os.access(lockdir, os.W_OK): msg = "Locking directory {!r} isn't writeable.".format(lockdir) if self.simulate: - log.error(msg) + LOG.error(msg) else: raise LockdirNotWriteableError(lockdir) @@ -817,12 +817,12 @@ class LockHandler(BaseHandler): counter += 1 if self.verbose > 3: - log.debug("Current time difference: {:0.3f} seconds.".format(time_diff)) + LOG.debug("Current time difference: {:0.3f} seconds.".format(time_diff)) if time_diff >= max_delay: break # Try creating lockfile exclusive - log.debug("Try {try_nr} on creating lockfile {lfile!r} ...".format( + LOG.debug("Try {try_nr} on creating lockfile {lfile!r} ...".format( try_nr=counter, lfile=lockfile)) ctime = datetime.datetime.utcnow() fd = self._create_lockfile(lockfile) @@ -834,14 +834,14 @@ class LockHandler(BaseHandler): if not self.check_lockfile(lockfile, max_age, use_pid): # No other process is using this lockfile if os.path.exists(lockfile): - log.info("Removing lockfile {!r} ...".format(lockfile)) + LOG.info("Removing lockfile {!r} ...".format(lockfile)) try: if not self.simulate: os.remove(lockfile) except Exception as e: msg = "Error on removing lockfile {lfile!r): {err}".format( lfile=lockfile, err=e) - log.error(msg) + LOG.error(msg) time.sleep(delay) delay += delay_increase continue @@ -852,7 +852,7 @@ class LockHandler(BaseHandler): # No success, then retry later if self.verbose > 2: - log.debug("Sleeping for {:0.1f} seconds.".format(float(delay))) + LOG.debug("Sleeping for {:0.1f} seconds.".format(float(delay))) time.sleep(delay) delay += delay_increase @@ -863,17 +863,17 @@ class LockHandler(BaseHandler): if raise_on_fail: raise e else: - log.error(msg) + LOG.error(msg) return None # or an int for success msg = "Got a lock for lockfile {!r}.".format(lockfile) if self.silent: - log.debug(msg) + LOG.debug(msg) else: - log.info(msg) + LOG.info(msg) out = to_utf8("{}\n".format(pid)) - log.debug("Write {what!r} in lockfile {lfile!r} ...".format( + LOG.debug("Write {what!r} in lockfile {lfile!r} ...".format( what=out, lfile=lockfile)) finally: @@ -882,11 +882,11 @@ class LockHandler(BaseHandler): os.write(fd, out) if stay_opened: - log.debug("Seeking and syncing {!r} ...".format(lockfile)) + LOG.debug("Seeking and syncing {!r} ...".format(lockfile)) os.lseek(fd, 0, 0) os.fsync(fd) else: - log.debug("Closing {!r} ...".format(lockfile)) + LOG.debug("Closing {!r} ...".format(lockfile)) os.close(fd) fd = None @@ -914,9 +914,9 @@ class LockHandler(BaseHandler): """ if self.verbose > 1: - log.debug("Trying to open {!r} exclusive ...".format(lockfile)) + LOG.debug("Trying to open {!r} exclusive ...".format(lockfile)) if self.simulate: - log.debug("Simulation mode, no real creation of a lockfile.") + LOG.debug("Simulation mode, no real creation of a lockfile.") return -1 fd = None @@ -927,7 +927,7 @@ class LockHandler(BaseHandler): msg = "Error on creating lockfile {lfile!r}: {err}".format( lfile=lockfile, err=e) if e.errno == errno.EEXIST: - log.debug(msg) + LOG.debug(msg) return None else: error_tuple = sys.exc_info() @@ -954,21 +954,21 @@ class LockHandler(BaseHandler): lockfile = os.path.normpath(os.path.join(self.lockdir, lockfile)) if not os.path.exists(lockfile): - log.debug("Lockfile {!r} to remove doesn't exists.".format(lockfile)) + LOG.debug("Lockfile {!r} to remove doesn't exists.".format(lockfile)) return True - log.info("Removing lockfile {!r} ...".format(lockfile)) + LOG.info("Removing lockfile {!r} ...".format(lockfile)) if self.simulate: - log.debug("Simulation mode - lockfile won't removed.") + LOG.debug("Simulation mode - lockfile won't removed.") return True try: os.remove(lockfile) except Exception as e: - log.error("Error on removing lockfile {lfile!r}: {err}".format(lfile=lockfile, err=e)) + LOG.error("Error on removing lockfile {lfile!r}: {err}".format(lfile=lockfile, err=e)) if self.verbose: tb = traceback.format_exc() - log.debug("Stacktrace:\n" + tb) + LOG.debug("Stacktrace:\n" + tb) return False return True @@ -1017,31 +1017,31 @@ class LockHandler(BaseHandler): val=max_age, what='max_age') raise LockHandlerError(msg) - log.debug("Checking lockfile {!r} ...".format(lockfile)) + LOG.debug("Checking lockfile {!r} ...".format(lockfile)) if not os.path.exists(lockfile): if self.verbose > 2: - log.debug("Lockfile {!r} doesn't exists.".format(lockfile)) + LOG.debug("Lockfile {!r} doesn't exists.".format(lockfile)) return False if not os.access(lockfile, os.R_OK): - log.warn("No read access for lockfile {!r}.".format(lockfile)) + LOG.warn("No read access for lockfile {!r}.".format(lockfile)) return True if not os.access(lockfile, os.W_OK): - log.warn("No write access for lockfile {!r}.".format(lockfile)) + LOG.warn("No write access for lockfile {!r}.".format(lockfile)) return True if use_pid: pid = self.get_pid_from_file(lockfile, True) if pid is None: - log.warn("Unusable lockfile {!r}.".format(lockfile)) + LOG.warn("Unusable lockfile {!r}.".format(lockfile)) else: if self.dead(pid): - log.warn("Process with PID {} is unfortunately dead.".format(pid)) + LOG.warn("Process with PID {} is unfortunately dead.".format(pid)) return False else: - log.debug("Process with PID {} is still running.".format(pid)) + LOG.debug("Process with PID {} is still running.".format(pid)) return True fstat = None @@ -1049,19 +1049,19 @@ class LockHandler(BaseHandler): fstat = os.stat(lockfile) except OSError as e: if e.errno == errno.ENOENT: - log.info("Could not stat for file {lfile!r}: {err}".format( + LOG.info("Could not stat for file {lfile!r}: {err}".format( lfile=lockfile, err=e.strerror)) return False raise age = time.time() - fstat.st_mtime if age >= max_age: - log.debug("Lockfile {lfile!r} is older than {max} seconds ({age} seconds).".format( + LOG.debug("Lockfile {lfile!r} is older than {max} seconds ({age} seconds).".format( lfile=lockfile, max=max_age, age=age)) return False msg = "Lockfile {lfile!r} is {age} seconds old, but not old enough ({max}seconds).".format( lfile=lockfile, max=max_age, age=age) - log.debug(msg) + LOG.debug(msg) return True # ------------------------------------------------------------------------- @@ -1083,14 +1083,14 @@ class LockHandler(BaseHandler): """ if self.verbose > 1: - log.debug("Trying to open pidfile {!r} ...".format(pidfile)) + LOG.debug("Trying to open pidfile {!r} ...".format(pidfile)) try: fh = open(pidfile, "rb") except Exception as e: msg = "Could not open pidfile {!r} for reading: ".format(pidfile) msg += str(e) if force: - log.warn(msg) + LOG.warn(msg) return None else: raise LockHandlerError(str(e)) @@ -1102,7 +1102,7 @@ class LockHandler(BaseHandler): if content == "": msg = "First line of pidfile {!r} was empty.".format(pidfile) if force: - log.warn(msg) + LOG.warn(msg) return None else: raise LockHandlerError(msg) @@ -1114,7 +1114,7 @@ class LockHandler(BaseHandler): msg = "Could not interprete {cont!r} as a PID from {file!r}: {err}".format( cont=content, file=pidfile, err=e) if force: - log.warn(msg) + LOG.warn(msg) return None else: raise LockHandlerError(msg) @@ -1122,7 +1122,7 @@ class LockHandler(BaseHandler): if pid <= 0: msg = "Invalid PID {pid} in {file!r} found.".format(pid=pid, file=pidfile) if force: - log.warn(msg) + LOG.warn(msg) return None else: raise LockHandlerError(msg) diff --git a/lib/webhooks/r10k.py b/lib/webhooks/r10k.py index fdec7b8..3d485b7 100644 --- a/lib/webhooks/r10k.py +++ b/lib/webhooks/r10k.py @@ -22,7 +22,7 @@ import warnings import requests # Own modules -import webhooks +from . import __version__ from .common import to_str @@ -30,7 +30,6 @@ from .base_app import BaseHookApp from .handler import BaseHandler -__version__ = webhooks.__version__ LOG = logging.getLogger(__name__)