Skip to content

Commit

Permalink
Merge pull request #34 from rbscholtus/windows/pidfile-locations
Browse files Browse the repository at this point in the history
Use APPDATA and HOME locations on Windows
  • Loading branch information
trbs authored Jul 18, 2020
2 parents 64aa87c + 0356a1d commit 56be516
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

3.0.4
-----

- Use APPDATA and HOME locations on Windows


3.0.3
-----

Expand Down
3 changes: 1 addition & 2 deletions pid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
else:
from .posix import PidFile # NOQA


__version__ = "3.0.3"
__version__ = "3.0.4"
__all__ = [
'__version__',
'DEFAULT_PID_DIR',
Expand Down
23 changes: 13 additions & 10 deletions pid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ def effective_access(*args, **kwargs):

def determine_pid_directory():
if sys.platform == "win32":
return tempfile.gettempdir()

uid = os.geteuid() if hasattr(os, "geteuid") else os.getuid()

paths = [
"/run/user/%s/" % uid,
"/var/run/user/%s/" % uid,
"/run/",
"/var/run/",
]
if 'APPDATA' in os.environ:
paths = [os.environ['APPDATA']]
else:
paths = [os.path.expanduser('~\\AppData\\Roaming')]
else:
uid = os.geteuid() if hasattr(os, "geteuid") else os.getuid() # pylint: disable=no-member

paths = [
"/run/user/%s/" % uid,
"/var/run/user/%s/" % uid,
"/run/",
"/var/run/",
]

for path in paths:
if effective_access(os.path.realpath(path), os.W_OK | os.X_OK):
Expand Down

0 comments on commit 56be516

Please sign in to comment.