from .pidfile import PidFileError, InvalidPidFileError, PidFileInUseError, PidFile
-__version__ = '0.2.2'
+__version__ = '0.2.3'
LOG = logging.getLogger(__name__)
LOG.error(msg)
self.exit(1)
- LOG.info("Here we go again ...")
+ try:
+ self.pidfile.create()
+ except PidFileError as e:
+ LOG.error("Could not occupy pidfile: {}".format(e))
+ self.exit(7)
+ return
+
+ try:
+
+ LOG.info("Here we go again ...")
+
+ finally:
+ self.cleanup()
+ self.pidfile = None
+
+ # -------------------------------------------------------------------------
+ def cleanup(self):
+
+ LOG.info("Cleaning up ...")
+
+ for tgt_file in self.moved_files.keys():
+ backup_file = self.moved_files[tgt_file]
+ LOG.debug("Searching for {!r}.".format(backup_file))
+ if os.path.exists(backup_file):
+ LOG.info("Removing {!r} ...".format(backup_file))
+ if not self.simulate:
+ os.remove(backup_file)
+
+ # -----------------------
+ def emit_rm_err(function, path, excinfo):
+ LOG.error("Error removing {!r} - {}: {}".format(
+ path, excinfo[1].__class__.__name__, excinfo[1]))
+
+ if self.tempdir:
+ if self.keep_tempdir:
+ msg = (
+ "Temporary directory {!r} will not be removed. "
+ "It's on yours to remove it manually.").format(self.tempdir)
+ LOG.warn(msg)
+ else:
+ LOG.debug("Destroying temporary directory {!r} ...".format(self.tempdir))
+ shutil.rmtree(self.tempdir, False, emit_rm_err)
+ self.tempdir = None
+
# =============================================================================