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:
echel0n 2014-04-01 18:35:20 -07:00
parent 08bd4584d8
commit 6d45257035
29 changed files with 348 additions and 543 deletions

View file

@ -1,50 +1,44 @@
import sys
import urllib
import os
import shutil
import ConfigParser
import datetime
import time
import json
import logging
import socket
from nzbToMediaEnv import *
from nzbToMediaUtil import *
Logger = logging.getLogger()
socket.setdefaulttimeout(int(TimeOut)) #initialize socket timeout.
def process(dirName, nzbName=None, status=0, inputCategory=None):
status = int(status)
config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg")
Logger.info("Loading config from %s", configFilename)
if not os.path.isfile(configFilename):
Logger.info("Loading config from %s", CONFIG_FILE)
if not config():
Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
return 1 # failure
config.read(configFilename)
section = "HeadPhones"
if inputCategory != None and config.has_section(inputCategory):
if inputCategory != None and config().has_section(inputCategory):
section = inputCategory
host = config.get(section, "host")
port = config.get(section, "port")
apikey = config.get(section, "apikey")
delay = float(config.get(section, "delay"))
host = config().get(section, "host")
port = config().get(section, "port")
apikey = config().get(section, "apikey")
delay = float(config().get(section, "delay"))
try:
ssl = int(config.get(section, "ssl"))
except (ConfigParser.NoOptionError, ValueError):
ssl = int(config().get(section, "ssl"))
except (config.NoOptionError, ValueError):
ssl = 0
try:
web_root = config.get(section, "web_root")
except ConfigParser.NoOptionError:
web_root = config().get(section, "web_root")
except config.NoOptionError:
web_root = ""
if ssl: