def execute(self): numTries = 0 while not ek.ek(os.path.isfile, db.dbFilename(suffix='v0')): if not ek.ek(os.path.isfile, db.dbFilename()): break try: logger.log( u"Attempting to back up your sickbeard.db file before migration..." ) shutil.copy(db.dbFilename(), db.dbFilename(suffix='v0')) logger.log(u"Done backup, proceeding with migration.") break except Exception, e: logger.log( u"Error while trying to back up your sickbeard.db: " + ex(e)) numTries += 1 time.sleep(1) logger.log(u"Trying again.") if numTries >= 10: logger.log( u"Unable to back up your sickbeard.db file, please do it manually." ) sys.exit(1)
def __init__(self, dbname): self.db_versions = {} self.db_name = dbname self.my_db = db.DBConnection(self.db_name) self.filename = db.dbFilename(self.db_name) self.backup_filename = db.dbFilename(self.db_name, 'bak') self.rollback_version = None
def backupDatabase(version): logger.log(u"Backing up database before upgrade") if not helpers.backupVersionedFile(db.dbFilename(), version): logger.log_error_and_exit(u"Database backup failed, abort upgrading database") else: logger.log(u"Proceeding with upgrade")
def backupDatabase(version): logger.log(u"Backing up database before upgrade") if not helpers.backupVersionedFile(db.dbFilename(), version): logger.log_error_and_exit( u"Database backup failed, abort upgrading database") else: logger.log(u"Proceeding with upgrade")
def execute(self): numTries = 0 while not ek.ek(os.path.isfile, db.dbFilename(suffix='v0')): if not ek.ek(os.path.isfile, db.dbFilename()): break try: logger.log(u"Attempting to back up your sickbeard.db file before migration...") shutil.copy(db.dbFilename(), db.dbFilename(suffix='v0')) logger.log(u"Done backup, proceeding with migration.") break except Exception, e: logger.log(u"Error while trying to back up your sickbeard.db: "+ex(e)) numTries += 1 time.sleep(1) logger.log(u"Trying again.") if numTries >= 10: logger.log(u"Unable to back up your sickbeard.db file, please do it manually.") sys.exit(1)
def execute(self): backupDatabase(0) # old stuff that's been removed from common but we need it to upgrade HD = 1 SD = 3 ANY = 2 BEST = 4 ACTION_SNATCHED = 1 ACTION_PRESNATCHED = 2 ACTION_DOWNLOADED = 3 PREDOWNLOADED = 3 MISSED = 6 BACKLOG = 7 DISCBACKLOG = 8 SNATCHED_BACKLOG = 10 ### Update default quality if sickbeard.QUALITY_DEFAULT == HD: sickbeard.QUALITY_DEFAULT = common.HD elif sickbeard.QUALITY_DEFAULT == SD: sickbeard.QUALITY_DEFAULT = common.SD elif sickbeard.QUALITY_DEFAULT == ANY: sickbeard.QUALITY_DEFAULT = common.ANY elif sickbeard.QUALITY_DEFAULT == BEST: sickbeard.QUALITY_DEFAULT = common.BEST ### Update episode statuses toUpdate = self.connection.select( "SELECT episode_id, location, status FROM tv_episodes WHERE status IN (?, ?, ?, ?, ?, ?, ?)", [ common.DOWNLOADED, common.SNATCHED, PREDOWNLOADED, MISSED, BACKLOG, DISCBACKLOG, SNATCHED_BACKLOG ]) didUpdate = False for curUpdate in toUpdate: # remember that we changed something didUpdate = True newStatus = None oldStatus = int(curUpdate["status"]) if oldStatus == common.SNATCHED: newStatus = common.Quality.compositeStatus( common.SNATCHED, common.Quality.UNKNOWN) elif oldStatus == PREDOWNLOADED: newStatus = common.Quality.compositeStatus( common.DOWNLOADED, common.Quality.SDTV) elif oldStatus in (MISSED, BACKLOG, DISCBACKLOG): newStatus = common.WANTED elif oldStatus == SNATCHED_BACKLOG: newStatus = common.Quality.compositeStatus( common.SNATCHED, common.Quality.UNKNOWN) if newStatus != None: self.connection.action( "UPDATE tv_episodes SET status = ? WHERE episode_id = ? ", [newStatus, curUpdate["episode_id"]]) continue # if we get here status should be == DOWNLOADED if not curUpdate["location"]: continue newQuality = common.Quality.nameQuality(curUpdate["location"]) if newQuality == common.Quality.UNKNOWN: newQuality = common.Quality.assumeQuality( curUpdate["location"]) self.connection.action( "UPDATE tv_episodes SET status = ? WHERE episode_id = ?", [ common.Quality.compositeStatus( common.DOWNLOADED, newQuality), curUpdate["episode_id"] ]) # if no updates were done then the backup is useless if didUpdate: os.remove(db.dbFilename(suffix='v0')) ### Update show qualities toUpdate = self.connection.select("SELECT * FROM tv_shows") for curUpdate in toUpdate: if not curUpdate["quality"]: continue if int(curUpdate["quality"]) == HD: newQuality = common.HD elif int(curUpdate["quality"]) == SD: newQuality = common.SD elif int(curUpdate["quality"]) == ANY: newQuality = common.ANY elif int(curUpdate["quality"]) == BEST: newQuality = common.BEST else: logger.log( u"Unknown show quality: " + str(curUpdate["quality"]), logger.WARNING) newQuality = None if newQuality: self.connection.action( "UPDATE tv_shows SET quality = ? WHERE show_id = ?", [newQuality, curUpdate["show_id"]]) ### Update history toUpdate = self.connection.select("SELECT * FROM history") for curUpdate in toUpdate: newAction = None newStatus = None if int(curUpdate["action"] == ACTION_SNATCHED): newStatus = common.SNATCHED elif int(curUpdate["action"] == ACTION_DOWNLOADED): newStatus = common.DOWNLOADED elif int(curUpdate["action"] == ACTION_PRESNATCHED): newAction = common.Quality.compositeStatus( common.SNATCHED, common.Quality.SDTV) if newAction == None and newStatus == None: continue if not newAction: if int(curUpdate["quality"] == HD): newAction = common.Quality.compositeStatus( newStatus, common.Quality.HDTV) elif int(curUpdate["quality"] == SD): newAction = common.Quality.compositeStatus( newStatus, common.Quality.SDTV) else: newAction = common.Quality.compositeStatus( newStatus, common.Quality.UNKNOWN) self.connection.action( "UPDATE history SET action = ? WHERE date = ? AND showid = ?", [newAction, curUpdate["date"], curUpdate["showid"]]) self.connection.action("CREATE TABLE db_version (db_version INTEGER);") self.connection.action( "INSERT INTO db_version (db_version) VALUES (?)", [1])
def backupDatabase(version): helpers.backupVersionedFile(db.dbFilename(), version)
class NewQualitySettings (NumericProviders): def test(self): return self.hasTable("db_version") def execute(self): numTries = 0 while not ek.ek(os.path.isfile, db.dbFilename(suffix='v0')): if not ek.ek(os.path.isfile, db.dbFilename()): break try: logger.log(u"Attempting to back up your sickbeard.db file before migration...") shutil.copy(db.dbFilename(), db.dbFilename(suffix='v0')) logger.log(u"Done backup, proceeding with migration.") break except Exception, e: logger.log(u"Error while trying to back up your sickbeard.db: "+ex(e)) numTries += 1 time.sleep(1) logger.log(u"Trying again.") if numTries >= 10: logger.log(u"Unable to back up your sickbeard.db file, please do it manually.") sys.exit(1) # old stuff that's been removed from common but we need it to upgrade HD = 1 SD = 3 ANY = 2 BEST = 4 ACTION_SNATCHED = 1 ACTION_PRESNATCHED = 2 ACTION_DOWNLOADED = 3 PREDOWNLOADED = 3 MISSED = 6 BACKLOG = 7 DISCBACKLOG = 8 SNATCHED_BACKLOG = 10 ### Update default quality if sickbeard.QUALITY_DEFAULT == HD: sickbeard.QUALITY_DEFAULT = common.HD elif sickbeard.QUALITY_DEFAULT == SD: sickbeard.QUALITY_DEFAULT = common.SD elif sickbeard.QUALITY_DEFAULT == ANY: sickbeard.QUALITY_DEFAULT = common.ANY elif sickbeard.QUALITY_DEFAULT == BEST: sickbeard.QUALITY_DEFAULT = common.BEST ### Update episode statuses toUpdate = self.connection.select("SELECT episode_id, location, status FROM tv_episodes WHERE status IN (?, ?, ?, ?, ?, ?, ?)", [common.DOWNLOADED, common.SNATCHED, PREDOWNLOADED, MISSED, BACKLOG, DISCBACKLOG, SNATCHED_BACKLOG]) didUpdate = False for curUpdate in toUpdate: # remember that we changed something didUpdate = True newStatus = None oldStatus = int(curUpdate["status"]) if oldStatus == common.SNATCHED: newStatus = common.Quality.compositeStatus(common.SNATCHED, common.Quality.UNKNOWN) elif oldStatus == PREDOWNLOADED: newStatus = common.Quality.compositeStatus(common.DOWNLOADED, common.Quality.SDTV) elif oldStatus in (MISSED, BACKLOG, DISCBACKLOG): newStatus = common.WANTED elif oldStatus == SNATCHED_BACKLOG: newStatus = common.Quality.compositeStatus(common.SNATCHED, common.Quality.UNKNOWN) if newStatus != None: self.connection.action("UPDATE tv_episodes SET status = ? WHERE episode_id = ? ", [newStatus, curUpdate["episode_id"]]) continue # if we get here status should be == DOWNLOADED if not curUpdate["location"]: continue newQuality = common.Quality.nameQuality(curUpdate["location"]) if newQuality == common.Quality.UNKNOWN: newQuality = common.Quality.assumeQuality(curUpdate["location"]) self.connection.action("UPDATE tv_episodes SET status = ? WHERE episode_id = ?", [common.Quality.compositeStatus(common.DOWNLOADED, newQuality), curUpdate["episode_id"]]) # if no updates were done then the backup is useless if didUpdate: os.remove(db.dbFilename(suffix='v0')) ### Update show qualities toUpdate = self.connection.select("SELECT * FROM tv_shows") for curUpdate in toUpdate: if not curUpdate["quality"]: continue if int(curUpdate["quality"]) == HD: newQuality = common.HD elif int(curUpdate["quality"]) == SD: newQuality = common.SD elif int(curUpdate["quality"]) == ANY: newQuality = common.ANY elif int(curUpdate["quality"]) == BEST: newQuality = common.BEST else: logger.log(u"Unknown show quality: "+str(curUpdate["quality"]), logger.WARNING) newQuality = None if newQuality: self.connection.action("UPDATE tv_shows SET quality = ? WHERE show_id = ?", [newQuality, curUpdate["show_id"]]) ### Update history toUpdate = self.connection.select("SELECT * FROM history") for curUpdate in toUpdate: newAction = None newStatus = None if int(curUpdate["action"] == ACTION_SNATCHED): newStatus = common.SNATCHED elif int(curUpdate["action"] == ACTION_DOWNLOADED): newStatus = common.DOWNLOADED elif int(curUpdate["action"] == ACTION_PRESNATCHED): newAction = common.Quality.compositeStatus(common.SNATCHED, common.Quality.SDTV) if newAction == None and newStatus == None: continue if not newAction: if int(curUpdate["quality"] == HD): newAction = common.Quality.compositeStatus(newStatus, common.Quality.HDTV) elif int(curUpdate["quality"] == SD): newAction = common.Quality.compositeStatus(newStatus, common.Quality.SDTV) else: newAction = common.Quality.compositeStatus(newStatus, common.Quality.UNKNOWN) self.connection.action("UPDATE history SET action = ? WHERE date = ? AND showid = ?", [newAction, curUpdate["date"], curUpdate["showid"]]) self.connection.action("CREATE TABLE db_version (db_version INTEGER);") self.connection.action("INSERT INTO db_version (db_version) VALUES (?)", [1])
def execute(self): backupDatabase(0) # old stuff that's been removed from common but we need it to upgrade HD = 1 SD = 3 ANY = 2 BEST = 4 ACTION_SNATCHED = 1 ACTION_PRESNATCHED = 2 ACTION_DOWNLOADED = 3 PREDOWNLOADED = 3 MISSED = 6 BACKLOG = 7 DISCBACKLOG = 8 SNATCHED_BACKLOG = 10 ### Update default quality if sickbeard.QUALITY_DEFAULT == HD: sickbeard.QUALITY_DEFAULT = common.HD elif sickbeard.QUALITY_DEFAULT == SD: sickbeard.QUALITY_DEFAULT = common.SD elif sickbeard.QUALITY_DEFAULT == ANY: sickbeard.QUALITY_DEFAULT = common.ANY elif sickbeard.QUALITY_DEFAULT == BEST: sickbeard.QUALITY_DEFAULT = common.BEST ### Update episode statuses toUpdate = self.connection.select("SELECT episode_id, location, status FROM tv_episodes WHERE status IN (?, ?, ?, ?, ?, ?, ?)", [common.DOWNLOADED, common.SNATCHED, PREDOWNLOADED, MISSED, BACKLOG, DISCBACKLOG, SNATCHED_BACKLOG]) didUpdate = False for curUpdate in toUpdate: # remember that we changed something didUpdate = True newStatus = None oldStatus = int(curUpdate["status"]) if oldStatus == common.SNATCHED: newStatus = common.Quality.compositeStatus(common.SNATCHED, common.Quality.UNKNOWN) elif oldStatus == PREDOWNLOADED: newStatus = common.Quality.compositeStatus(common.DOWNLOADED, common.Quality.SDTV) elif oldStatus in (MISSED, BACKLOG, DISCBACKLOG): newStatus = common.WANTED elif oldStatus == SNATCHED_BACKLOG: newStatus = common.Quality.compositeStatus(common.SNATCHED, common.Quality.UNKNOWN) if newStatus != None: self.connection.action("UPDATE tv_episodes SET status = ? WHERE episode_id = ? ", [newStatus, curUpdate["episode_id"]]) continue # if we get here status should be == DOWNLOADED if not curUpdate["location"]: continue newQuality = common.Quality.nameQuality(curUpdate["location"]) if newQuality == common.Quality.UNKNOWN: newQuality = common.Quality.assumeQuality(curUpdate["location"]) self.connection.action("UPDATE tv_episodes SET status = ? WHERE episode_id = ?", [common.Quality.compositeStatus(common.DOWNLOADED, newQuality), curUpdate["episode_id"]]) # if no updates were done then the backup is useless if didUpdate: os.remove(db.dbFilename(suffix='v0')) ### Update show qualities toUpdate = self.connection.select("SELECT * FROM tv_shows") for curUpdate in toUpdate: if not curUpdate["quality"]: continue if int(curUpdate["quality"]) == HD: newQuality = common.HD elif int(curUpdate["quality"]) == SD: newQuality = common.SD elif int(curUpdate["quality"]) == ANY: newQuality = common.ANY elif int(curUpdate["quality"]) == BEST: newQuality = common.BEST else: logger.log(u"Unknown show quality: " + str(curUpdate["quality"]), logger.WARNING) newQuality = None if newQuality: self.connection.action("UPDATE tv_shows SET quality = ? WHERE show_id = ?", [newQuality, curUpdate["show_id"]]) ### Update history toUpdate = self.connection.select("SELECT * FROM history") for curUpdate in toUpdate: newAction = None newStatus = None if int(curUpdate["action"] == ACTION_SNATCHED): newStatus = common.SNATCHED elif int(curUpdate["action"] == ACTION_DOWNLOADED): newStatus = common.DOWNLOADED elif int(curUpdate["action"] == ACTION_PRESNATCHED): newAction = common.Quality.compositeStatus(common.SNATCHED, common.Quality.SDTV) if newAction == None and newStatus == None: continue if not newAction: if int(curUpdate["quality"] == HD): newAction = common.Quality.compositeStatus(newStatus, common.Quality.HDTV) elif int(curUpdate["quality"] == SD): newAction = common.Quality.compositeStatus(newStatus, common.Quality.SDTV) else: newAction = common.Quality.compositeStatus(newStatus, common.Quality.UNKNOWN) self.connection.action("UPDATE history SET action = ? WHERE date = ? AND showid = ?", [newAction, curUpdate["date"], curUpdate["showid"]]) self.connection.action("CREATE TABLE db_version (db_version INTEGER);") self.connection.action("INSERT INTO db_version (db_version) VALUES (?)", [1])