From 7788669de179037e0a02873dcf159c96b4cfde0c Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 11 Jun 2014 09:31:29 +0200 Subject: [PATCH 1/5] Fill in profiles & qualities when they are empty. fix #3396 --- couchpotato/core/plugins/profile/main.py | 11 +++++- couchpotato/core/plugins/quality/main.py | 43 ++++++++++++++---------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/couchpotato/core/plugins/profile/main.py b/couchpotato/core/plugins/profile/main.py index 8dc59336..10987198 100644 --- a/couchpotato/core/plugins/profile/main.py +++ b/couchpotato/core/plugins/profile/main.py @@ -38,9 +38,18 @@ class ProfilePlugin(Plugin): def forceDefaults(self): + db = get_db() + + # Fill qualities and profiles if they are empty somehow.. + if db.count(db.all, 'profile') == 0: + + if db.count(db.all, 'quality') == 0: + fireEvent('quality.fill', single = True) + + self.fill() + # Get all active movies without profile try: - db = get_db() medias = fireEvent('media.with_status', 'active', single = True) profile_ids = [x.get('_id') for x in self.all()] diff --git a/couchpotato/core/plugins/quality/main.py b/couchpotato/core/plugins/quality/main.py index 7bb33791..63049243 100644 --- a/couchpotato/core/plugins/quality/main.py +++ b/couchpotato/core/plugins/quality/main.py @@ -1,5 +1,6 @@ import traceback import re +from CodernityDB.database import RecordNotFound from couchpotato import get_db from couchpotato.api import addApiView @@ -51,6 +52,7 @@ class QualityPlugin(Plugin): addEvent('quality.order', self.getOrder) addEvent('quality.ishigher', self.isHigher) addEvent('quality.isfinish', self.isFinish) + addEvent('quality.fill', self.fill) addApiView('quality.size.save', self.saveSize) addApiView('quality.list', self.allView, docs = { @@ -152,24 +154,31 @@ class QualityPlugin(Plugin): order = 0 for q in self.qualities: - db.insert({ - '_t': 'quality', - 'order': order, - 'identifier': q.get('identifier'), - 'size_min': tryInt(q.get('size')[0]), - 'size_max': tryInt(q.get('size')[1]), - }) + existing = None + try: + existing = db.get('quality', q.get('identifier')) + except RecordNotFound: + pass - log.info('Creating profile: %s', q.get('label')) - db.insert({ - '_t': 'profile', - 'order': order + 20, # Make sure it goes behind other profiles - 'core': True, - 'qualities': [q.get('identifier')], - 'label': toUnicode(q.get('label')), - 'finish': [True], - 'wait_for': [0], - }) + if not existing: + db.insert({ + '_t': 'quality', + 'order': order, + 'identifier': q.get('identifier'), + 'size_min': tryInt(q.get('size')[0]), + 'size_max': tryInt(q.get('size')[1]), + }) + + log.info('Creating profile: %s', q.get('label')) + db.insert({ + '_t': 'profile', + 'order': order + 20, # Make sure it goes behind other profiles + 'core': True, + 'qualities': [q.get('identifier')], + 'label': toUnicode(q.get('label')), + 'finish': [True], + 'wait_for': [0], + }) order += 1 From 7950c4bdb403f3daa9c732cffa91e55570584f10 Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 11 Jun 2014 09:34:06 +0200 Subject: [PATCH 2/5] Update fedora service init --- init/couchpotato.fedora.service | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/init/couchpotato.fedora.service b/init/couchpotato.fedora.service index 7df166bc..d3b52ba5 100644 --- a/init/couchpotato.fedora.service +++ b/init/couchpotato.fedora.service @@ -1,12 +1,13 @@ [Unit] Description=CouchPotato application instance +After=network.target [Service] -ExecStart=/usr/lib/CouchPotatoServer/CouchPotato.py --daemon +ExecStart=/var/lib/CouchPotatoServer/CouchPotato.py --daemon GuessMainPID=no Type=forking User=couchpotato Group=couchpotato [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target From 2898a066feaa3bea8c50aeb8b9fed13ddf88b7e9 Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 11 Jun 2014 09:49:30 +0200 Subject: [PATCH 3/5] Prevent threading from GC before proper close. fix #3420 --- libs/axl/axel.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/axl/axel.py b/libs/axl/axel.py index d0f069ab..64d29779 100644 --- a/libs/axl/axel.py +++ b/libs/axl/axel.py @@ -1,6 +1,7 @@ # axel.py # # Copyright (C) 2010 Adrian Cristea adrian dot cristea at gmail dotcom +# Edits by Ruud Burger # # Based on an idea by Peter Thatcher, found on # http://www.valuedlessons.com/2008/04/events-in-python.html @@ -11,12 +12,14 @@ # Source: http://pypi.python.org/pypi/axel # Docs: http://packages.python.org/axel -from couchpotato.core.helpers.variable import natsortKey -import Queue +from Queue import Empty, Queue import hashlib import sys import threading +from couchpotato.core.helpers.variable import natsortKey + + class Event(object): """ Event object inspired by C# events. Handlers can be registered and @@ -140,7 +143,7 @@ class Event(object): def fire(self, *args, **kwargs): """ Stores all registered handlers in a queue for processing """ - self.queue = Queue.Queue() + self.queue = Queue() result = {} if self.handlers: @@ -239,9 +242,9 @@ class Event(object): order_lock.release() if self.queue.empty(): - raise Queue.Empty + raise Empty - except Queue.Empty: + except Empty: break def _extract(self, queue_item): From ef407bcb3c5ade146fbc8e797bab74c8755866af Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 11 Jun 2014 09:53:52 +0200 Subject: [PATCH 4/5] Don't clear pyc when develop --- couchpotato/core/_base/updater/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/couchpotato/core/_base/updater/main.py b/couchpotato/core/_base/updater/main.py index 8164dc59..5a47fc06 100644 --- a/couchpotato/core/_base/updater/main.py +++ b/couchpotato/core/_base/updater/main.py @@ -142,7 +142,9 @@ class Updater(Plugin): } def doShutdown(self): - self.updater.deletePyc(show_logs = False) + if not Env.get('dev'): + self.updater.deletePyc(show_logs = False) + return super(Updater, self).doShutdown() From ba9c975335c9b470d74d6ba87de63b9f885bf5f6 Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 11 Jun 2014 10:11:36 +0200 Subject: [PATCH 5/5] Allow empty quality --- couchpotato/core/plugins/quality/static/quality.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/couchpotato/core/plugins/quality/static/quality.js b/couchpotato/core/plugins/quality/static/quality.js index 601438d3..29324c22 100644 --- a/couchpotato/core/plugins/quality/static/quality.js +++ b/couchpotato/core/plugins/quality/static/quality.js @@ -29,9 +29,14 @@ var QualityBase = new Class({ }, getQuality: function(identifier){ - return this.qualities.filter(function(q){ - return q.identifier == identifier; - }).pick(); + try { + return this.qualities.filter(function(q){ + return q.identifier == identifier; + }).pick(); + } + catch(e){} + + return {} }, addSettings: function(){ @@ -104,7 +109,7 @@ var QualityBase = new Class({ var profile_list; self.settings.createGroup({ 'label': 'Profile Defaults', - 'description': '(Needs refresh \'' +(App.isMac() ? 'CMD+R' : 'F5')+ '\' after editing)' + 'description': '(Needs refresh \'' +(App.isMac() ? 'CMD+R' : 'F5')+ '\' after editing)' }).adopt( new Element('.ctrlHolder#profile_ordering').adopt( new Element('label[text=Order]'),