diff --git a/couchpotato/__init__.py b/couchpotato/__init__.py index 9ab7d65..089ecd4 100644 --- a/couchpotato/__init__.py +++ b/couchpotato/__init__.py @@ -4,9 +4,6 @@ from couchpotato.core.event import fireEvent from couchpotato.core.helpers.variable import md5 from couchpotato.core.logger import CPLog from couchpotato.environment import Env -from sqlalchemy.engine import create_engine -from sqlalchemy.orm import scoped_session -from sqlalchemy.orm.session import sessionmaker from tornado import template from tornado.web import RequestHandler import os diff --git a/couchpotato/api.py b/couchpotato/api.py index d133853..e8970dc 100644 --- a/couchpotato/api.py +++ b/couchpotato/api.py @@ -104,7 +104,7 @@ class ApiHandler(RequestHandler): if jsonp_callback: self.write(str(jsonp_callback) + '(' + json.dumps(result) + ')') - elif isinstance(result, (tuple)) and result[0] == 'redirect': + elif isinstance(result, tuple) and result[0] == 'redirect': self.redirect(result[1]) else: self.write(result) diff --git a/couchpotato/core/_base/clientscript/main.py b/couchpotato/core/_base/clientscript/main.py index fece6fa..7476f39 100644 --- a/couchpotato/core/_base/clientscript/main.py +++ b/couchpotato/core/_base/clientscript/main.py @@ -111,7 +111,7 @@ class ClientScript(Plugin): data = jsmin(f) else: data = self.prefix(f) - data = cssmin(f) + data = cssmin(data) data = data.replace('../images/', '../static/images/') data = data.replace('../fonts/', '../static/fonts/') data = data.replace('../../static/', '../static/') # Replace inside plugins diff --git a/couchpotato/core/auth.py b/couchpotato/core/auth.py index e58016b..e877860 100644 --- a/couchpotato/core/auth.py +++ b/couchpotato/core/auth.py @@ -10,10 +10,15 @@ def requires_auth(handler_class): def wrap_execute(handler_execute): def require_basic_auth(handler, kwargs): + if Env.setting('username') and Env.setting('password'): auth_header = handler.request.headers.get('Authorization') auth_decoded = base64.decodestring(auth_header[6:]) if auth_header else None + + username = '' + password = '' + if auth_decoded: username, password = auth_decoded.split(':', 2) diff --git a/couchpotato/core/downloaders/base.py b/couchpotato/core/downloaders/base.py index cc0d59e..3b160c6 100644 --- a/couchpotato/core/downloaders/base.py +++ b/couchpotato/core/downloaders/base.py @@ -119,7 +119,7 @@ class Downloader(Provider): except: log.debug('Torrent hash "%s" wasn\'t found on: %s', (torrent_hash, source)) - log.error('Failed converting magnet url to torrent: %s', (torrent_hash)) + log.error('Failed converting magnet url to torrent: %s', torrent_hash) return False def downloadReturnId(self, download_id): @@ -128,7 +128,7 @@ class Downloader(Provider): 'id': download_id } - def isDisabled(self, manual, data): + def isDisabled(self, manual = False, data = {}): return not self.isEnabled(manual, data) def _isEnabled(self, manual, data = {}): @@ -136,10 +136,10 @@ class Downloader(Provider): return return True - def isEnabled(self, manual, data = {}): + def isEnabled(self, manual = False, data = {}): d_manual = self.conf('manual', default = False) return super(Downloader, self).isEnabled() and \ - ((d_manual and manual) or (d_manual is False)) and \ + (d_manual and manual or d_manual is False) and \ (not data or self.isCorrectProtocol(data.get('protocol'))) def _pause(self, item, pause = True): diff --git a/couchpotato/core/downloaders/blackhole/main.py b/couchpotato/core/downloaders/blackhole/main.py index 9d2a526..750c6c7 100644 --- a/couchpotato/core/downloaders/blackhole/main.py +++ b/couchpotato/core/downloaders/blackhole/main.py @@ -62,7 +62,7 @@ class Blackhole(Downloader): else: return ['nzb'] - def isEnabled(self, manual, data = {}): + def isEnabled(self, manual = False, data = {}): for_protocol = ['both'] if data and 'torrent' in data.get('protocol'): for_protocol.append('torrent') diff --git a/couchpotato/core/downloaders/deluge/main.py b/couchpotato/core/downloaders/deluge/main.py index 6a9eb3c..580ed7f 100644 --- a/couchpotato/core/downloaders/deluge/main.py +++ b/couchpotato/core/downloaders/deluge/main.py @@ -54,7 +54,7 @@ class Deluge(Downloader): if self.conf('completed_directory'): if os.path.isdir(self.conf('completed_directory')): - options['move_completed'] = 1 + options['move_completed'] = 1 options['move_completed_path'] = self.conf('completed_directory') else: log.error('Download directory from Deluge settings: %s doesn\'t exist', self.conf('directory')) @@ -96,7 +96,7 @@ class Deluge(Downloader): queue = self.drpc.get_alltorrents() - if not (queue): + if not queue: log.debug('Nothing in queue or error') return False diff --git a/couchpotato/core/downloaders/nzbget/main.py b/couchpotato/core/downloaders/nzbget/main.py index 04f68f4..adeedea 100644 --- a/couchpotato/core/downloaders/nzbget/main.py +++ b/couchpotato/core/downloaders/nzbget/main.py @@ -172,11 +172,15 @@ class NZBGet(Downloader): try: history = rpc.history() + nzb_id = None + path = None + for hist in history: if hist['Parameters'] and hist['Parameters']['couchpotato'] and hist['Parameters']['couchpotato'] == item['id']: nzb_id = hist['ID'] path = hist['DestDir'] - if rpc.editqueue('HistoryDelete', 0, "", [tryInt(nzb_id)]): + + if nzb_id and path and rpc.editqueue('HistoryDelete', 0, "", [tryInt(nzb_id)]): shutil.rmtree(path, True) except: log.error('Failed deleting: %s', traceback.format_exc(0)) diff --git a/couchpotato/core/downloaders/nzbvortex/main.py b/couchpotato/core/downloaders/nzbvortex/main.py index 2944c32..1e0a4b2 100644 --- a/couchpotato/core/downloaders/nzbvortex/main.py +++ b/couchpotato/core/downloaders/nzbvortex/main.py @@ -122,7 +122,7 @@ class NZBVortex(Downloader): # Try login and do again if not repeat: self.login() - return self.call(call, parameters = parameters, repeat = True, *args, **kwargs) + return self.call(call, parameters = parameters, repeat = True, **kwargs) log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) except: @@ -148,7 +148,7 @@ class NZBVortex(Downloader): return self.api_level - def isEnabled(self, manual, data): + def isEnabled(self, manual = False, data = {}): return super(NZBVortex, self).isEnabled(manual, data) and self.getApiLevel() diff --git a/couchpotato/core/downloaders/sabnzbd/main.py b/couchpotato/core/downloaders/sabnzbd/main.py index 68bbd26..110c55b 100644 --- a/couchpotato/core/downloaders/sabnzbd/main.py +++ b/couchpotato/core/downloaders/sabnzbd/main.py @@ -26,9 +26,10 @@ class Sabnzbd(Downloader): 'priority': self.conf('priority'), } + nzb_filename = None if filedata: if len(filedata) < 50: - log.error('No proper nzb available: %s', (filedata)) + log.error('No proper nzb available: %s', filedata) return False # If it's a .rar, it adds the .rar extension, otherwise it stays .nzb @@ -38,7 +39,7 @@ class Sabnzbd(Downloader): req_params['name'] = data.get('url') try: - if req_params.get('mode') is 'addfile': + if nzb_filename and req_params.get('mode') is 'addfile': sab_data = self.call(req_params, params = {'nzbfile': (ss(nzb_filename), filedata)}, multipart = True) else: sab_data = self.call(req_params) diff --git a/couchpotato/core/downloaders/synology/main.py b/couchpotato/core/downloaders/synology/main.py index 362577f..58ab099 100644 --- a/couchpotato/core/downloaders/synology/main.py +++ b/couchpotato/core/downloaders/synology/main.py @@ -49,7 +49,7 @@ class Synology(Downloader): else: return ['nzb'] - def isEnabled(self, manual, data = {}): + def isEnabled(self, manual = False, data = {}): for_protocol = ['both'] if data and 'torrent' in data.get('protocol'): for_protocol.append('torrent') @@ -61,7 +61,7 @@ class Synology(Downloader): class SynologyRPC(object): - '''SynologyRPC lite library''' + """SynologyRPC lite library""" def __init__(self, host = 'localhost', port = 5000, username = None, password = None): @@ -98,7 +98,7 @@ class SynologyRPC(object): req = requests.post(url, data = args, files = files) req.raise_for_status() response = json.loads(req.text) - if response['success'] == True: + if response['success']: log.info('Synology action successfull') return response except requests.ConnectionError, err: @@ -111,11 +111,11 @@ class SynologyRPC(object): return response def create_task(self, url = None, filename = None, filedata = None): - ''' Creates new download task in Synology DownloadStation. Either specify + """ Creates new download task in Synology DownloadStation. Either specify url or pair (filename, filedata). Returns True if task was created, False otherwise - ''' + """ result = False # login if self._login(): diff --git a/couchpotato/core/downloaders/transmission/main.py b/couchpotato/core/downloaders/transmission/main.py index be7f2f7..5ff33c0 100644 --- a/couchpotato/core/downloaders/transmission/main.py +++ b/couchpotato/core/downloaders/transmission/main.py @@ -44,8 +44,9 @@ class Transmission(Downloader): return False # Set parameters for adding torrent - params = {} - params['paused'] = self.conf('paused', default = False) + params = { + 'paused': self.conf('paused', default = False) + } if self.conf('directory'): if os.path.isdir(self.conf('directory')): @@ -135,11 +136,11 @@ class Transmission(Downloader): def removeFailed(self, item): log.info('%s failed downloading, deleting...', item['name']) - return self.trpc.remove_torrent(self, item['hashString'], True) + return self.trpc.remove_torrent(item['hashString'], True) def processComplete(self, item, delete_files = False): log.debug('Requesting Transmission to remove the torrent %s%s.', (item['name'], ' and cleanup the downloaded files' if delete_files else '')) - return self.trpc.remove_torrent(self, item['hashString'], delete_files) + return self.trpc.remove_torrent(item['hashString'], delete_files) class TransmissionRPC(object): diff --git a/couchpotato/core/downloaders/utorrent/main.py b/couchpotato/core/downloaders/utorrent/main.py index 59e9a4a..e1b9938 100644 --- a/couchpotato/core/downloaders/utorrent/main.py +++ b/couchpotato/core/downloaders/utorrent/main.py @@ -1,5 +1,5 @@ from base64 import b16encode, b32decode -from bencode import bencode, bdecode +from bencode import bencode as benc, bdecode from couchpotato.core.downloaders.base import Downloader, StatusList from couchpotato.core.helpers.encoding import isInt, ss from couchpotato.core.helpers.variable import tryInt, tryFloat @@ -74,7 +74,7 @@ class uTorrent(Downloader): torrent_params['trackers'] = '%0D%0A%0D%0A'.join(self.torrent_trackers) else: info = bdecode(filedata)["info"] - torrent_hash = sha1(bencode(info)).hexdigest().upper() + torrent_hash = sha1(benc(info)).hexdigest().upper() torrent_filename = self.createFileName(data, filedata, movie) if data.get('seed_ratio'): diff --git a/couchpotato/core/event.py b/couchpotato/core/event.py index 0e0b4a7..30c5189 100644 --- a/couchpotato/core/event.py +++ b/couchpotato/core/event.py @@ -21,9 +21,11 @@ def addEvent(name, handler, priority = 100): def createHandle(*args, **kwargs): + h = None try: # Open handler has_parent = hasattr(handler, 'im_self') + parent = None if has_parent: parent = handler.im_self bc = hasattr(parent, 'beforeCall') @@ -33,7 +35,7 @@ def addEvent(name, handler, priority = 100): h = runHandler(name, handler, *args, **kwargs) # Close handler - if has_parent: + if parent and has_parent: ac = hasattr(parent, 'afterCall') if ac: parent.afterCall(handler) except: diff --git a/couchpotato/core/helpers/encoding.py b/couchpotato/core/helpers/encoding.py index 9b753db..6e86444 100644 --- a/couchpotato/core/helpers/encoding.py +++ b/couchpotato/core/helpers/encoding.py @@ -63,7 +63,7 @@ def stripAccents(s): def tryUrlencode(s): new = u'' - if isinstance(s, (dict)): + if isinstance(s, dict): for key, value in s.iteritems(): new += u'&%s=%s' % (key, tryUrlencode(value)) diff --git a/couchpotato/core/helpers/request.py b/couchpotato/core/helpers/request.py index c224979..888e63f 100644 --- a/couchpotato/core/helpers/request.py +++ b/couchpotato/core/helpers/request.py @@ -8,7 +8,7 @@ def getParams(params): reg = re.compile('^[a-z0-9_\.]+$') - current = temp = {} + temp = {} for param, value in sorted(params.iteritems()): nest = re.split("([\[\]]+)", param) diff --git a/couchpotato/core/helpers/rss.py b/couchpotato/core/helpers/rss.py index d88fdb5..b840d86 100644 --- a/couchpotato/core/helpers/rss.py +++ b/couchpotato/core/helpers/rss.py @@ -6,7 +6,7 @@ log = CPLog(__name__) class RSS(object): def getTextElements(self, xml, path): - ''' Find elements and return tree''' + """ Find elements and return tree""" textelements = [] try: @@ -28,7 +28,7 @@ class RSS(object): return elements def getElement(self, xml, path): - ''' Find element and return text''' + """ Find element and return text""" try: return xml.find(path) @@ -36,7 +36,7 @@ class RSS(object): return def getTextElement(self, xml, path): - ''' Find element and return text''' + """ Find element and return text""" try: return xml.find(path).text diff --git a/couchpotato/core/helpers/variable.py b/couchpotato/core/helpers/variable.py index 537b356..8f393d0 100644 --- a/couchpotato/core/helpers/variable.py +++ b/couchpotato/core/helpers/variable.py @@ -179,11 +179,11 @@ def getTitle(library_dict): def possibleTitles(raw_title): - titles = [] - - titles.append(toSafeString(raw_title).lower()) - titles.append(raw_title.lower()) - titles.append(simplifyString(raw_title)) + titles = [ + toSafeString(raw_title).lower(), + raw_title.lower(), + simplifyString(raw_title) + ] # replace some chars new_title = raw_title.replace('&', 'and') diff --git a/couchpotato/core/loader.py b/couchpotato/core/loader.py index 745c75d..f101105 100644 --- a/couchpotato/core/loader.py +++ b/couchpotato/core/loader.py @@ -66,7 +66,7 @@ class Loader(object): self.loadPlugins(m, plugin.get('name')) except ImportError as e: # todo:: subclass ImportError for missing requirements. - if (e.message.lower().startswith("missing")): + if e.message.lower().startswith("missing"): log.error(e.message) pass # todo:: this needs to be more descriptive. @@ -122,7 +122,7 @@ class Loader(object): try: module.start() return True - except Exception, e: + except: log.error('Failed loading plugin "%s": %s', (module.__file__, traceback.format_exc())) return False diff --git a/couchpotato/core/media/__init__.py b/couchpotato/core/media/__init__.py index 8187f98..1cef967 100644 --- a/couchpotato/core/media/__init__.py +++ b/couchpotato/core/media/__init__.py @@ -1,5 +1,4 @@ from couchpotato.core.event import addEvent -from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin diff --git a/couchpotato/core/media/_base/searcher/__init__.py b/couchpotato/core/media/_base/searcher/__init__.py index f3d764d..0fb6cc0 100644 --- a/couchpotato/core/media/_base/searcher/__init__.py +++ b/couchpotato/core/media/_base/searcher/__init__.py @@ -1,5 +1,4 @@ from .main import Searcher -import random def start(): return Searcher() diff --git a/couchpotato/core/media/_base/searcher/base.py b/couchpotato/core/media/_base/searcher/base.py index ab29439..368c6e2 100644 --- a/couchpotato/core/media/_base/searcher/base.py +++ b/couchpotato/core/media/_base/searcher/base.py @@ -1,4 +1,3 @@ -from couchpotato.api import addApiView from couchpotato.core.event import addEvent, fireEvent from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin @@ -19,12 +18,10 @@ class SearcherBase(Plugin): self.initCron() - - """ Set the searcher cronjob - Make sure to reset cronjob after setting has changed - - """ def initCron(self): + """ Set the searcher cronjob + Make sure to reset cronjob after setting has changed + """ _type = self.getType() @@ -38,14 +35,11 @@ class SearcherBase(Plugin): addEvent('setting.save.%s_searcher.cron_hour.after' % _type, setCrons) addEvent('setting.save.%s_searcher.cron_minute.after' % _type, setCrons) - - """ Return progress of current searcher - - """ def getProgress(self, **kwargs): + """ Return progress of current searcher""" - progress = {} - progress[self.getType()] = self.in_progress + progress = { + self.getType(): self.in_progress + } return progress - diff --git a/couchpotato/core/media/_base/searcher/main.py b/couchpotato/core/media/_base/searcher/main.py index 7d84a58..3222edb 100644 --- a/couchpotato/core/media/_base/searcher/main.py +++ b/couchpotato/core/media/_base/searcher/main.py @@ -173,10 +173,10 @@ class Searcher(SearcherBase): year_name = fireEvent('scanner.name_year', name, single = True) if len(found) == 0 and movie_year < datetime.datetime.now().year - 3 and not year_name.get('year', None): if size > 3000: # Assume dvdr - log.info('Quality was missing in name, assuming it\'s a DVD-R based on the size: %s', (size)) + log.info('Quality was missing in name, assuming it\'s a DVD-R based on the size: %s', size) found['dvdr'] = True else: # Assume dvdrip - log.info('Quality was missing in name, assuming it\'s a DVD-Rip based on the size: %s', (size)) + log.info('Quality was missing in name, assuming it\'s a DVD-Rip based on the size: %s', size) found['dvdrip'] = True # Allow other qualities @@ -191,6 +191,7 @@ class Searcher(SearcherBase): if not isinstance(haystack, (list, tuple, set)): haystack = [haystack] + year_name = {} for string in haystack: year_name = fireEvent('scanner.name_year', string, single = True) diff --git a/couchpotato/core/media/movie/_base/main.py b/couchpotato/core/media/movie/_base/main.py index 518893f..a8d890d 100644 --- a/couchpotato/core/media/movie/_base/main.py +++ b/couchpotato/core/media/movie/_base/main.py @@ -145,7 +145,7 @@ class MovieBase(MovieTypeBase): imdb_id = getImdb(str(movie_id)) - if(imdb_id): + if imdb_id: m = db.query(Movie).filter(Movie.library.has(identifier = imdb_id)).first() else: m = db.query(Movie).filter_by(id = movie_id).first() @@ -231,7 +231,7 @@ class MovieBase(MovieTypeBase): })) db.expire_all() - return (total_count, movies) + return total_count, movies def availableChars(self, status = None, release_status = None): @@ -270,12 +270,12 @@ class MovieBase(MovieTypeBase): def listView(self, **kwargs): - status = splitString(kwargs.get('status', None)) - release_status = splitString(kwargs.get('release_status', None)) - limit_offset = kwargs.get('limit_offset', None) - starts_with = kwargs.get('starts_with', None) - search = kwargs.get('search', None) - order = kwargs.get('order', None) + status = splitString(kwargs.get('status')) + release_status = splitString(kwargs.get('release_status')) + limit_offset = kwargs.get('limit_offset') + starts_with = kwargs.get('starts_with') + search = kwargs.get('search') + order = kwargs.get('order') total_movies, movies = self.list( status = status, @@ -372,7 +372,7 @@ class MovieBase(MovieTypeBase): fireEvent('status.get', ['active', 'snatched', 'ignored', 'done', 'downloaded'], single = True) default_profile = fireEvent('profile.default', single = True) - cat_id = params.get('category_id', None) + cat_id = params.get('category_id') db = get_session() m = db.query(Movie).filter_by(library_id = library.get('id')).first() @@ -463,7 +463,7 @@ class MovieBase(MovieTypeBase): m.profile_id = kwargs.get('profile_id') - cat_id = kwargs.get('category_id', None) + cat_id = kwargs.get('category_id') if cat_id is not None: m.category_id = tryInt(cat_id) if tryInt(cat_id) > 0 else None @@ -559,7 +559,7 @@ class MovieBase(MovieTypeBase): log.debug('Can\'t restatus movie, doesn\'t seem to exist.') return False - log.debug('Changing status for %s', (m.library.titles[0].title)) + log.debug('Changing status for %s', m.library.titles[0].title) if not m.profile: m.status_id = done_status.get('id') else: diff --git a/couchpotato/core/media/movie/library/movie/main.py b/couchpotato/core/media/movie/library/movie/main.py index 98da582..12e6abc 100644 --- a/couchpotato/core/media/movie/library/movie/main.py +++ b/couchpotato/core/media/movie/library/movie/main.py @@ -2,8 +2,8 @@ from couchpotato import get_session from couchpotato.core.event import addEvent, fireEventAsync, fireEvent from couchpotato.core.helpers.encoding import toUnicode, simplifyString from couchpotato.core.logger import CPLog -from couchpotato.core.settings.model import Library, LibraryTitle, File from couchpotato.core.media._base.library import LibraryBase +from couchpotato.core.settings.model import Library, LibraryTitle, File from string import ascii_letters import time import traceback @@ -66,6 +66,7 @@ class MovieLibraryPlugin(LibraryBase): library = db.query(Library).filter_by(identifier = identifier).first() done_status = fireEvent('status.get', 'done', single = True) + library_dict = None if library: library_dict = library.to_dict(self.default_dict) diff --git a/couchpotato/core/notifications/base.py b/couchpotato/core/notifications/base.py index 7418e1a..61cb212 100644 --- a/couchpotato/core/notifications/base.py +++ b/couchpotato/core/notifications/base.py @@ -45,6 +45,7 @@ class Notification(Provider): def _notify(self, *args, **kwargs): if self.isEnabled(): return self.notify(*args, **kwargs) + return False def notify(self, message = '', data = {}, listener = None): pass diff --git a/couchpotato/core/notifications/nmj/main.py b/couchpotato/core/notifications/nmj/main.py index 695f53b..43bb950 100644 --- a/couchpotato/core/notifications/nmj/main.py +++ b/couchpotato/core/notifications/nmj/main.py @@ -23,16 +23,15 @@ class NMJ(Notification): def autoConfig(self, host = 'localhost', **kwargs): - database = '' mount = '' try: terminal = telnetlib.Telnet(host) except Exception: - log.error('Warning: unable to get a telnet session to %s', (host)) + log.error('Warning: unable to get a telnet session to %s', host) return self.failed() - log.debug('Connected to %s via telnet', (host)) + log.debug('Connected to %s via telnet', host) terminal.read_until('sh-3.00# ') terminal.write('cat /tmp/source\n') terminal.write('cat /tmp/netshare\n') @@ -46,7 +45,7 @@ class NMJ(Notification): device = match.group(2) log.info('Found NMJ database %s on device %s', (database, device)) else: - log.error('Could not get current NMJ database on %s, NMJ is probably not running!', (host)) + log.error('Could not get current NMJ database on %s, NMJ is probably not running!', host) return self.failed() if device.startswith('NETWORK_SHARE/'): @@ -54,7 +53,7 @@ class NMJ(Notification): if match: mount = match.group().replace('127.0.0.1', host) - log.info('Found mounting url on the Popcorn Hour in configuration: %s', (mount)) + log.info('Found mounting url on the Popcorn Hour in configuration: %s', mount) else: log.error('Detected a network share on the Popcorn Hour, but could not get the mounting url') return self.failed() @@ -73,9 +72,9 @@ class NMJ(Notification): database = self.conf('database') if mount: - log.debug('Try to mount network drive via url: %s', (mount)) + log.debug('Try to mount network drive via url: %s', mount) try: - data = self.urlopen(mount) + self.urlopen(mount) except: return False @@ -98,11 +97,11 @@ class NMJ(Notification): et = etree.fromstring(response) result = et.findtext('returnValue') except SyntaxError, e: - log.error('Unable to parse XML returned from the Popcorn Hour: %s', (e)) + log.error('Unable to parse XML returned from the Popcorn Hour: %s', e) return False if int(result) > 0: - log.error('Popcorn Hour returned an errorcode: %s', (result)) + log.error('Popcorn Hour returned an errorcode: %s', result) return False else: log.info('NMJ started background scan') diff --git a/couchpotato/core/notifications/notifymyandroid/main.py b/couchpotato/core/notifications/notifymyandroid/main.py index 2c4ac90..5e5bfb9 100644 --- a/couchpotato/core/notifications/notifymyandroid/main.py +++ b/couchpotato/core/notifications/notifymyandroid/main.py @@ -15,12 +15,9 @@ class NotifyMyAndroid(Notification): nma.addkey(keys) nma.developerkey(self.conf('dev_key')) - # hacky fix for the event type - # as it seems to be part of the message now - self.event = message.split(' ')[0] response = nma.push( application = self.default_title, - event = self.event, + event = message.split(' ')[0], description = message, priority = self.conf('priority'), batch_mode = len(keys) > 1 diff --git a/couchpotato/core/notifications/plex/main.py b/couchpotato/core/notifications/plex/main.py index 02c9b30..9becfb5 100644 --- a/couchpotato/core/notifications/plex/main.py +++ b/couchpotato/core/notifications/plex/main.py @@ -37,7 +37,7 @@ class Plex(Notification): for s in sections: if s.getAttribute('type') in source_type: url = refresh_url % s.getAttribute('key') - x = self.urlopen(url) + self.urlopen(url) except: log.error('Plex library update failed for %s, Media Server not running: %s', (host, traceback.format_exc(1))) diff --git a/couchpotato/core/notifications/synoindex/main.py b/couchpotato/core/notifications/synoindex/main.py index 315520e..3980430 100644 --- a/couchpotato/core/notifications/synoindex/main.py +++ b/couchpotato/core/notifications/synoindex/main.py @@ -27,9 +27,8 @@ class Synoindex(Notification): return True except OSError, e: log.error('Unable to run synoindex: %s', e) - return False - return True + return False def test(self, **kwargs): return { diff --git a/couchpotato/core/notifications/twitter/main.py b/couchpotato/core/notifications/twitter/main.py index facc36b..4a34d60 100644 --- a/couchpotato/core/notifications/twitter/main.py +++ b/couchpotato/core/notifications/twitter/main.py @@ -4,7 +4,8 @@ from couchpotato.core.helpers.variable import cleanHost from couchpotato.core.logger import CPLog from couchpotato.core.notifications.base import Notification from couchpotato.environment import Env -from pytwitter import Api, parse_qsl +from pytwitter import Api +from urlparse import parse_qsl import oauth2 log = CPLog(__name__) diff --git a/couchpotato/core/notifications/xbmc/main.py b/couchpotato/core/notifications/xbmc/main.py index 34a9c1d..836b40c 100755 --- a/couchpotato/core/notifications/xbmc/main.py +++ b/couchpotato/core/notifications/xbmc/main.py @@ -53,9 +53,9 @@ class XBMC(Notification): try: for result in response: - if (result.get('result') and result['result'] == 'OK'): + if result.get('result') and result['result'] == 'OK': successful += 1 - elif (result.get('error')): + elif result.get('error'): log.error('XBMC error; %s: %s (%s)', (result['id'], result['error']['message'], result['error']['code'])) except: @@ -72,7 +72,7 @@ class XBMC(Notification): ('JSONRPC.Version', {}) ]) for result in response: - if (result.get('result') and type(result['result']['version']).__name__ == 'int'): + if result.get('result') and type(result['result']['version']).__name__ == 'int': # only v2 and v4 return an int object # v6 (as of XBMC v12(Frodo)) is required to send notifications xbmc_rpc_version = str(result['result']['version']) @@ -85,15 +85,15 @@ class XBMC(Notification): # send the text message resp = self.notifyXBMCnoJSON(host, {'title':self.default_title, 'message':message}) for result in resp: - if (result.get('result') and result['result'] == 'OK'): + if result.get('result') and result['result'] == 'OK': log.debug('Message delivered successfully!') success = True break - elif (result.get('error')): + elif result.get('error'): log.error('XBMC error; %s: %s (%s)', (result['id'], result['error']['message'], result['error']['code'])) break - elif (result.get('result') and type(result['result']['version']).__name__ == 'dict'): + elif result.get('result') and type(result['result']['version']).__name__ == 'dict': # XBMC JSON-RPC v6 returns an array object containing # major, minor and patch number xbmc_rpc_version = str(result['result']['version']['major']) @@ -108,16 +108,16 @@ class XBMC(Notification): # send the text message resp = self.request(host, [('GUI.ShowNotification', {'title':self.default_title, 'message':message, 'image': self.getNotificationImage('small')})]) for result in resp: - if (result.get('result') and result['result'] == 'OK'): + if result.get('result') and result['result'] == 'OK': log.debug('Message delivered successfully!') success = True break - elif (result.get('error')): + elif result.get('error'): log.error('XBMC error; %s: %s (%s)', (result['id'], result['error']['message'], result['error']['code'])) break # error getting version info (we do have contact with XBMC though) - elif (result.get('error')): + elif result.get('error'): log.error('XBMC error; %s: %s (%s)', (result['id'], result['error']['message'], result['error']['code'])) log.debug('Use JSON notifications: %s ', self.use_json_notifications) diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index e60aaf4..92a7efa 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -26,11 +26,13 @@ log = CPLog(__name__) class Plugin(object): _class_name = None + plugin_path = None enabled_option = 'enabled' auto_register_static = True _needs_shutdown = False + _running = None user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20130519 Firefox/24.0' http_last_use = {} @@ -306,4 +308,4 @@ class Plugin(object): return not self.isEnabled() def isEnabled(self): - return self.conf(self.enabled_option) or self.conf(self.enabled_option) == None + return self.conf(self.enabled_option) or self.conf(self.enabled_option) is None diff --git a/couchpotato/core/plugins/browser/main.py b/couchpotato/core/plugins/browser/main.py index 6b989a0..380e682 100644 --- a/couchpotato/core/plugins/browser/main.py +++ b/couchpotato/core/plugins/browser/main.py @@ -12,7 +12,7 @@ if os.name == 'nt': except: # todo:: subclass ImportError for missing dependencies, vs. broken plugins? raise ImportError("Missing the win32file module, which is a part of the prerequisite \ - pywin32 package. You can get it from http://sourceforge.net/projects/pywin32/files/pywin32/"); + pywin32 package. You can get it from http://sourceforge.net/projects/pywin32/files/pywin32/") else: import win32file #@UnresolvedImport diff --git a/couchpotato/core/plugins/dashboard/main.py b/couchpotato/core/plugins/dashboard/main.py index df6f975..b02e5d9 100644 --- a/couchpotato/core/plugins/dashboard/main.py +++ b/couchpotato/core/plugins/dashboard/main.py @@ -93,7 +93,7 @@ class Dashboard(Plugin): }) # Don't list older movies - if ((not late and ((not eta.get('dvd') and not eta.get('theater')) or (eta.get('dvd') and eta.get('dvd') > (now - 2419200)))) or \ + if ((not late and (not eta.get('dvd') and not eta.get('theater') or eta.get('dvd') and eta.get('dvd') > (now - 2419200))) or (late and (eta.get('dvd', 0) > 0 or eta.get('theater')) and eta.get('dvd') < (now - 2419200))): movies.append(temp) diff --git a/couchpotato/core/plugins/log/main.py b/couchpotato/core/plugins/log/main.py index 18a78b9..dc8f740 100644 --- a/couchpotato/core/plugins/log/main.py +++ b/couchpotato/core/plugins/log/main.py @@ -90,7 +90,6 @@ class Logging(Plugin): if not os.path.isfile(path): break - reversed_lines = [] f = open(path, 'r') reversed_lines = toUnicode(f.read()).split('[0m\n') reversed_lines.reverse() diff --git a/couchpotato/core/plugins/manage/main.py b/couchpotato/core/plugins/manage/main.py index 516cb88..f1ffefa 100644 --- a/couchpotato/core/plugins/manage/main.py +++ b/couchpotato/core/plugins/manage/main.py @@ -184,7 +184,7 @@ class Manage(Plugin): fireEvent('release.add', group = group) fireEventAsync('library.update.movie', identifier = identifier, on_complete = self.createAfterUpdate(folder, identifier)) else: - self.in_progress[folder]['to_go'] = self.in_progress[folder]['to_go'] - 1 + self.in_progress[folder]['to_go'] -= 1 return addToLibrary @@ -195,7 +195,7 @@ class Manage(Plugin): if not self.in_progress or self.shuttingDown(): return - self.in_progress[folder]['to_go'] = self.in_progress[folder]['to_go'] - 1 + self.in_progress[folder]['to_go'] -= 1 total = self.in_progress[folder]['total'] movie_dict = fireEvent('movie.get', identifier, single = True) diff --git a/couchpotato/core/plugins/profile/main.py b/couchpotato/core/plugins/profile/main.py index c70d7c9..27963fb 100644 --- a/couchpotato/core/plugins/profile/main.py +++ b/couchpotato/core/plugins/profile/main.py @@ -155,7 +155,7 @@ class ProfilePlugin(Plugin): def fill(self): - db = get_session(); + db = get_session() profiles = [{ 'label': 'Best', diff --git a/couchpotato/core/plugins/quality/main.py b/couchpotato/core/plugins/quality/main.py index 67c7f00..0e67a07 100644 --- a/couchpotato/core/plugins/quality/main.py +++ b/couchpotato/core/plugins/quality/main.py @@ -102,7 +102,7 @@ class QualityPlugin(Plugin): def fill(self): - db = get_session(); + db = get_session() order = 0 for q in self.qualities: diff --git a/couchpotato/core/plugins/release/main.py b/couchpotato/core/plugins/release/main.py index 03b2bec..b2cc4e5 100644 --- a/couchpotato/core/plugins/release/main.py +++ b/couchpotato/core/plugins/release/main.py @@ -8,6 +8,7 @@ from couchpotato.core.plugins.scanner.main import Scanner from couchpotato.core.settings.model import File, Release as Relea, Movie from sqlalchemy.sql.expression import and_, or_ import os +import traceback log = CPLog(__name__) @@ -88,8 +89,8 @@ class Release(Plugin): added_files = db.query(File).filter(or_(*[File.id == x for x in added_files])).all() rel.files.extend(added_files) db.commit() - except Exception, e: - log.debug('Failed to attach "%s" to release: %s', (cur_file, e)) + except: + log.debug('Failed to attach "%s" to release: %s', (added_files, traceback.format_exc())) fireEvent('movie.restatus', movie.id) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 888e069..a45a265 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -9,8 +9,7 @@ from couchpotato.core.plugins.base import Plugin from couchpotato.core.settings.model import Library, File, Profile, Release, \ ReleaseInfo from couchpotato.environment import Env -from unrar2 import RarFile, RarInfo -from unrar2.rar_exceptions import * +from unrar2 import RarFile import errno import fnmatch import os @@ -62,10 +61,10 @@ class Renamer(Plugin): def scanView(self, **kwargs): - async = tryInt(kwargs.get('async', None)) - movie_folder = kwargs.get('movie_folder', None) - downloader = kwargs.get('downloader', None) - download_id = kwargs.get('download_id', None) + async = tryInt(kwargs.get('async', 0)) + movie_folder = kwargs.get('movie_folder') + downloader = kwargs.get('downloader') + download_id = kwargs.get('download_id') download_info = {'folder': movie_folder} if movie_folder else None if download_info: @@ -98,7 +97,7 @@ class Renamer(Plugin): elif self.conf('from') in self.conf('to'): log.error('The "to" can\'t be inside of the "from" folder. You\'ll get an infinite loop.') return - elif (movie_folder and movie_folder in [self.conf('to'), self.conf('from')]): + elif movie_folder and movie_folder in [self.conf('to'), self.conf('from')]: log.error('The "to" and "from" folders can\'t be inside of or the same as the provided movie folder.') return @@ -131,8 +130,8 @@ class Renamer(Plugin): # Unpack any archives extr_files = None if self.conf('unrar'): - folder, movie_folder, files, extr_files = self.extractFiles(folder = folder, movie_folder = movie_folder, files = files, \ - cleanup = self.conf('cleanup') and not self.downloadIsTorrent(download_info)) + folder, movie_folder, files, extr_files = self.extractFiles(folder = folder, movie_folder = movie_folder, files = files, + cleanup = self.conf('cleanup') and not self.downloadIsTorrent(download_info)) groups = fireEvent('scanner.scan', folder = folder if folder else self.conf('from'), files = files, download_info = download_info, return_ignored = False, single = True) @@ -347,7 +346,7 @@ class Renamer(Plugin): profile = db.query(Profile).filter_by(core = True, label = group['meta_data']['quality']['label']).first() fireEvent('movie.add', params = {'identifier': group['library']['identifier'], 'profile_id': profile.id}, search_after = False) db.expire_all() - library = db.query(Library).filter_by(identifier = group['library']['identifier']).first() + library_ent = db.query(Library).filter_by(identifier = group['library']['identifier']).first() for movie in library_ent.movies: @@ -517,7 +516,7 @@ class Renamer(Plugin): def tagDir(self, group, tag): ignore_file = None - if isinstance(group, (dict)): + if isinstance(group, dict): for movie_file in sorted(list(group['files']['movie'])): ignore_file = '%s.%s.ignore' % (os.path.splitext(movie_file)[0], tag) break @@ -603,9 +602,9 @@ Remove it if you want it to be renamed (again, or at least let it try again) return True def doReplace(self, string, replacements, remove_multiple = False): - ''' + """ replace confignames with the real thing - ''' + """ replacements = replacements.copy() if remove_multiple: @@ -873,7 +872,7 @@ Remove it if you want it to be renamed (again, or at least let it try again) #Extract all found archives for archive in archives: # Check if it has already been processed by CPS - if (self.hastagDir(os.path.dirname(archive['file']))): + if self.hastagDir(os.path.dirname(archive['file'])): continue # Find all related archive files @@ -970,4 +969,4 @@ Remove it if you want it to be renamed (again, or at least let it try again) files = [] folder = None - return (folder, movie_folder, files, extr_files) + return folder, movie_folder, files, extr_files diff --git a/couchpotato/core/plugins/scanner/main.py b/couchpotato/core/plugins/scanner/main.py index 553fa83..188924a 100644 --- a/couchpotato/core/plugins/scanner/main.py +++ b/couchpotato/core/plugins/scanner/main.py @@ -429,7 +429,7 @@ class Scanner(Plugin): if len(processed_movies) > 0: log.info('Found %s movies in the folder %s', (len(processed_movies), folder)) else: - log.debug('Found no movies in the folder %s', (folder)) + log.debug('Found no movies in the folder %s', folder) return processed_movies @@ -508,6 +508,7 @@ class Scanner(Plugin): detected_languages = {} # Subliminal scanner + paths = None try: paths = group['files']['movie'] scan_result = [] @@ -560,12 +561,14 @@ class Scanner(Plugin): break # Check and see if nfo contains the imdb-id + nfo_file = None if not imdb_id: try: - for nfo_file in files['nfo']: + for nf in files['nfo']: imdb_id = getImdb(nfo_file) if imdb_id: - log.debug('Found movie via nfo file: %s', nfo_file) + log.debug('Found movie via nfo file: %s', nf) + nfo_file = nf break except: pass @@ -585,11 +588,12 @@ class Scanner(Plugin): # Check if path is already in db if not imdb_id: db = get_session() - for cur_file in files['movie']: - f = db.query(File).filter_by(path = toUnicode(cur_file)).first() + for cf in files['movie']: + f = db.query(File).filter_by(path = toUnicode(cf)).first() try: imdb_id = f.library[0].identifier - log.debug('Found movie via database: %s', cur_file) + log.debug('Found movie via database: %s', cf) + cur_file = cf break except: pass @@ -680,10 +684,9 @@ class Scanner(Plugin): return getExt(s.lower()) in ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tbn'] files = set(filter(test, files)) - images = {} - - # Fanart - images['backdrop'] = set(filter(lambda s: re.search('(^|[\W_])fanart|backdrop\d*[\W_]', s.lower()) and self.filesizeBetween(s, 0, 5), files)) + images = { + 'backdrop': set(filter(lambda s: re.search('(^|[\W_])fanart|backdrop\d*[\W_]', s.lower()) and self.filesizeBetween(s, 0, 5), files)) + } # Rest images['rest'] = files - images['backdrop'] diff --git a/couchpotato/core/plugins/score/main.py b/couchpotato/core/plugins/score/main.py index cc87c9a..5f9da1a 100644 --- a/couchpotato/core/plugins/score/main.py +++ b/couchpotato/core/plugins/score/main.py @@ -17,7 +17,7 @@ class Score(Plugin): addEvent('score.calculate', self.calculate) def calculate(self, nzb, movie): - ''' Calculate the score of a NZB, used for sorting later ''' + """ Calculate the score of a NZB, used for sorting later """ # Merge global and category preferred_words = splitString(Env.setting('preferred_words', section = 'searcher').lower()) diff --git a/couchpotato/core/plugins/score/scores.py b/couchpotato/core/plugins/score/scores.py index a95b0a4..6aa0b46 100644 --- a/couchpotato/core/plugins/score/scores.py +++ b/couchpotato/core/plugins/score/scores.py @@ -1,6 +1,6 @@ from couchpotato.core.event import fireEvent from couchpotato.core.helpers.encoding import simplifyString -from couchpotato.core.helpers.variable import tryInt, splitString +from couchpotato.core.helpers.variable import tryInt from couchpotato.environment import Env import re @@ -24,7 +24,7 @@ name_scores = [ def nameScore(name, year, preferred_words): - ''' Calculate score for words in the NZB name ''' + """ Calculate score for words in the NZB name """ score = 0 name = name.lower() @@ -34,11 +34,11 @@ def nameScore(name, year, preferred_words): v = value.split(':') add = int(v.pop()) if v.pop() in name: - score = score + add + score += add # points if the year is correct if str(year) in name: - score = score + 5 + score += 5 # Contains preferred word nzb_words = re.split('\W+', simplifyString(name)) diff --git a/couchpotato/core/plugins/status/main.py b/couchpotato/core/plugins/status/main.py index 8db2bf7..7546c65 100644 --- a/couchpotato/core/plugins/status/main.py +++ b/couchpotato/core/plugins/status/main.py @@ -75,7 +75,7 @@ class StatusPlugin(Plugin): def get(self, identifiers): - if not isinstance(identifiers, (list)): + if not isinstance(identifiers, list): identifiers = [identifiers] db = get_session() diff --git a/couchpotato/core/plugins/subtitle/main.py b/couchpotato/core/plugins/subtitle/main.py index ea836f0..2aa22f4 100644 --- a/couchpotato/core/plugins/subtitle/main.py +++ b/couchpotato/core/plugins/subtitle/main.py @@ -36,7 +36,7 @@ class Subtitle(Plugin): files = [] for file in release.files.filter(FileType.status.has(identifier = 'movie')).all(): - files.append(file.path); + files.append(file.path) # get subtitles for those files subliminal.list_subtitles(files, cache_dir = Env.get('cache_dir'), multi = True, languages = self.getLanguages(), services = self.services) diff --git a/couchpotato/core/plugins/suggestion/main.py b/couchpotato/core/plugins/suggestion/main.py index 0e7d701..a7b640e 100644 --- a/couchpotato/core/plugins/suggestion/main.py +++ b/couchpotato/core/plugins/suggestion/main.py @@ -47,6 +47,7 @@ class Suggestion(Plugin): ignored = splitString(Env.prop('suggest_ignore', default = '')) + new_suggestions = [] if imdb: if not remove_only: ignored.append(imdb) diff --git a/couchpotato/core/providers/automation/imdb/main.py b/couchpotato/core/providers/automation/imdb/main.py index c4aef7f..e9d14b5 100644 --- a/couchpotato/core/providers/automation/imdb/main.py +++ b/couchpotato/core/providers/automation/imdb/main.py @@ -58,7 +58,7 @@ class IMDBWatchlist(IMDBBase): break except: - log.error('Failed loading IMDB watchlist: %s %s', (url, traceback.format_exc())) + log.error('Failed loading IMDB watchlist: %s %s', (watchlist_url, traceback.format_exc())) return movies diff --git a/couchpotato/core/providers/info/omdbapi/main.py b/couchpotato/core/providers/info/omdbapi/main.py index 2726ef5..87bb0a7 100755 --- a/couchpotato/core/providers/info/omdbapi/main.py +++ b/couchpotato/core/providers/info/omdbapi/main.py @@ -98,7 +98,7 @@ class OMDBAPI(MovieProvider): 'mpaa': str(movie.get('Rated', '')), 'runtime': self.runtimeToMinutes(movie.get('Runtime', '')), 'released': movie.get('Released'), - 'year': year if isinstance(year, (int)) else None, + 'year': year if isinstance(year, int) else None, 'plot': movie.get('Plot'), 'genres': splitString(movie.get('Genre', '')), 'directors': splitString(movie.get('Director', '')), diff --git a/couchpotato/core/providers/info/themoviedb/main.py b/couchpotato/core/providers/info/themoviedb/main.py index 561cdc7..2ec0e94 100644 --- a/couchpotato/core/providers/info/themoviedb/main.py +++ b/couchpotato/core/providers/info/themoviedb/main.py @@ -23,7 +23,7 @@ class TheMovieDb(MovieProvider): tmdb3.set_cache(engine='file', filename=os.path.join(Env.get('cache_dir'), 'python', 'tmdb.cache')) def search(self, q, limit = 12): - ''' Find movie by name ''' + """ Find movie by name """ if self.isDisabled(): return False @@ -72,9 +72,6 @@ class TheMovieDb(MovieProvider): result = self.getCache(cache_key) if not result: - result = {} - movie = None - try: log.debug('Getting info: %s', cache_key) movie = tmdb3.Movie(identifier) @@ -129,7 +126,7 @@ class TheMovieDb(MovieProvider): movie_data['titles'].append(movie.originaltitle) for alt in movie.alternate_titles: alt_name = alt.title - if alt_name and not alt_name in movie_data['titles'] and alt_name.lower() != 'none' and alt_name != None: + if alt_name and not alt_name in movie_data['titles'] and alt_name.lower() != 'none' and alt_name is not None: movie_data['titles'].append(alt_name) movie_data['titles'] = list(set(movie_data['titles'])) @@ -149,6 +146,5 @@ class TheMovieDb(MovieProvider): def isDisabled(self): if self.conf('api_key') == '': log.error('No API key provided.') - True - else: - False + return True + return False diff --git a/couchpotato/core/providers/metadata/base.py b/couchpotato/core/providers/metadata/base.py index 8cd1a1c..7a65568 100644 --- a/couchpotato/core/providers/metadata/base.py +++ b/couchpotato/core/providers/metadata/base.py @@ -82,8 +82,11 @@ class MetaDataBase(Plugin): def getThumbnail(self, movie_info = {}, data = {}, wanted_file_type = 'poster_original'): file_types = fireEvent('file.types', single = True) - for file_type in file_types: - if file_type.get('identifier') == wanted_file_type: + file_type = {} + + for ft in file_types: + if ft.get('identifier') == wanted_file_type: + file_type = ft break # See if it is in current files diff --git a/couchpotato/core/providers/nzb/binsearch/main.py b/couchpotato/core/providers/nzb/binsearch/main.py index 1d86300..dee5fc7 100644 --- a/couchpotato/core/providers/nzb/binsearch/main.py +++ b/couchpotato/core/providers/nzb/binsearch/main.py @@ -86,8 +86,10 @@ class BinSearch(NZBProvider): def download(self, url = '', nzb_id = ''): - params = {'action': 'nzb'} - params[nzb_id] = 'on' + params = { + 'action': 'nzb', + nzb_id: 'on' + } try: return self.urlopen(url, params = params, show_error = False) diff --git a/couchpotato/core/providers/nzb/newznab/main.py b/couchpotato/core/providers/nzb/newznab/main.py index 8eb3e84..02ffcfd 100644 --- a/couchpotato/core/providers/nzb/newznab/main.py +++ b/couchpotato/core/providers/nzb/newznab/main.py @@ -118,7 +118,7 @@ class Newznab(NZBProvider, RSS): return list - def belongsTo(self, url, provider = None): + def belongsTo(self, url, provider = None, host = None): hosts = self.getHosts() diff --git a/couchpotato/core/providers/torrent/scenehd/main.py b/couchpotato/core/providers/torrent/scenehd/main.py index f471ec0..2b76e43 100644 --- a/couchpotato/core/providers/torrent/scenehd/main.py +++ b/couchpotato/core/providers/torrent/scenehd/main.py @@ -65,7 +65,7 @@ class SceneHD(TorrentProvider): log.error('Failed getting results from %s: %s', (self.getName(), traceback.format_exc())) - def getLoginParams(self, params): + def getLoginParams(self): return tryUrlencode({ 'username': self.conf('username'), 'password': self.conf('password'), diff --git a/couchpotato/core/providers/torrent/thepiratebay/main.py b/couchpotato/core/providers/torrent/thepiratebay/main.py index 82cbbe9..6aa2216 100644 --- a/couchpotato/core/providers/torrent/thepiratebay/main.py +++ b/couchpotato/core/providers/torrent/thepiratebay/main.py @@ -86,10 +86,10 @@ class ThePirateBay(TorrentMagnetProvider): if link and download: def extra_score(item): - trusted = (0, 10)[result.find('img', alt = re.compile('Trusted')) != None] - vip = (0, 20)[result.find('img', alt = re.compile('VIP')) != None] - confirmed = (0, 30)[result.find('img', alt = re.compile('Helpers')) != None] - moderated = (0, 50)[result.find('img', alt = re.compile('Moderator')) != None] + trusted = (0, 10)[result.find('img', alt = re.compile('Trusted')) is not None] + vip = (0, 20)[result.find('img', alt = re.compile('VIP')) is not None] + confirmed = (0, 30)[result.find('img', alt = re.compile('Helpers')) is not None] + moderated = (0, 50)[result.find('img', alt = re.compile('Moderator')) is not None] return confirmed + trusted + vip + moderated diff --git a/couchpotato/core/providers/userscript/allocine/main.py b/couchpotato/core/providers/userscript/allocine/main.py index 8cc889e..f8ca630 100644 --- a/couchpotato/core/providers/userscript/allocine/main.py +++ b/couchpotato/core/providers/userscript/allocine/main.py @@ -19,9 +19,6 @@ class AlloCine(UserscriptBase): except: return - name = None - year = None - try: start = data.find('') end = data.find('', start) diff --git a/couchpotato/core/settings/__init__.py b/couchpotato/core/settings/__init__.py index e08adb8..b75e5dd 100644 --- a/couchpotato/core/settings/__init__.py +++ b/couchpotato/core/settings/__init__.py @@ -1,13 +1,10 @@ from __future__ import with_statement from couchpotato.api import addApiView from couchpotato.core.event import addEvent, fireEvent -from couchpotato.core.helpers.encoding import isInt, toUnicode +from couchpotato.core.helpers.encoding import toUnicode from couchpotato.core.helpers.variable import mergeDicts, tryInt, tryFloat from couchpotato.core.settings.model import Properties import ConfigParser -import os.path -import time -import traceback class Settings(object): @@ -92,7 +89,7 @@ class Settings(object): self.setType(section_name, option_name, option.get('type')) if save: - self.save(self) + self.save() def set(self, section, option, value): return self.p.set(section, option, value) diff --git a/couchpotato/environment.py b/couchpotato/environment.py index ac0f729..0f04d83 100644 --- a/couchpotato/environment.py +++ b/couchpotato/environment.py @@ -74,7 +74,7 @@ class Env(object): s = Env.get('settings') # Return setting - if value == None: + if value is None: return s.get(attr, default = default, section = section, type = type) # Set setting @@ -86,7 +86,7 @@ class Env(object): @staticmethod def prop(identifier, value = None, default = None): s = Env.get('settings') - if value == None: + if value is None: v = s.getProperty(identifier) return v if v else default diff --git a/couchpotato/runner.py b/couchpotato/runner.py index 715eab5..ab92919 100644 --- a/couchpotato/runner.py +++ b/couchpotato/runner.py @@ -112,7 +112,7 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En try: if os.path.isfile(file_path): os.remove(file_path) - except Exception, e: + except: raise os.rmdir(backup) @@ -257,7 +257,7 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En application.add_handlers(".*$", [ ('%s%s/(.*)' % (static_path, dir_name), StaticFileHandler, {'path': toUnicode(os.path.join(base_path, 'couchpotato', 'static', dir_name))}) ]) - Env.set('static_path', static_path); + Env.set('static_path', static_path) # Load configs & plugins