Massive changes to the way we handle our config, its now loaded and stored in memory so that we don't keep loading it and possibly get corrupt values.

New logger class added,logger options removed from settings.
This commit is contained in:
echel0n 2014-04-11 20:09:00 -07:00
commit 18926d1db8
30 changed files with 1603 additions and 1058 deletions

View file

@ -1,47 +1,42 @@
import logging
import urllib
import socket
import time
import nzbtomedia
from lib import requests
from nzbtomedia.nzbToMediaConfig import config
from nzbtomedia.nzbToMediaUtil import convert_to_ascii
Logger = logging.getLogger()
from nzbtomedia import logger
class autoProcessComics:
def processEpisode(self, dirName, nzbName=None, status=0, clientAgent='manual', inputCategory=None):
if dirName is None:
Logger.error("No directory was given!")
logger.error("No directory was given!")
return 1 # failure
# auto-detect correct section
section = config().findsection(inputCategory)
section = nzbtomedia.CFG.findsection(inputCategory)
if not section:
Logger.error(
"MAIN: We were unable to find a section for category %s, please check your autoProcessMedia.cfg file.", inputCategory)
logger.error(
"We were unable to find a section for category %s, please check your autoProcessMedia.cfg file.", inputCategory)
return 1
socket.setdefaulttimeout(int(config.NZBTOMEDIA_TIMEOUT)) #initialize socket timeout.
logger.postprocess("Loading config from %s", nzbtomedia.CONFIG_FILE)
Logger.info("Loading config from %s", config.CONFIG_FILE)
host = config()[section][inputCategory]["host"]
port = config()[section][inputCategory]["port"]
username = config()[section][inputCategory]["username"]
password = config()[section][inputCategory]["password"]
host = nzbtomedia.CFG[section][inputCategory]["host"]
port = nzbtomedia.CFG[section][inputCategory]["port"]
username = nzbtomedia.CFG[section][inputCategory]["username"]
password = nzbtomedia.CFG[section][inputCategory]["password"]
try:
ssl = int(config()[section][inputCategory]["ssl"])
ssl = int(nzbtomedia.CFG[section][inputCategory]["ssl"])
except:
ssl = 0
try:
web_root = config()[section][inputCategory]["web_root"]
web_root = nzbtomedia.CFG[section][inputCategory]["web_root"]
except:
web_root = ""
try:
watch_dir = config()[section][inputCategory]["watch_dir"]
watch_dir = nzbtomedia.CFG[section][inputCategory]["watch_dir"]
except:
watch_dir = ""
params = {}
@ -62,16 +57,16 @@ class autoProcessComics:
url = protocol + host + ":" + port + web_root + "/post_process?" + urllib.urlencode(params)
Logger.debug("Opening URL: %s", url)
logger.debug("Opening URL: %s", url)
try:
r = requests.get(url, auth=(username, password), stream=True)
except requests.ConnectionError:
Logger.exception("Unable to open URL")
logger.error("Unable to open URL")
return 1 # failure
for line in r.iter_lines():
if line: Logger.info("%s", line)
if line: logger.postprocess("%s", line)
time.sleep(60) #wait 1 minute for now... need to see just what gets logged and how long it takes to process
return 0 # Success