-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added encapsulation to return a valid UNIX socket path always, resolves
- Loading branch information
1 parent
5462f7c
commit bf3e2fd
Showing
5 changed files
with
64 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
# Copyright (C) 2013 ~ 2016 - Oscar Campos <[email protected]> | ||
# This program is Free Software se LICENSE file for details | ||
|
||
import os | ||
import platform | ||
import tempfile | ||
|
||
|
||
class UnixSocketPath(object): | ||
"""Encapsulate logic to handle with paths to UNIX domain sockets | ||
""" | ||
|
||
socketpath = { | ||
'linux': os.path.join('~', '.local', 'share', 'anaconda', 'run'), | ||
'darwin': os.path.join( | ||
'~', 'Library', 'Application Support', 'Anaconda') | ||
} | ||
|
||
def __init__(self, project): | ||
self.__project = project | ||
self.__socket_file = os.path.join( | ||
os.path.expanduser( | ||
UnixSocketPath.socketpath.get(platform.system().lower()) | ||
), | ||
project or 'anaconda', | ||
'anaconda.sock' | ||
) | ||
|
||
@property | ||
def socket(self): | ||
"""Return back a valid socket path always | ||
""" | ||
|
||
if len(self.__socket_file) < 103: | ||
return self.__socket_file | ||
|
||
socket_path = os.path.join( | ||
tempfile.gettempdir(), | ||
self.__project or 'anaconda', | ||
'anaconda.sock' | ||
) | ||
if len(socket_path) > 103: | ||
# probably the project name is crazy long | ||
socket_path = os.path.join( | ||
tempfile.gettempdir(), self.__project[:10], 'anaconda.sock' | ||
) | ||
|
||
return socket_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters