Skip to content

Commit

Permalink
update the pidfile object with actual data (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
aw-was-here authored Mar 12, 2023
1 parent aee02f1 commit 2137aa0
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions pid/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,27 @@ def setup(self):
self._is_setup = True

def _make_filename(self):
pidname = self.pidname
piddir = self.piddir
if pidname is None:
pidname = f"{os.path.basename(sys.argv[0])}.pid"
if self.enforce_dotpid_postfix and not pidname.endswith(".pid"):
pidname = f"{pidname}.pid"
if piddir is None:
if self.pidname is None:
self.pidname = f"{os.path.basename(sys.argv[0])}.pid"
if self.enforce_dotpid_postfix and not self.pidname.endswith(".pid"):
self.pidname = f"{self.pidname}.pid"

if self.piddir is None:
if os.path.isdir(DEFAULT_PID_DIR) and self.force_tmpdir is False:
piddir = DEFAULT_PID_DIR
self.piddir = DEFAULT_PID_DIR
else:
piddir = tempfile.gettempdir()

if os.path.exists(piddir) and not os.path.isdir(piddir):
raise IOError(f"Pid file directory '{piddir}' exists but is not a directory")
if not os.path.isdir(piddir):
os.makedirs(piddir)
if not effective_access(piddir, os.R_OK):
raise IOError(f"Pid file directory '{piddir}' cannot be read")
if not effective_access(piddir, os.W_OK | os.X_OK):
raise IOError(f"Pid file directory '{piddir}' cannot be written to")

return os.path.abspath(os.path.join(piddir, pidname))
self.piddir = tempfile.gettempdir()

if os.path.exists(self.piddir) and not os.path.isdir(self.piddir):
raise IOError(f"Pid file directory '{self.piddir}' exists but is not a directory")
if not os.path.isdir(self.piddir):
os.makedirs(self.piddir)
if not effective_access(self.piddir, os.R_OK):
raise IOError(f"Pid file directory '{self.piddir}' cannot be read")
if not effective_access(self.piddir, os.W_OK | os.X_OK):
raise IOError(f"Pid file directory '{self.piddir}' cannot be written to")

return os.path.abspath(os.path.join(self.piddir, self.pidname))

def _register_term_signal(self):
register_term_signal_handler = self.register_term_signal_handler
Expand Down

0 comments on commit 2137aa0

Please sign in to comment.