This repository was archived by the owner on Nov 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 203
Use XDG Base Directories #96
Open
aDogCalledSpot
wants to merge
1
commit into
Rafficer:master
Choose a base branch
from
aDogCalledSpot:xdg_base_directory
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -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" | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_HOMEandXDG_CONFIG_HOMEenvironment 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
$HOMEdirectories 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 (
/etcfor config files,/var/logfor logs, etc....). Having the$HOMEorganized thus does not increase its complexity. Rather it only improves upon organization facilitating automated maintenance/archival tasks.