Skip to content

Commit

Permalink
Renaming db, backups and log files
Browse files Browse the repository at this point in the history
  • Loading branch information
ratoaq2 committed Oct 12, 2016
1 parent 60154d6 commit 269e4eb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
/data/
restore/
backup*/
backup-*.zip
cache.db*
config.ini*
sickbeard.db*
main.db.*
failed.db*
*.db
autoProcessTV.cfg
Expand Down
13 changes: 7 additions & 6 deletions medusa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
LEGACY_SRC_FOLDERS = ('sickbeard', 'sickrage')
LIB_FOLDER = 'lib'
UNKNOWN_RELEASE_GROUP = 'Medusa'
# TODO: allow restore to ready sickrage-{timestamp}.zip and medusa-{timestamp}.zip
BACKUP_FILENAME = 'sickrage-{timestamp}.zip'
# TODO: change db to medusa
APPLICATION_DB = 'sickbeard.db'
BACKUP_DIR = 'backup'
BACKUP_FILENAME_PREFIX = 'backup'
BACKUP_FILENAME = BACKUP_FILENAME_PREFIX + '-{timestamp}.zip'
LEGACY_DB = 'sickbeard.db'
APPLICATION_DB = 'main.db'
FAILED_DB = 'failed.db'
CACHE_DB = 'cache.db'
# TODO: change log to medusa
LOG_FILENAME = 'sickrage.log'
LOG_FILENAME = 'application.log'
CONFIG_INI = 'config.ini'
GIT_ORG = 'pymedusa'
GIT_REPO = 'Medusa'
Expand Down Expand Up @@ -734,6 +734,7 @@ def initialize(consoleLogging=True): # pylint: disable=too-many-locals, too-man
sys.exit(7)

# init logging
logger.backwards_compatibility()
logger.init_logging(console_logging=consoleLogging)

# git reset on update
Expand Down
13 changes: 13 additions & 0 deletions medusa/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,19 @@ def reconfigure():
instance.reconfigure_file_handler()


def backwards_compatibility():
"""Keep backwards compatibility renaming old log files."""
log_re = re.compile(r'\w+\.log(?P<suffix>\.\d+)?')
cwd = os.getcwd() if os.path.isabs(app.DATA_DIR) else ''
for filename in os.listdir(app.LOG_DIR):
# Rename log files
match = log_re.match(filename)
if match:
new_file = os.path.join(cwd, app.LOG_DIR, app.LOG_FILENAME + (match.group('suffix') or ''))
os.rename(os.path.join(cwd, app.LOG_DIR, filename), new_file)
continue


# Keeps the standard logging.getLogger to be used by SylteAdapter
standard_logger = logging.getLogger

Expand Down
2 changes: 1 addition & 1 deletion medusa/versionChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _runbackup(self):
logger.log(u"Config backup in progress...")
ui.notifications.message('Backup', 'Config backup in progress...')
try:
backupDir = os.path.join(app.DATA_DIR, 'backup')
backupDir = os.path.join(app.DATA_DIR, app.BACKUP_DIR)
if not os.path.isdir(backupDir):
os.mkdir(backupDir)

Expand Down
23 changes: 23 additions & 0 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import locale
import mimetypes
import os
import re
import shutil
import signal
import subprocess
Expand Down Expand Up @@ -263,6 +264,9 @@ def start(self, args): # pylint: disable=too-many-branches,too-many-statements
if option in ('--noresize',):
app.NO_RESIZE = True

# Keep backwards compatibility
Application.backwards_compatibility()

# The pid file is only useful in daemon mode, make sure we can write the file properly
if self.create_pid:
if self.run_as_daemon:
Expand Down Expand Up @@ -393,6 +397,25 @@ def start(self, args): # pylint: disable=too-many-branches,too-many-statements
while True:
time.sleep(1)

@staticmethod
def backwards_compatibility():
if os.path.isdir(app.DATA_DIR):
cwd = os.getcwd() if os.path.isabs(app.DATA_DIR) else ''
backup_re = re.compile(r'[^\d]+(?P<suffix>-\d{14}\.zip)')
for filename in os.listdir(app.DATA_DIR):
# Rename database file
if filename.startswith(app.LEGACY_DB):
new_file = os.path.join(cwd, app.DATA_DIR, app.APPLICATION_DB + filename[len(app.LEGACY_DB):])
os.rename(os.path.join(cwd, app.DATA_DIR, filename), new_file)
continue

# Rename old backups
match = backup_re.match(filename)
if match:
new_file = os.path.join(cwd, app.DATA_DIR, app.BACKUP_FILENAME_PREFIX + match.group('suffix'))
os.rename(os.path.join(cwd, app.DATA_DIR, filename), new_file)
continue

def daemonize(self):
"""
Fork off as a daemon
Expand Down

0 comments on commit 269e4eb

Please sign in to comment.