-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use XDG Base Directories #96
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,44 @@ | |
except KeyError: | ||
USER = getpass.getuser() | ||
|
||
CONFIG_DIR = os.path.join(os.path.expanduser("~{0}".format(USER)), ".pvpn-cli") | ||
# Ensure backwards compatibility | ||
home_path = os.path.expanduser("~{0}".format(USER)) | ||
home_config = os.path.join(home_path, ".pvpn-cli") | ||
if os.path.exists(home_config): | ||
CONFIG_DIR = home_config | ||
DATA_DIR = home_config | ||
CACHE_DIR = home_config | ||
|
||
else: | ||
# Get the config directory | ||
xdg_config_str = os.getenv("XDG_CONFIG_HOME") | ||
if not xdg_config_str: | ||
xdg_config = os.path.join(home_path, ".config") | ||
else: | ||
xdg_config = os.path.realpath(xdg_config_str) | ||
Comment on lines
+19
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: perhaps you can simplify it by writing xdg_config = os.path.realpath(
os.getenv("XDG_CONFIG_HOME", os.path.join(home_path, ".config"))
) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also use the XDG module (last updated April of 2021) to facilitate the base directory specification. |
||
CONFIG_DIR = os.path.join(xdg_config, "pvpn-cli") | ||
|
||
# Get the data directory | ||
xdg_data_str = os.getenv("XDG_DATA_HOME") | ||
if not xdg_data_str: | ||
xdg_data = os.path.join(home_path, ".local/share") | ||
else: | ||
xdg_data = os.path.realpath(xdg_data_str) | ||
DATA_DIR = os.path.join(xdg_data, "pvpn-cli") | ||
|
||
# Get the cache directory | ||
xdg_cache_str = os.getenv("XDG_CACHE_HOME") | ||
if not xdg_cache_str: | ||
xdg_cache = os.path.join(home_path, ".cache") | ||
else: | ||
xdg_cache = os.path.realpath(xdg_cache_str) | ||
CACHE_DIR = os.path.join(xdg_cache, "pvpn-cli") | ||
|
||
|
||
CONFIG_FILE = os.path.join(CONFIG_DIR, "pvpn-cli.cfg") | ||
TEMPLATE_FILE = os.path.join(CONFIG_DIR, "template.ovpn") | ||
SERVER_INFO_FILE = os.path.join(CONFIG_DIR, "serverinfo.json") | ||
SPLIT_TUNNEL_FILE = os.path.join(CONFIG_DIR, "split_tunnel.txt") | ||
OVPN_FILE = os.path.join(CONFIG_DIR, "connect.ovpn") | ||
PASSFILE = os.path.join(CONFIG_DIR, "pvpnpass") | ||
TEMPLATE_FILE = os.path.join(CACHE_DIR, "template.ovpn") | ||
SERVER_INFO_FILE = os.path.join(CACHE_DIR, "serverinfo.json") | ||
SPLIT_TUNNEL_FILE = os.path.join(DATA_DIR, "split_tunnel.txt") | ||
OVPN_FILE = os.path.join(DATA_DIR, "connect.ovpn") | ||
PASSFILE = os.path.join(DATA_DIR, "pvpnpass") | ||
VERSION = "2.2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be
LOG_DIR
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There currently isn't a LOG_DIR as there isn't one listed in the specification. As log files are not necessary to run the program they are placed into the CACHE_DIR. I could make a separate LOG_DIR and have that be the same as CACHE_DIR to make the code clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I just see that XDG standard is incomplete here: https://stackoverflow.com/questions/25897836/where-should-i-write-a-user-specific-log-file-to-and-be-xdg-base-directory-comp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The specification does state the following
This was was already stated in the stack overflow link above as well.
Admittedly I have not defined this environment variable in my own implementation. (I only have
XDG_DATA_HOME
andXDG_CONFIG_HOME
environment variable defined).While it may not be set in stone, I think the XDG Base Directories is the best and most widely accepted standard that we have. Implementing this will further encourage adoption, keep
$HOME
directories clean and easier to maintain. This change also is somewhat trivial and provides more value than the pain of adding it.While I understand that this seems to scatter the various files needed by protonvpn_cli among the different directories, keep in mind that this is the case with system applications as well (
/etc
for config files,/var/log
for logs, etc....). Having the$HOME
organized thus does not increase its complexity. Rather it only improves upon organization facilitating automated maintenance/archival tasks.