Add downgrade functionality (contributed script)

This commit is contained in:
Bas Stottelaar
2014-11-12 19:29:11 +01:00
parent 548e0a9821
commit bb7b1f64ce
3 changed files with 57 additions and 9 deletions
+2 -4
View File
@@ -6,12 +6,13 @@
*.pyproj *.pyproj
*.sln *.sln
# Logs and databases # # Headphones files #
###################### ######################
*.log *.log
*.db* *.db*
*.db-journal *.db-journal
*.ini *.ini
version.lock
logs/* logs/*
cache/* cache/*
@@ -64,6 +65,3 @@ _ReSharper*/
/logs /logs
.project .project
.pydevproject .pydevproject
headphones_docs
+38
View File
@@ -0,0 +1,38 @@
#!/bin/bash
# Parameter check
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Syntax: $0 <source directory> <data directory>"
exit 1
fi
# Repository check
if [ ! -d "$1/.git" ]; then
echo "This script can only downgrade Headphones installations via Git."
exit 1
fi
# Version file check
if [ ! -s "$2/version.lock" ]; then
echo "Missing the version.lock file in the data folder, or the file is empty. Did you start Headphones at least once?"
exit 1
fi
# Git installation check
if [ ! -x "$(command -v wget)" ]; then
echo "Git is required to downgrade."
exit 1
fi
# Display information
HASH=$(cat $2/version.lock)
echo "This script will try to downgrade Headphones to the last version that started, version $HASH. Make sure you have a backup of your config file and database, just in case!"
echo "Press enter to continue, or CTRL + C to quit."
read
# Downgrade
cd "$1"
git reset --hard "$HASH"
echo "All done, Headphones should be downgraded to the last version that started."
+17 -5
View File
@@ -138,9 +138,8 @@ def initialize(config_file):
if not os.path.exists(CONFIG.CACHE_DIR): if not os.path.exists(CONFIG.CACHE_DIR):
try: try:
os.makedirs(CONFIG.CACHE_DIR) os.makedirs(CONFIG.CACHE_DIR)
except OSError: except OSError as e:
logger.error( logger.error("Could not create cache dir '%s': %s", DATA_DIR, e)
'Could not create cache dir. Check permissions of datadir: %s', DATA_DIR)
# Sanity check for search interval. Set it to at least 6 hours # Sanity check for search interval. Set it to at least 6 hours
if CONFIG.SEARCH_INTERVAL < 360: if CONFIG.SEARCH_INTERVAL < 360:
@@ -154,10 +153,23 @@ def initialize(config_file):
except Exception as e: except Exception as e:
logger.error("Can't connect to the database: %s", e) logger.error("Can't connect to the database: %s", e)
# Get the currently installed version - returns None, 'win32' or the git hash # Get the currently installed version. Returns None, 'win32' or the git
# Also sets INSTALL_TYPE variable to 'win', 'git' or 'source' # hash.
CURRENT_VERSION, CONFIG.GIT_BRANCH = versioncheck.getVersion() CURRENT_VERSION, CONFIG.GIT_BRANCH = versioncheck.getVersion()
# Write current version to a file, so we know which version did work.
# This allowes one to restore to that version. The idea is that if we
# arrive here, most parts of Headphones seem to work.
if CURRENT_VERSION:
version_lock_file = os.path.join(DATA_DIR, "version.lock")
try:
with open(version_lock_file, "w") as fp:
fp.write(CURRENT_VERSION)
except IOError as e:
logger.error("Unable to write current version to file '%s': %s",
version_lock_file, e)
# Check for new versions # Check for new versions
if CONFIG.CHECK_GITHUB_ON_STARTUP: if CONFIG.CHECK_GITHUB_ON_STARTUP:
try: try: