From 6d45257035c297cd02015db45aa57cee07ffa6a9 Mon Sep 17 00:00:00 2001 From: echel0n Date: Tue, 1 Apr 2014 18:35:20 -0700 Subject: [PATCH] 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. --- ResetDateTime.py | 2 +- TorrentToMedia.py | 92 ++++----- autoProcess/Transcoder.py | 43 ++-- autoProcess/autoProcessComics.py | 39 ++-- autoProcess/autoProcessGames.py | 34 ++-- autoProcess/autoProcessMovie.py | 52 +++-- autoProcess/autoProcessMusic.py | 36 ++-- autoProcess/autoProcessTV.py | 68 +++---- autoProcess/autoSickBeardFork.py | 26 ++- autoProcess/migratecfg.py | 330 ++++++++----------------------- autoProcess/nzbToMediaUtil.py | 38 ++-- extractor/extractor.py | 15 +- nzbToCouchPotato.py | 2 - nzbToGamez.py | 2 - nzbToHeadPhones.py | 2 - nzbToMedia.py | 37 ++-- nzbToMediaConfig.py | 35 ++++ nzbToMylar.py | 2 - nzbToSickBeard.py | 2 - synchronousdeluge/client.py | 2 +- synchronousdeluge/rencode.py | 1 - tests/test_autofork.py | 3 + transmissionrpc/client.py | 8 +- transmissionrpc/constants.py | 2 + transmissionrpc/httphandler.py | 1 - transmissionrpc/six.py | 2 +- transmissionrpc/torrent.py | 4 +- transmissionrpc/utils.py | 7 +- utorrent/upload.py | 4 +- 29 files changed, 348 insertions(+), 543 deletions(-) create mode 100644 nzbToMediaConfig.py create mode 100644 tests/test_autofork.py diff --git a/ResetDateTime.py b/ResetDateTime.py index c52eb165..24ec2e1e 100755 --- a/ResetDateTime.py +++ b/ResetDateTime.py @@ -81,7 +81,7 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 os.utime(filepath, None) continue except: - print "Error: unable to reset time for file", filePath + print "Error: unable to reset time for file", file sys.exit(POSTPROCESS_ERROR) sys.exit(POSTPROCESS_SUCCESS) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 692fdeab..6d969fe1 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -1,15 +1,9 @@ #!/usr/bin/env python #System imports -import os -import sys -import ConfigParser -import shutil import logging import datetime -import time -import re -from subprocess import call, Popen +from subprocess import Popen # Custom imports import autoProcess.migratecfg as migratecfg @@ -450,69 +444,65 @@ if __name__ == "__main__": WakeUp() - config = ConfigParser.ConfigParser() - configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg") - - if not os.path.isfile(configFilename): + if not config(): Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?") sys.exit(-1) # CONFIG FILE - Logger.info("MAIN: Loading config from %s", configFilename) - config.read(configFilename) + Logger.info("MAIN: Loading config from %s", CONFIG_FILE) # EXAMPLE VALUES: - clientAgent = config.get("Torrent", "clientAgent") # utorrent | deluge | transmission | rtorrent | other - useLink_in = config.get("Torrent", "useLink") # no | hard | sym - outputDirectory = config.get("Torrent", "outputDirectory") # /abs/path/to/complete/ - categories = (config.get("Torrent", "categories")).split(',') # music,music_videos,pictures,software - noFlatten = (config.get("Torrent", "noFlatten")).split(',') + clientAgent = config().get("Torrent", "clientAgent") # utorrent | deluge | transmission | rtorrent | other + useLink_in = config().get("Torrent", "useLink") # no | hard | sym + outputDirectory = config().get("Torrent", "outputDirectory") # /abs/path/to/complete/ + categories = (config().get("Torrent", "categories")).split(',') # music,music_videos,pictures,software + noFlatten = (config().get("Torrent", "noFlatten")).split(',') - uTorrentWEBui = config.get("Torrent", "uTorrentWEBui") # http://localhost:8090/gui/ - uTorrentUSR = config.get("Torrent", "uTorrentUSR") # mysecretusr - uTorrentPWD = config.get("Torrent", "uTorrentPWD") # mysecretpwr + uTorrentWEBui = config().get("Torrent", "uTorrentWEBui") # http://localhost:8090/gui/ + uTorrentUSR = config().get("Torrent", "uTorrentUSR") # mysecretusr + uTorrentPWD = config().get("Torrent", "uTorrentPWD") # mysecretpwr - TransmissionHost = config.get("Torrent", "TransmissionHost") # localhost - TransmissionPort = config.get("Torrent", "TransmissionPort") # 8084 - TransmissionUSR = config.get("Torrent", "TransmissionUSR") # mysecretusr - TransmissionPWD = config.get("Torrent", "TransmissionPWD") # mysecretpwr + TransmissionHost = config().get("Torrent", "TransmissionHost") # localhost + TransmissionPort = config().get("Torrent", "TransmissionPort") # 8084 + TransmissionUSR = config().get("Torrent", "TransmissionUSR") # mysecretusr + TransmissionPWD = config().get("Torrent", "TransmissionPWD") # mysecretpwr - DelugeHost = config.get("Torrent", "DelugeHost") # localhost - DelugePort = config.get("Torrent", "DelugePort") # 8084 - DelugeUSR = config.get("Torrent", "DelugeUSR") # mysecretusr - DelugePWD = config.get("Torrent", "DelugePWD") # mysecretpwr + DelugeHost = config().get("Torrent", "DelugeHost") # localhost + DelugePort = config().get("Torrent", "DelugePort") # 8084 + DelugeUSR = config().get("Torrent", "DelugeUSR") # mysecretusr + DelugePWD = config().get("Torrent", "DelugePWD") # mysecretpwr - deleteOriginal = int(config.get("Torrent", "deleteOriginal")) # 0 - forceClean = int(config.get("Torrent", "forceClean")) # 0 + deleteOriginal = int(config().get("Torrent", "deleteOriginal")) # 0 + forceClean = int(config().get("Torrent", "forceClean")) # 0 - compressedContainer = (config.get("Extensions", "compressedExtensions")).split(',') # .zip,.rar,.7z - mediaContainer = (config.get("Extensions", "mediaExtensions")).split(',') # .mkv,.avi,.divx - metaContainer = (config.get("Extensions", "metaExtensions")).split(',') # .nfo,.sub,.srt - minSampleSize = int(config.get("Extensions", "minSampleSize")) # 200 (in MB) - SampleIDs = (config.get("Extensions", "SampleIDs")).split(',') # sample,-s. + compressedContainer = (config().get("Extensions", "compressedExtensions")).split(',') # .zip,.rar,.7z + mediaContainer = (config().get("Extensions", "mediaExtensions")).split(',') # .mkv,.avi,.divx + metaContainer = (config().get("Extensions", "metaExtensions")).split(',') # .nfo,.sub,.srt + minSampleSize = int(config().get("Extensions", "minSampleSize")) # 200 (in MB) + SampleIDs = (config().get("Extensions", "SampleIDs")).split(',') # sample,-s. - cpsCategory = (config.get("CouchPotato", "cpsCategory")).split(',') # movie - sbCategory = (config.get("SickBeard", "sbCategory")).split(',') # tv - Torrent_ForceLink = int(config.get("SickBeard", "Torrent_ForceLink")) # 1 - hpCategory = (config.get("HeadPhones", "hpCategory")).split(',') # music - mlCategory = (config.get("Mylar", "mlCategory")).split(',') # comics - gzCategory = (config.get("Gamez", "gzCategory")).split(',') # games + cpsCategory = (config().get("CouchPotato", "cpsCategory")).split(',') # movie + sbCategory = (config().get("SickBeard", "sbCategory")).split(',') # tv + Torrent_ForceLink = int(config().get("SickBeard", "Torrent_ForceLink")) # 1 + hpCategory = (config().get("HeadPhones", "hpCategory")).split(',') # music + mlCategory = (config().get("Mylar", "mlCategory")).split(',') # comics + gzCategory = (config().get("Gamez", "gzCategory")).split(',') # games categories.extend(cpsCategory) categories.extend(sbCategory) categories.extend(hpCategory) categories.extend(mlCategory) categories.extend(gzCategory) - user_script_categories = config.get("UserScript", "user_script_categories").split(',') # NONE + user_script_categories = config().get("UserScript", "user_script_categories").split(',') # NONE if not "NONE" in user_script_categories: - user_script_mediaExtensions = (config.get("UserScript", "user_script_mediaExtensions")).split(',') - user_script = config.get("UserScript", "user_script_path") - user_script_param = (config.get("UserScript", "user_script_param")).split(',') - user_script_successCodes = (config.get("UserScript", "user_script_successCodes")).split(',') - user_script_clean = int(config.get("UserScript", "user_script_clean")) - user_delay = int(config.get("UserScript", "delay")) - user_script_runOnce = int(config.get("UserScript", "user_script_runOnce")) + user_script_mediaExtensions = (config().get("UserScript", "user_script_mediaExtensions")).split(',') + user_script = config().get("UserScript", "user_script_path") + user_script_param = (config().get("UserScript", "user_script_param")).split(',') + user_script_successCodes = (config().get("UserScript", "user_script_successCodes")).split(',') + user_script_clean = int(config().get("UserScript", "user_script_clean")) + user_delay = int(config().get("UserScript", "delay")) + user_script_runOnce = int(config().get("UserScript", "user_script_runOnce")) - transcode = int(config.get("Transcoder", "transcode")) + transcode = int(config().get("Transcoder", "transcode")) n = 0 for arg in sys.argv: diff --git a/autoProcess/Transcoder.py b/autoProcess/Transcoder.py index 25cc981a..db34c8c3 100644 --- a/autoProcess/Transcoder.py +++ b/autoProcess/Transcoder.py @@ -1,10 +1,11 @@ import sys -import os -import ConfigParser import logging import errno from subprocess import call +from nzbToMediaConfig import * + + Logger = logging.getLogger() def Transcode_directory(dirName): @@ -28,32 +29,28 @@ def Transcode_directory(dirName): else: ffmpeg = 'ffmpeg' useNiceness = True - - 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) - mediaContainer = (config.get("Extensions", "mediaExtensions")).split(',') - duplicate = int(config.get("Transcoder", "duplicate")) - ignoreExtensions = (config.get("Transcoder", "ignoreExtensions")).split(',') - outputVideoExtension = config.get("Transcoder", "outputVideoExtension").strip() - outputVideoCodec = config.get("Transcoder", "outputVideoCodec").strip() - outputVideoPreset = config.get("Transcoder", "outputVideoPreset").strip() - outputVideoFramerate = config.get("Transcoder", "outputVideoFramerate").strip() - outputVideoBitrate = config.get("Transcoder", "outputVideoBitrate").strip() - outputAudioCodec = config.get("Transcoder", "outputAudioCodec").strip() - outputAudioBitrate = config.get("Transcoder", "outputAudioBitrate").strip() - outputSubtitleCodec = config.get("Transcoder", "outputSubtitleCodec").strip() - outputFastStart = int(config.get("Transcoder", "outputFastStart")) - outputQualityPercent = int(config.get("Transcoder", "outputQualityPercent")) + mediaContainer = (config().get("Extensions", "mediaExtensions")).split(',') + duplicate = int(config().get("Transcoder", "duplicate")) + ignoreExtensions = (config().get("Transcoder", "ignoreExtensions")).split(',') + outputVideoExtension = config().get("Transcoder", "outputVideoExtension").strip() + outputVideoCodec = config().get("Transcoder", "outputVideoCodec").strip() + outputVideoPreset = config().get("Transcoder", "outputVideoPreset").strip() + outputVideoFramerate = config().get("Transcoder", "outputVideoFramerate").strip() + outputVideoBitrate = config().get("Transcoder", "outputVideoBitrate").strip() + outputAudioCodec = config().get("Transcoder", "outputAudioCodec").strip() + outputAudioBitrate = config().get("Transcoder", "outputAudioBitrate").strip() + outputSubtitleCodec = config().get("Transcoder", "outputSubtitleCodec").strip() + outputFastStart = int(config().get("Transcoder", "outputFastStart")) + outputQualityPercent = int(config().get("Transcoder", "outputQualityPercent")) if useNiceness: - niceness = int(config.get("Transcoder", "niceness")) + niceness = int(config().get("Transcoder", "niceness")) map(lambda ext: ext.strip(), mediaContainer) map(lambda ext: ext.strip(), ignoreExtensions) diff --git a/autoProcess/autoProcessComics.py b/autoProcess/autoProcessComics.py index 72c06efb..4c6d744e 100644 --- a/autoProcess/autoProcessComics.py +++ b/autoProcess/autoProcessComics.py @@ -1,14 +1,9 @@ -import sys import urllib -import os.path -import time -import ConfigParser import logging -import socket from nzbToMediaEnv import * from nzbToMediaUtil import * -from nzbToMediaSceneExceptions import process_all_exceptions + Logger = logging.getLogger() socket.setdefaulttimeout(int(TimeOut)) #initialize socket timeout. @@ -34,36 +29,36 @@ class AuthURLOpener(urllib.FancyURLopener): def processEpisode(dirName, nzbName=None, status=0, inputCategory=None): - config = ConfigParser.ConfigParser() - configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg") - Logger.info("Loading config from %s", configFilename) + + + Logger.info("Loading config from %s", CONFIG_FILE) - if not os.path.isfile(configFilename): + 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 = "Mylar" - 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") - username = config.get(section, "username") - password = config.get(section, "password") + host = config().get(section, "host") + port = config().get(section, "port") + username = config().get(section, "username") + password = config().get(section, "password") 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 = "" try: - watch_dir = config.get(section, "watch_dir") - except ConfigParser.NoOptionError: + watch_dir = config().get(section, "watch_dir") + except config.NoOptionError: watch_dir = "" params = {} diff --git a/autoProcess/autoProcessGames.py b/autoProcess/autoProcessGames.py index 9fd6a082..ccc989ad 100644 --- a/autoProcess/autoProcessGames.py +++ b/autoProcess/autoProcessGames.py @@ -1,49 +1,43 @@ -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 = "Gamez" - 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") + host = config().get(section, "host") + port = config().get(section, "port") + apikey = config().get(section, "apikey") 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: diff --git a/autoProcess/autoProcessMovie.py b/autoProcess/autoProcessMovie.py index db11e7a8..3e9665b9 100644 --- a/autoProcess/autoProcessMovie.py +++ b/autoProcess/autoProcessMovie.py @@ -1,19 +1,14 @@ -import sys import urllib -import os -import shutil -import ConfigParser import datetime -import time import json import logging -import socket import Transcoder from nzbToMediaEnv import * from nzbToMediaUtil import * from nzbToMediaSceneExceptions import process_all_exceptions + Logger = logging.getLogger() socket.setdefaulttimeout(int(TimeOut)) #initialize socket timeout. @@ -130,7 +125,7 @@ def get_movie_info(baseURL, imdbid, download_id): return movie_id, imdbid, download_id, movie_status, release_status def get_status(baseURL, movie_id, download_id): - + result = None movie_status = None release_status = None if not movie_id: @@ -151,6 +146,7 @@ def get_status(baseURL, movie_id, download_id): Logger.debug("This movie is marked as status %s in CouchPotatoServer", movie_status) except: Logger.exception("Could not find a status for this movie") + try: if len(result["media"]["releases"]) == 1 and result["media"]["releases"][0]["status"] == "done": release_status = result["media"]["releases"][0]["status"] @@ -167,46 +163,43 @@ def get_status(baseURL, movie_id, download_id): def process(dirName, nzbName=None, status=0, clientAgent = "manual", download_id = "", 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 = "CouchPotato" - 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")) - method = config.get(section, "method") - delete_failed = int(config.get(section, "delete_failed")) - wait_for = int(config.get(section, "wait_for")) + host = config().get(section, "host") + port = config().get(section, "port") + apikey = config().get(section, "apikey") + delay = float(config().get(section, "delay")) + method = config().get(section, "method") + delete_failed = int(config().get(section, "delete_failed")) + wait_for = int(config().get(section, "wait_for")) 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 = "" try: - transcode = int(config.get("Transcoder", "transcode")) - except (ConfigParser.NoOptionError, ValueError): + transcode = int(config().get("Transcoder", "transcode")) + except (config.NoOptionError, ValueError): transcode = 0 try: - remoteCPS = int(config.get(section, "remoteCPS")) - except (ConfigParser.NoOptionError, ValueError): + remoteCPS = int(config().get(section, "remoteCPS")) + except (config.NoOptionError, ValueError): remoteCPS = 0 nzbName = str(nzbName) # make sure it is a string @@ -312,6 +305,7 @@ def process(dirName, nzbName=None, status=0, clientAgent = "manual", download_id # we will now check to see if CPS has finished renaming before returning to TorrentToMedia and unpausing. socket.setdefaulttimeout(int(TimeOut)) #initialize socket timeout. + release_status = None start = datetime.datetime.now() # set time for timeout pause_for = int(wait_for) * 10 # keep this so we only ever have 6 complete loops. This may not be necessary now? while (datetime.datetime.now() - start) < datetime.timedelta(minutes=wait_for): # only wait 2 (default) minutes, then return. diff --git a/autoProcess/autoProcessMusic.py b/autoProcess/autoProcessMusic.py index ce5d2e84..95de8792 100644 --- a/autoProcess/autoProcessMusic.py +++ b/autoProcess/autoProcessMusic.py @@ -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: diff --git a/autoProcess/autoProcessTV.py b/autoProcess/autoProcessTV.py index 3d5293e3..3b7aca1c 100644 --- a/autoProcess/autoProcessTV.py +++ b/autoProcess/autoProcessTV.py @@ -3,10 +3,10 @@ import logging import copy import Transcoder -from nzbToMediaEnv import * -from nzbToMediaUtil import * from nzbToMediaSceneExceptions import process_all_exceptions from autoProcess.autoSickBeardFork import autoFork +from nzbToMediaEnv import * +from nzbToMediaUtil import * Logger = logging.getLogger() @@ -40,72 +40,72 @@ def delete(dirName): def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputCategory=None): status = int(failed) - 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 = "SickBeard" - if inputCategory != None and config.has_section(inputCategory): + if inputCategory != None and config().has_section(inputCategory): section = inputCategory watch_dir = "" - host = config.get(section, "host") - port = config.get(section, "port") - username = config.get(section, "username") - password = config.get(section, "password") + host = config().get(section, "host") + port = config().get(section, "port") + username = config().get(section, "username") + password = config().get(section, "password") 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 = "" try: - watch_dir = config.get(section, "watch_dir") - except ConfigParser.NoOptionError: + watch_dir = config().get(section, "watch_dir") + except config.NoOptionError: watch_dir = "" try: - transcode = int(config.get("Transcoder", "transcode")) - except (ConfigParser.NoOptionError, ValueError): + transcode = int(config().get("Transcoder", "transcode")) + except (config.NoOptionError, ValueError): transcode = 0 try: - delete_failed = int(config.get(section, "delete_failed")) - except (ConfigParser.NoOptionError, ValueError): + delete_failed = int(config().get(section, "delete_failed")) + except (config.NoOptionError, ValueError): delete_failed = 0 try: - delay = float(config.get(section, "delay")) - except (ConfigParser.NoOptionError, ValueError): + delay = float(config().get(section, "delay")) + except (config.NoOptionError, ValueError): delay = 0 try: - wait_for = int(config.get(section, "wait_for")) - except (ConfigParser.NoOptionError, ValueError): + wait_for = int(config().get(section, "wait_for")) + except (config.NoOptionError, ValueError): wait_for = 5 try: - SampleIDs = (config.get("Extensions", "SampleIDs")).split(',') - except (ConfigParser.NoOptionError, ValueError): + SampleIDs = (config().get("Extensions", "SampleIDs")).split(',') + except (config.NoOptionError, ValueError): SampleIDs = ['sample','-s.'] try: - nzbExtractionBy = config.get(section, "nzbExtractionBy") - except (ConfigParser.NoOptionError, ValueError): + nzbExtractionBy = config().get(section, "nzbExtractionBy") + except (config.NoOptionError, ValueError): nzbExtractionBy = "Downloader" try: - process_method = config.get(section, "process_method") - except ConfigParser.NoOptionError: + process_method = config().get(section, "process_method") + except config.NoOptionError: process_method = None TimeOut = 60 * int(wait_for) # SickBeard needs to complete all moving and renaming before returning the log sequence via url. socket.setdefaulttimeout(int(TimeOut)) #initialize socket timeout. - mediaContainer = (config.get("Extensions", "mediaExtensions")).split(',') - minSampleSize = int(config.get("Extensions", "minSampleSize")) + mediaContainer = (config().get("Extensions", "mediaExtensions")).split(',') + minSampleSize = int(config().get("Extensions", "minSampleSize")) if not os.path.isdir(dirName) and os.path.isfile(dirName): # If the input directory is a file, assume single file download and split dir/name. dirName = os.path.split(os.path.normpath(dirName))[0] diff --git a/autoProcess/autoSickBeardFork.py b/autoProcess/autoSickBeardFork.py index 56260579..a46b0534 100644 --- a/autoProcess/autoSickBeardFork.py +++ b/autoProcess/autoSickBeardFork.py @@ -1,11 +1,10 @@ -import sys import urllib -import os -import ConfigParser import logging +from nzbToMediaConfig import * from autoProcess.nzbToMediaEnv import * + Logger = logging.getLogger() class AuthURLOpener(urllib.FancyURLopener): @@ -27,29 +26,26 @@ class AuthURLOpener(urllib.FancyURLopener): return urllib.FancyURLopener.open(self, url) def autoFork(fork=None): - config = ConfigParser.ConfigParser() - configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg") - config.read(configFilename) # config settings section = "SickBeard" - host = config.get(section, "host") - port = config.get(section, "port") - username = config.get(section, "username") - password = config.get(section, "password") + host = config().get(section, "host") + port = config().get(section, "port") + username = config().get(section, "username") + password = config().get(section, "password") 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 = "" try: - fork = forks.items()[forks.keys().index(config.get(section, "fork"))] + fork = forks.items()[forks.keys().index(config().get(section, "fork"))] except: fork = "auto" diff --git a/autoProcess/migratecfg.py b/autoProcess/migratecfg.py index 619cab25..b828e0b5 100644 --- a/autoProcess/migratecfg.py +++ b/autoProcess/migratecfg.py @@ -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) \ No newline at end of file diff --git a/autoProcess/nzbToMediaUtil.py b/autoProcess/nzbToMediaUtil.py index 0edba8ae..43fbd73e 100644 --- a/autoProcess/nzbToMediaUtil.py +++ b/autoProcess/nzbToMediaUtil.py @@ -1,28 +1,26 @@ import logging import logging.config -import os import re import sys import shutil import struct import socket import time -import ConfigParser import linktastic.linktastic as linktastic +from nzbToMediaConfig import * + Logger = logging.getLogger() - def safeName(name): safename = re.sub(r"[\/\\\:\*\?\"\<\>\|]", "", name) #make this name safe for use in directories for windows etc. return safename def nzbtomedia_configure_logging(dirname): - logFile = os.path.join(dirname, "postprocess.log") - logging.config.fileConfig(os.path.join(dirname, "autoProcessMedia.cfg")) - fileHandler = logging.handlers.RotatingFileHandler(logFile, mode='a', maxBytes=1048576, backupCount=1, encoding='utf-8', delay=True) + logging.config.fileConfig(CONFIG_FILE) + fileHandler = logging.handlers.RotatingFileHandler(LOG_FILE, mode='a', maxBytes=1048576, backupCount=1, encoding='utf-8', delay=True) fileHandler.formatter = logging.Formatter('%(asctime)s|%(levelname)-7.7s %(message)s', '%H:%M:%S') fileHandler.level = logging.DEBUG logging.getLogger().addHandler(fileHandler) @@ -316,22 +314,18 @@ def TestCon(host, port): def WakeUp(): - config = ConfigParser.ConfigParser() - configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg") - - if not os.path.isfile(configFilename): - Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?") + if not config(): + Logger.error("You need an autoProcessMedia.config() file - did you rename and edit the .sample?") return - config.read(configFilename) - wake = int(config.get("WakeOnLan", "wake")) + wake = int(config().get("WakeOnLan", "wake")) if wake == 0: # just return if we don't need to wake anything. return - Logger.info("Loading WakeOnLan config from %s", configFilename) - config.get("WakeOnLan", "host") - host = config.get("WakeOnLan", "host") - port = int(config.get("WakeOnLan", "port")) - mac = config.get("WakeOnLan", "mac") + Logger.info("Loading WakeOnLan config from %s", CONFIG_FILE) + config().get("WakeOnLan", "host") + host = config().get("WakeOnLan", "host") + port = int(config().get("WakeOnLan", "port")) + mac = config().get("WakeOnLan", "mac") i=1 while TestCon(host, port) == "Down" and i < 4: @@ -346,13 +340,11 @@ def WakeUp(): Logger.info("System with mac: %s has been woken. Continuing with the rest of the script.", mac) def converto_to_ascii(nzbName, dirName): - config = ConfigParser.ConfigParser() - configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg") - if not os.path.isfile(configFilename): + if not config(): Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?") return nzbName, dirName - config.read(configFilename) - ascii_convert = int(config.get("ASCII", "convert")) + + ascii_convert = int(config().get("ASCII", "convert")) if ascii_convert == 0 or os.name == 'nt': # just return if we don't want to convert or on windows os and "\" is replaced!. return nzbName, dirName diff --git a/extractor/extractor.py b/extractor/extractor.py index ff0bedd9..8402cab8 100644 --- a/extractor/extractor.py +++ b/extractor/extractor.py @@ -1,9 +1,8 @@ -import os import sys -import ConfigParser -sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]),'autoProcess/')) import logging -from subprocess import call, Popen, PIPE + +from nzbToMediaConfig import * +from subprocess import call, Popen from autoProcess.nzbToMediaUtil import create_destination @@ -112,11 +111,9 @@ def extract(filePath, outputDestination): # Create outputDestination folder create_destination(outputDestination) - config = ConfigParser.ConfigParser() - configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg") - Logger.info("MAIN: Loading config from %s", configFilename) - config.read(configFilename) - passwordsfile = config.get("passwords", "PassWordFile") + Logger.info("MAIN: Loading config from %s", CONFIG_FILE) + + passwordsfile = config().get("passwords", "PassWordFile") if passwordsfile != "" and os.path.isfile(os.path.normpath(passwordsfile)): passwords = [line.strip() for line in open(os.path.normpath(passwordsfile))] else: diff --git a/nzbToCouchPotato.py b/nzbToCouchPotato.py index d1cb87dd..6370bf0a 100755 --- a/nzbToCouchPotato.py +++ b/nzbToCouchPotato.py @@ -116,8 +116,6 @@ ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## -import os -import sys import logging import autoProcess.migratecfg as migratecfg diff --git a/nzbToGamez.py b/nzbToGamez.py index 415527e7..cbfdcfa6 100755 --- a/nzbToGamez.py +++ b/nzbToGamez.py @@ -57,8 +57,6 @@ ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## -import os -import sys import logging import autoProcess.migratecfg as migratecfg diff --git a/nzbToHeadPhones.py b/nzbToHeadPhones.py index c641b9f1..d4916f0c 100755 --- a/nzbToHeadPhones.py +++ b/nzbToHeadPhones.py @@ -62,8 +62,6 @@ ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## -import os -import sys import logging import autoProcess.migratecfg as migratecfg diff --git a/nzbToMedia.py b/nzbToMedia.py index fadcee68..901ebadc 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -261,22 +261,25 @@ ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## -import os -import sys -import ConfigParser import logging -import autoProcess.migratecfg as migratecfg import autoProcess.autoProcessComics as autoProcessComics import autoProcess.autoProcessGames as autoProcessGames import autoProcess.autoProcessMusic as autoProcessMusic import autoProcess.autoProcessMovie as autoProcessMovie import autoProcess.autoProcessTV as autoProcessTV +import autoProcess.migratecfg as migratecfg from autoProcess.nzbToMediaEnv import * from autoProcess.nzbToMediaUtil import * +# Exit codes used by NZBGet +POSTPROCESS_PARCHECK = 92 +POSTPROCESS_SUCCESS = 93 +POSTPROCESS_ERROR = 94 +POSTPROCESS_NONE = 95 + # check to migrate old cfg before trying to load. -if os.path.isfile(os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg.sample")): +if config(SAMPLE_CONFIG_FILE): migratecfg.migrate() # check to write settings from nzbGet UI to autoProcessMedia.cfg. if os.environ.has_key('NZBOP_SCRIPTDIR'): @@ -290,20 +293,17 @@ Logger.info("nzbToMedia %s", VERSION) WakeUp() -config = ConfigParser.ConfigParser() -configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg") -if not os.path.isfile(configFilename): +if not config(): Logger.error("MAIN: You need an autoProcessMedia.cfg file - did you rename and edit the .sample?") sys.exit(-1) -# CONFIG FILE -Logger.info("MAIN: Loading config from %s", configFilename) -config.read(configFilename) -cpsCategory = (config.get("CouchPotato", "cpsCategory")).split(',') # movie -sbCategory = (config.get("SickBeard", "sbCategory")).split(',') # tv -hpCategory = (config.get("HeadPhones", "hpCategory")).split(',') # music -mlCategory = (config.get("Mylar", "mlCategory")).split(',') # comics -gzCategory = (config.get("Gamez", "gzCategory")).split(',') # games +Logger.info("MAIN: Loading config from %s", CONFIG_FILE) + +cpsCategory = (config().get("CouchPotato", "cpsCategory")).split(',') # movie +sbCategory = (config().get("SickBeard", "sbCategory")).split(',') # tv +hpCategory = (config().get("HeadPhones", "hpCategory")).split(',') # music +mlCategory = (config().get("Mylar", "mlCategory")).split(',') # comics +gzCategory = (config().get("Gamez", "gzCategory")).split(',') # games # NZBGet V11+ # Check if the script is called from nzbget 11.0 or later @@ -312,11 +312,6 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 # NZBGet argv: all passed as environment variables. clientAgent = "nzbget" - # Exit codes used by NZBGet - POSTPROCESS_PARCHECK=92 - POSTPROCESS_SUCCESS=93 - POSTPROCESS_ERROR=94 - POSTPROCESS_NONE=95 # Check nzbget.conf options status = 0 diff --git a/nzbToMediaConfig.py b/nzbToMediaConfig.py new file mode 100644 index 00000000..7cdce263 --- /dev/null +++ b/nzbToMediaConfig.py @@ -0,0 +1,35 @@ +import os +import ConfigParser + +# init paths +MY_FULLNAME = os.path.normpath(os.path.abspath(__file__)) +MY_NAME = os.path.basename(MY_FULLNAME) +PROG_DIR = os.path.dirname(MY_FULLNAME) + +# init config file names +CONFIG_FILE = os.path.join(PROG_DIR, "autoProcessMedia.cfg") +SAMPLE_CONFIG_FILE = os.path.join(PROG_DIR, "autoProcessMedia.cfg.sample") +MOVIE_CONFIG_FILE = os.path.join(PROG_DIR, "autoProcessMovie.cfg") +TV_CONFIG_FILE = os.path.join(PROG_DIR, "autoProcessTv.cfg") +LOG_FILE = os.path.join(PROG_DIR, "postprocess.log") + +class config(ConfigParser.ConfigParser): + + # link error handlers + Error = ConfigParser.Error + NoSectionError = ConfigParser.NoSectionError + NoOptionError = ConfigParser.NoOptionError + DuplicateSectionError = ConfigParser.DuplicateSectionError + InterpolationError = ConfigParser.InterpolationError + InterpolationMissingOptionError = ConfigParser.InterpolationMissingOptionError + InterpolationSyntaxError = ConfigParser.InterpolationSyntaxError + InterpolationDepthError = ConfigParser.InterpolationDepthError + ParsingError = ConfigParser.ParsingError + MissingSectionHeaderError = ConfigParser.MissingSectionHeaderError + + def __init__(self, *file): + ConfigParser.ConfigParser.__init__(self) + self.optionxform = str + if not file: + file = CONFIG_FILE + self.read(file) diff --git a/nzbToMylar.py b/nzbToMylar.py index 88d75316..a22e6df7 100755 --- a/nzbToMylar.py +++ b/nzbToMylar.py @@ -60,8 +60,6 @@ ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## -import os -import sys import logging import autoProcess.migratecfg as migratecfg diff --git a/nzbToSickBeard.py b/nzbToSickBeard.py index 78792076..17f40e9b 100755 --- a/nzbToSickBeard.py +++ b/nzbToSickBeard.py @@ -124,8 +124,6 @@ ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## -import os -import sys import logging import autoProcess.migratecfg as migratecfg diff --git a/synchronousdeluge/client.py b/synchronousdeluge/client.py index 22419e80..394b6767 100644 --- a/synchronousdeluge/client.py +++ b/synchronousdeluge/client.py @@ -1,6 +1,5 @@ import os import platform - from collections import defaultdict from itertools import imap @@ -8,6 +7,7 @@ from synchronousdeluge.exceptions import DelugeRPCError from synchronousdeluge.protocol import DelugeRPCRequest, DelugeRPCResponse from synchronousdeluge.transfer import DelugeTransfer + __all__ = ["DelugeClient"] diff --git a/synchronousdeluge/rencode.py b/synchronousdeluge/rencode.py index e58c7154..a0a6eec3 100644 --- a/synchronousdeluge/rencode.py +++ b/synchronousdeluge/rencode.py @@ -63,7 +63,6 @@ __all__ = ['dumps', 'loads'] # import struct -import string from threading import Lock # Default number of bits for serialized floats, either 32 or 64 (also a parameter for dumps()). diff --git a/tests/test_autofork.py b/tests/test_autofork.py new file mode 100644 index 00000000..89364ddf --- /dev/null +++ b/tests/test_autofork.py @@ -0,0 +1,3 @@ +from autoProcess.autoSickBeardFork import autoFork +fork, params = autoFork() +print fork, params \ No newline at end of file diff --git a/transmissionrpc/client.py b/transmissionrpc/client.py index 095f7de7..436006b9 100644 --- a/transmissionrpc/client.py +++ b/transmissionrpc/client.py @@ -2,7 +2,11 @@ # Copyright (c) 2008-2013 Erik Svensson # Licensed under the MIT license. -import re, time, operator, warnings, os +import re +import time +import operator +import warnings +import os import base64 import json @@ -12,9 +16,9 @@ from transmissionrpc.utils import LOGGER, get_arguments, make_rpc_name, argument from transmissionrpc.httphandler import DefaultHTTPHandler from transmissionrpc.torrent import Torrent from transmissionrpc.session import Session - from six import PY3, integer_types, string_types, iteritems + if PY3: from urllib.parse import urlparse from urllib.request import urlopen diff --git a/transmissionrpc/constants.py b/transmissionrpc/constants.py index 984eb44c..8c706b34 100644 --- a/transmissionrpc/constants.py +++ b/transmissionrpc/constants.py @@ -3,8 +3,10 @@ # Licensed under the MIT license. import logging + from six import iteritems + LOGGER = logging.getLogger('transmissionrpc') LOGGER.setLevel(logging.ERROR) diff --git a/transmissionrpc/httphandler.py b/transmissionrpc/httphandler.py index 47c5326d..3fdcee6c 100644 --- a/transmissionrpc/httphandler.py +++ b/transmissionrpc/httphandler.py @@ -5,7 +5,6 @@ import sys from transmissionrpc.error import HTTPHandlerError - from six import PY3 if PY3: diff --git a/transmissionrpc/six.py b/transmissionrpc/six.py index 85898ec7..836d516c 100644 --- a/transmissionrpc/six.py +++ b/transmissionrpc/six.py @@ -151,7 +151,7 @@ _moved_attributes = [ MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"), MovedModule("builtins", "__builtin__"), - MovedModule("configparser", "ConfigParser"), + MovedModule("config", "config"), MovedModule("copyreg", "copy_reg"), MovedModule("http_cookiejar", "cookielib", "http.cookiejar"), MovedModule("http_cookies", "Cookie", "http.cookies"), diff --git a/transmissionrpc/torrent.py b/transmissionrpc/torrent.py index eee66809..4d7d3d64 100644 --- a/transmissionrpc/torrent.py +++ b/transmissionrpc/torrent.py @@ -2,11 +2,11 @@ # Copyright (c) 2008-2013 Erik Svensson # Licensed under the MIT license. -import sys, datetime +import sys +import datetime from transmissionrpc.constants import PRIORITY, RATIO_LIMIT, IDLE_LIMIT from transmissionrpc.utils import Field, format_timedelta - from six import integer_types, string_types, text_type, iteritems diff --git a/transmissionrpc/utils.py b/transmissionrpc/utils.py index b8e37dfa..40653213 100644 --- a/transmissionrpc/utils.py +++ b/transmissionrpc/utils.py @@ -2,13 +2,16 @@ # Copyright (c) 2008-2013 Erik Svensson # Licensed under the MIT license. -import socket, datetime, logging +import socket +import datetime +import logging from collections import namedtuple + import transmissionrpc.constants as constants from transmissionrpc.constants import LOGGER - from six import string_types, iteritems + UNITS = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'] def format_size(size): diff --git a/utorrent/upload.py b/utorrent/upload.py index e7c06f40..9886c3ec 100644 --- a/utorrent/upload.py +++ b/utorrent/upload.py @@ -3,9 +3,7 @@ import itertools import mimetools import mimetypes -from cStringIO import StringIO -import urllib -import urllib2 + class MultiPartForm(object): """Accumulate the data to be used when posting a form."""