mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-19 21:03:14 -07:00
Added in a config class to access main config properly and now can be called from anywhere in the code by creating a instance.
Re-coded migratecfg, vast improvements made and code cleanup of unrequired checks. Fixed numerous small bugs throughout nzbToMedia including possible calls to variables that may not have been created do to conditional statements.
This commit is contained in:
parent
08bd4584d8
commit
6d45257035
29 changed files with 348 additions and 543 deletions
|
@ -1,298 +1,129 @@
|
|||
#System imports
|
||||
import ConfigParser
|
||||
import sys
|
||||
import os
|
||||
from nzbToMediaConfig import *
|
||||
|
||||
def migrate():
|
||||
confignew = ConfigParser.ConfigParser()
|
||||
confignew.optionxform = str
|
||||
configFilenamenew = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg.sample")
|
||||
confignew.read(configFilenamenew)
|
||||
|
||||
configold = ConfigParser.ConfigParser()
|
||||
configold.optionxform = str
|
||||
|
||||
categories = []
|
||||
confignew = config(SAMPLE_CONFIG_FILE)
|
||||
configold = config(CONFIG_FILE)
|
||||
|
||||
section = "CouchPotato"
|
||||
original = []
|
||||
configFilenameold = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
|
||||
if not os.path.isfile(configFilenameold): # lets look back for an older version.
|
||||
configFilenameold = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMovie.cfg")
|
||||
if not os.path.isfile(configFilenameold): # no config available
|
||||
configFilenameold = ""
|
||||
if configFilenameold: # read our old config.
|
||||
configold.read(configFilenameold)
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
if option == "category": # change this old format
|
||||
for option, value in configold.items(section) or config(MOVIE_CONFIG_FILE).items(section):
|
||||
if option is "category": # change this old format
|
||||
option = "cpsCategory"
|
||||
if option == "outputDirectory": # move this to new location format
|
||||
if option is "outputDirectory": # move this to new location format
|
||||
value = os.path.split(os.path.normpath(value))[0]
|
||||
confignew.set("Torrent", option, value)
|
||||
continue
|
||||
if option in ["username", "password" ]: # these are no-longer needed.
|
||||
continue
|
||||
if option == "cpsCategory":
|
||||
if option is "cpsCategory":
|
||||
categories.extend(value.split(','))
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "SickBeard"
|
||||
original = []
|
||||
configFilenameold = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
|
||||
if not os.path.isfile(configFilenameold): # lets look back for an older version.
|
||||
configFilenameold = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessTV.cfg")
|
||||
if not os.path.isfile(configFilenameold): # no config available
|
||||
configFilenameold = ""
|
||||
if configFilenameold: # read our old config.
|
||||
configold.read(configFilenameold)
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
if option == "category": # change this old format
|
||||
for option, value in configold.items(section) or config(TV_CONFIG_FILE).items(section):
|
||||
if option is "category": # change this old format
|
||||
option = "sbCategory"
|
||||
if option == "failed_fork": # change this old format
|
||||
if option is "failed_fork": # change this old format
|
||||
option = "fork"
|
||||
if value not in ["default", "failed", "failed-torrent", "auto"]:
|
||||
value = "auto"
|
||||
if option == "fork" and value not in ["default", "failed", "failed-torrent", "auto"]:
|
||||
if option is "fork" and value not in ["default", "failed", "failed-torrent", "auto"]:
|
||||
value = "auto"
|
||||
if option == "outputDirectory": # move this to new location format
|
||||
if option is "outputDirectory": # move this to new location format
|
||||
value = os.path.split(os.path.normpath(value))[0]
|
||||
confignew.set("Torrent", option, value)
|
||||
continue
|
||||
if option == "sbCategory":
|
||||
if option is "sbCategory":
|
||||
categories.extend(value.split(','))
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "HeadPhones"
|
||||
original = []
|
||||
configFilenameold = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
|
||||
if os.path.isfile(configFilenameold): # read our old config.
|
||||
configold.read(configFilenameold)
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
if option in ["username", "password" ]: # these are no-longer needed.
|
||||
continue
|
||||
option, value = item
|
||||
if option == "hpCategory":
|
||||
categories.extend(value.split(','))
|
||||
confignew.set(section, option, value)
|
||||
for section in configold.sections():
|
||||
if section is "HeadPhones":
|
||||
if option in ["username", "password" ]:
|
||||
continue
|
||||
if option is "hpCategory":
|
||||
categories.extend(value.split(','))
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "Mylar"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
if option == "mlCategory":
|
||||
categories.extend(value.split(','))
|
||||
confignew.set(section, option, value)
|
||||
if section is "Mylar":
|
||||
if option in "mlCategory":
|
||||
categories.extend(value.split(','))
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "Gamez"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
if option in ["username", "password" ]: # these are no-longer needed.
|
||||
continue
|
||||
if option == "gzCategory":
|
||||
categories.extend(value.split(','))
|
||||
confignew.set(section, option, value)
|
||||
if section is "Gamez":
|
||||
if option in ["username", "password" ]: # these are no-longer needed.
|
||||
continue
|
||||
if option == "gzCategory":
|
||||
categories.extend(value.split(','))
|
||||
confignew.set(section, option, value)
|
||||
|
||||
for section in categories:
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
continue
|
||||
try:
|
||||
confignew.add_section(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "Torrent"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
if option in ["compressedExtensions", "mediaExtensions", "metaExtensions", "minSampleSize"]:
|
||||
section = "Extensions" # these were moved
|
||||
if option == "useLink": # Sym links supported now as well.
|
||||
try:
|
||||
num_value = int(value)
|
||||
if num_value == 1:
|
||||
if section is "Torrent":
|
||||
if option in ["compressedExtensions", "mediaExtensions", "metaExtensions", "minSampleSize"]:
|
||||
section = "Extensions" # these were moved
|
||||
if option is "useLink": # Sym links supported now as well.
|
||||
num_value = int(value or 0)
|
||||
if num_value is 1:
|
||||
value = "hard"
|
||||
else:
|
||||
value = "no"
|
||||
except ValueError:
|
||||
pass
|
||||
confignew.set(section, option, value)
|
||||
section = "Torrent" # reset in case extensions out of order.
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "Extensions"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
confignew.set(section, option, value)
|
||||
if section is "Extensions":
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "Transcoder"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
confignew.set(section, option, value)
|
||||
if section is "Transcoder":
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "WakeOnLan"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
confignew.set(section, option, value)
|
||||
if section is "WakeOnLan":
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "UserScript"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
confignew.set(section, option, value)
|
||||
if section is "UserScript":
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "ASCII"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
confignew.set(section, option, value)
|
||||
if section is "ASCII":
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "passwords"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
confignew.set(section, option, value)
|
||||
if section is "passwords":
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "loggers"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
confignew.set(section, option, value)
|
||||
if section is "loggers":
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "handlers"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
confignew.set(section, option, value)
|
||||
if section is "handlers":
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "formatters"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
confignew.set(section, option, value)
|
||||
if section is "formatters":
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "logger_root"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
confignew.set(section, option, value)
|
||||
if section is "logger_root":
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "handler_console"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
confignew.set(section, option, value)
|
||||
if section is "handler_console":
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "formatter_generic"
|
||||
original = []
|
||||
try:
|
||||
original = configold.items(section)
|
||||
except:
|
||||
pass
|
||||
for item in original:
|
||||
option, value = item
|
||||
confignew.set(section, option, value)
|
||||
if section is "formatter_generic":
|
||||
confignew.set(section, option, value)
|
||||
|
||||
# writing our configuration file to 'autoProcessMedia.cfg.sample'
|
||||
with open(configFilenamenew, 'wb') as configFile:
|
||||
confignew.write(configFile)
|
||||
for section in categories:
|
||||
if configold.items(section):
|
||||
confignew.add_section(section)
|
||||
|
||||
for option, value in configold.items(section):
|
||||
confignew.set(section, option, value)
|
||||
|
||||
# create a backup of our old config
|
||||
if os.path.isfile(configFilenameold):
|
||||
backupname = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg.old")
|
||||
if os.path.isfile(backupname): # remove older backups
|
||||
os.unlink(backupname)
|
||||
os.rename(configFilenameold, backupname)
|
||||
if os.path.isfile(CONFIG_FILE):
|
||||
cfgbak_name = CONFIG_FILE + ".old"
|
||||
if os.path.isfile(cfgbak_name): # remove older backups
|
||||
os.unlink(cfgbak_name)
|
||||
os.rename(CONFIG_FILE, cfgbak_name)
|
||||
|
||||
if os.path.isfile(configFilenamenew):
|
||||
# rename our newly edited autoProcessMedia.cfg.sample to autoProcessMedia.cfg
|
||||
os.rename(configFilenamenew, configFilenameold)
|
||||
return
|
||||
# writing our configuration file to 'autoProcessMedia.cfg.sample'
|
||||
with open(CONFIG_FILE, 'wb') as configFile:
|
||||
confignew.write(configFile)
|
||||
|
||||
def addnzbget():
|
||||
confignew = ConfigParser.ConfigParser()
|
||||
confignew.optionxform = str
|
||||
configFilenamenew = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
|
||||
confignew.read(configFilenamenew)
|
||||
|
||||
confignew = config()
|
||||
section = "CouchPotato"
|
||||
envKeys = ['CATEGORY', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'DELAY', 'METHOD', 'DELETE_FAILED', 'REMOTECPS', 'WAIT_FOR']
|
||||
cfgKeys = ['cpsCategory', 'apikey', 'host', 'port', 'ssl', 'web_root', 'delay', 'method', 'delete_failed', 'remoteCPS', 'wait_for']
|
||||
|
@ -322,7 +153,7 @@ def addnzbget():
|
|||
if os.environ.has_key(key):
|
||||
option = cfgKeys[index]
|
||||
value = os.environ[key]
|
||||
confignew.set(section, option, value)
|
||||
confignew.set(section, option, value)
|
||||
|
||||
section = "Mylar"
|
||||
envKeys = ['CATEGORY', 'HOST', 'PORT', 'USERNAME', 'PASSWORD', 'SSL', 'WEB_ROOT']
|
||||
|
@ -374,9 +205,6 @@ def addnzbget():
|
|||
value = os.environ[key]
|
||||
confignew.set(section, option, value)
|
||||
|
||||
|
||||
# writing our configuration file to 'autoProcessMedia.cfg'
|
||||
with open(configFilenamenew, 'wb') as configFile:
|
||||
confignew.write(configFile)
|
||||
|
||||
return
|
||||
with open(CONFIG_FILE, 'wb') as configFile:
|
||||
confignew.write(configFile)
|
Loading…
Add table
Add a link
Reference in a new issue