mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 13:53:15 -07:00
Added error checking for migration NzbGet code.
Fixed migration code on how it writes backups and new config files.
This commit is contained in:
parent
7904330613
commit
9157309131
2 changed files with 117 additions and 117 deletions
|
@ -159,11 +159,14 @@ def initialize():
|
|||
|
||||
# run migrate to convert old cfg to new style cfg plus fix any cfg missing values/options.
|
||||
if not config.migrate():
|
||||
logger.error("Unable to load config from %s", CONFIG_FILE)
|
||||
logger.error("Unable to migrate config file %s, exiting ...", CONFIG_FILE)
|
||||
sys.exit(-1)
|
||||
|
||||
# run migrate to convert NzbGet data from old cfg style to new cfg style
|
||||
if os.environ.has_key('NZBOP_SCRIPTDIR'):
|
||||
config.addnzbget()
|
||||
if not config.addnzbget():
|
||||
logger.error("Unable to migrate NzbGet config file %s, exiting ...", CONFIG_FILE)
|
||||
sys.exit(-1)
|
||||
|
||||
# load newly migrated config
|
||||
logger.info("Loading config from %s", CONFIG_FILE)
|
||||
|
|
|
@ -90,7 +90,7 @@ class ConfigObj(configobj.ConfigObj, Section):
|
|||
pass
|
||||
|
||||
# check for autoProcessMedia.cfg and autoProcessMedia.cfg.spec and if they don't exist return and fail
|
||||
if not CFG_NEW or not CFG_OLD:
|
||||
if CFG_NEW is None or CFG_OLD is None:
|
||||
return False
|
||||
|
||||
subsections = {}
|
||||
|
@ -186,21 +186,19 @@ class ConfigObj(configobj.ConfigObj, Section):
|
|||
# create a backup of our old config
|
||||
CFG_OLD.filename = nzbtomedia.CONFIG_FILE + ".old"
|
||||
CFG_OLD.write()
|
||||
CFG_OLD.clear()
|
||||
|
||||
# write our new config to autoProcessMedia.cfg
|
||||
CFG_NEW.filename = nzbtomedia.CONFIG_FILE
|
||||
CFG_NEW.write()
|
||||
CFG_NEW.clear()
|
||||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def addnzbget():
|
||||
# load configs into memory
|
||||
CFG_OLD = config(nzbtomedia.CONFIG_FILE)
|
||||
CFG_NEW = CFG_OLD
|
||||
CFG_NEW = config()
|
||||
|
||||
try:
|
||||
section = "CouchPotato"
|
||||
envCatKey = 'NZBPO_CPSCATEGORY'
|
||||
envKeys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'DELAY', 'METHOD', 'DELETE_FAILED', 'REMOTECPS', 'WAIT_FOR', 'TIMEPERGIB']
|
||||
|
@ -321,15 +319,14 @@ class ConfigObj(configobj.ConfigObj, Section):
|
|||
value = os.environ[key]
|
||||
CFG_NEW[section][option] = value
|
||||
|
||||
# create a backup of our old config
|
||||
CFG_OLD.filename = nzbtomedia.CONFIG_FILE + ".old"
|
||||
CFG_OLD.write()
|
||||
CFG_OLD.clear()
|
||||
except:
|
||||
return False
|
||||
|
||||
# write our new config to autoProcessMedia.cfg
|
||||
CFG_NEW.filename = nzbtomedia.CONFIG_FILE
|
||||
CFG_NEW.write()
|
||||
CFG_NEW.clear()
|
||||
|
||||
return True
|
||||
|
||||
configobj.Section = Section
|
||||
configobj.ConfigObj = ConfigObj
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue