mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 22:03:13 -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.
|
# run migrate to convert old cfg to new style cfg plus fix any cfg missing values/options.
|
||||||
if not config.migrate():
|
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)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
# run migrate to convert NzbGet data from old cfg style to new cfg style
|
||||||
if os.environ.has_key('NZBOP_SCRIPTDIR'):
|
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
|
# load newly migrated config
|
||||||
logger.info("Loading config from %s", CONFIG_FILE)
|
logger.info("Loading config from %s", CONFIG_FILE)
|
||||||
|
|
|
@ -90,7 +90,7 @@ class ConfigObj(configobj.ConfigObj, Section):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# check for autoProcessMedia.cfg and autoProcessMedia.cfg.spec and if they don't exist return and fail
|
# 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
|
return False
|
||||||
|
|
||||||
subsections = {}
|
subsections = {}
|
||||||
|
@ -186,21 +186,19 @@ class ConfigObj(configobj.ConfigObj, Section):
|
||||||
# create a backup of our old config
|
# create a backup of our old config
|
||||||
CFG_OLD.filename = nzbtomedia.CONFIG_FILE + ".old"
|
CFG_OLD.filename = nzbtomedia.CONFIG_FILE + ".old"
|
||||||
CFG_OLD.write()
|
CFG_OLD.write()
|
||||||
CFG_OLD.clear()
|
|
||||||
|
|
||||||
# write our new config to autoProcessMedia.cfg
|
# write our new config to autoProcessMedia.cfg
|
||||||
CFG_NEW.filename = nzbtomedia.CONFIG_FILE
|
CFG_NEW.filename = nzbtomedia.CONFIG_FILE
|
||||||
CFG_NEW.write()
|
CFG_NEW.write()
|
||||||
CFG_NEW.clear()
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def addnzbget():
|
def addnzbget():
|
||||||
# load configs into memory
|
# load configs into memory
|
||||||
CFG_OLD = config(nzbtomedia.CONFIG_FILE)
|
CFG_NEW = config()
|
||||||
CFG_NEW = CFG_OLD
|
|
||||||
|
|
||||||
|
try:
|
||||||
section = "CouchPotato"
|
section = "CouchPotato"
|
||||||
envCatKey = 'NZBPO_CPSCATEGORY'
|
envCatKey = 'NZBPO_CPSCATEGORY'
|
||||||
envKeys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'DELAY', 'METHOD', 'DELETE_FAILED', 'REMOTECPS', 'WAIT_FOR', 'TIMEPERGIB']
|
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]
|
value = os.environ[key]
|
||||||
CFG_NEW[section][option] = value
|
CFG_NEW[section][option] = value
|
||||||
|
|
||||||
# create a backup of our old config
|
except:
|
||||||
CFG_OLD.filename = nzbtomedia.CONFIG_FILE + ".old"
|
return False
|
||||||
CFG_OLD.write()
|
|
||||||
CFG_OLD.clear()
|
|
||||||
|
|
||||||
# write our new config to autoProcessMedia.cfg
|
# write our new config to autoProcessMedia.cfg
|
||||||
CFG_NEW.filename = nzbtomedia.CONFIG_FILE
|
CFG_NEW.filename = nzbtomedia.CONFIG_FILE
|
||||||
CFG_NEW.write()
|
CFG_NEW.write()
|
||||||
CFG_NEW.clear()
|
|
||||||
|
return True
|
||||||
|
|
||||||
configobj.Section = Section
|
configobj.Section = Section
|
||||||
configobj.ConfigObj = ConfigObj
|
configobj.ConfigObj = ConfigObj
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue