-
Notifications
You must be signed in to change notification settings - Fork 250
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
Respect XDG Base Directory spec #239
Merged
Merged
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
import sys | ||
from shutil import move | ||
from colorama import Fore | ||
from .config import get_config_path | ||
from .printing import prompt_yes_no, print_green_bold, print_red_bold | ||
from .utils import home_prefix, safe_mkdir | ||
|
||
|
||
def upgrade_from_pre_v3(): | ||
""" | ||
Before v3.0, the config file was stored at ~/.shallow-backup. In v3.0, | ||
the XDG Base Directory specification was adopted and the new config is | ||
stored in either $XDG_CONFIG_HOME/shallow-backup/shallow-backup.conf or | ||
~/.config/shallow-backup/shallow-backup.conf. This method upgrades from | ||
v < 3.0 to v3.0 if required. | ||
""" | ||
old_config_name = ".shallow-backup" | ||
old_config_path = home_prefix(old_config_name) | ||
if os.path.isfile(old_config_path): | ||
if prompt_yes_no("Config file from a version before v3.0 detected. Would you like to upgrade?", Fore.GREEN): | ||
new_config_path = get_config_path() | ||
print_green_bold(f"Moving {old_config_path} to {new_config_path}") | ||
if os.path.exists(new_config_path): | ||
print_red_bold(f"ERROR: {new_config_path} already exists. Manual intervention is required.") | ||
sys.exit(1) | ||
|
||
safe_mkdir(os.path.split(new_config_path)[0]) | ||
move(old_config_path, new_config_path) | ||
|
||
print_green_bold("Replacing old shallow-backup config path with new config path in config file.") | ||
with open(new_config_path, "r") as f: | ||
contents = f.read() | ||
contents = contents.replace(old_config_name, | ||
new_config_path.replace(os.path.expanduser('~') + "/", "")) | ||
|
||
with open(new_config_path, "w") as f: | ||
f.write(contents) | ||
|
||
print_green_bold("Successful upgrade.") | ||
else: | ||
print_red_bold("Please downgrade to a version of shallow-backup before v3.0 if you do not want to upgrade your config.") | ||
sys.exit() | ||
elif os.path.isdir(old_config_path): | ||
print_red_bold(f"ERROR: {old_config_path} is a directory, when we were expecting a file. Manual intervention is required.") | ||
sys.exit(1) |
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.
Issue found: invalid syntax