Enable both nzb and torrent by default
Use default user download dir and enable blackhole
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from .main import Blackhole
|
from .main import Blackhole
|
||||||
|
from couchpotato.core.helpers.variable import getDownloadDir
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
return Blackhole()
|
return Blackhole()
|
||||||
@@ -16,7 +17,7 @@ config = [{
|
|||||||
'options': [
|
'options': [
|
||||||
{
|
{
|
||||||
'name': 'enabled',
|
'name': 'enabled',
|
||||||
'default': 0,
|
'default': True,
|
||||||
'type': 'enabler',
|
'type': 'enabler',
|
||||||
'radio_group': 'nzb,torrent',
|
'radio_group': 'nzb,torrent',
|
||||||
},
|
},
|
||||||
@@ -24,6 +25,7 @@ config = [{
|
|||||||
'name': 'directory',
|
'name': 'directory',
|
||||||
'type': 'directory',
|
'type': 'directory',
|
||||||
'description': 'Directory where the .nzb (or .torrent) file is saved to.',
|
'description': 'Directory where the .nzb (or .torrent) file is saved to.',
|
||||||
|
'default': getDownloadDir()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'use_for',
|
'name': 'use_for',
|
||||||
|
|||||||
@@ -63,11 +63,21 @@ def fireEvent(name, *args, **kwargs):
|
|||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
e = events[name]
|
e = events[name]
|
||||||
if not options['in_order']: e.lock.acquire()
|
|
||||||
|
# Lock this event
|
||||||
|
e.lock.acquire()
|
||||||
|
|
||||||
e.asynchronous = False
|
e.asynchronous = False
|
||||||
e.in_order = options['in_order']
|
|
||||||
|
# Make sure only 1 event is fired at a time when order is wanted
|
||||||
|
kwargs['event_order_lock'] = threading.RLock() if options['in_order'] or options['single'] else None
|
||||||
|
kwargs['event_return_on_result'] = options['single']
|
||||||
|
|
||||||
|
# Fire
|
||||||
result = e(*args, **kwargs)
|
result = e(*args, **kwargs)
|
||||||
if not options['in_order']: e.lock.release()
|
|
||||||
|
# Release lock for this event
|
||||||
|
e.lock.release()
|
||||||
|
|
||||||
if options['single'] and not options['merge']:
|
if options['single'] and not options['merge']:
|
||||||
results = None
|
results = None
|
||||||
|
|||||||
@@ -9,15 +9,34 @@ import sys
|
|||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
|
def getUserDir():
|
||||||
|
try:
|
||||||
|
import pwd
|
||||||
|
os.environ['HOME'] = pwd.getpwuid(os.geteuid()).pw_dir
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return os.path.expanduser('~')
|
||||||
|
|
||||||
|
def getDownloadDir():
|
||||||
|
user_dir = getUserDir()
|
||||||
|
|
||||||
|
# OSX
|
||||||
|
if 'darwin' in platform.platform().lower():
|
||||||
|
return os.path.join(user_dir, 'Downloads')
|
||||||
|
|
||||||
|
if os.name == 'nt':
|
||||||
|
return os.path.join(user_dir, 'Downloads')
|
||||||
|
|
||||||
|
return user_dir
|
||||||
|
|
||||||
def getDataDir():
|
def getDataDir():
|
||||||
|
|
||||||
# Windows
|
# Windows
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
return os.path.join(os.environ['APPDATA'], 'CouchPotato')
|
return os.path.join(os.environ['APPDATA'], 'CouchPotato')
|
||||||
|
|
||||||
import pwd
|
user_dir = getUserDir()
|
||||||
os.environ['HOME'] = pwd.getpwuid(os.geteuid()).pw_dir
|
|
||||||
user_dir = os.path.expanduser('~')
|
|
||||||
|
|
||||||
# OSX
|
# OSX
|
||||||
if 'darwin' in platform.platform().lower():
|
if 'darwin' in platform.platform().lower():
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ class CPLog(object):
|
|||||||
def info(self, msg, replace_tuple = ()):
|
def info(self, msg, replace_tuple = ()):
|
||||||
self.logger.info(self.addContext(msg, replace_tuple))
|
self.logger.info(self.addContext(msg, replace_tuple))
|
||||||
|
|
||||||
|
def info2(self, msg, replace_tuple = ()):
|
||||||
|
self.logger.log(19, self.addContext(msg, replace_tuple))
|
||||||
|
|
||||||
def debug(self, msg, replace_tuple = ()):
|
def debug(self, msg, replace_tuple = ()):
|
||||||
self.logger.debug(self.addContext(msg, replace_tuple))
|
self.logger.debug(self.addContext(msg, replace_tuple))
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from couchpotato.api import addApiView
|
from couchpotato.api import addApiView
|
||||||
from couchpotato.core.helpers.request import getParam, jsonified
|
from couchpotato.core.helpers.request import getParam, jsonified
|
||||||
|
from couchpotato.core.helpers.variable import getUserDir
|
||||||
from couchpotato.core.plugins.base import Plugin
|
from couchpotato.core.plugins.base import Plugin
|
||||||
import ctypes
|
import ctypes
|
||||||
import os
|
import os
|
||||||
@@ -65,15 +66,7 @@ class FileBrowser(Plugin):
|
|||||||
def view(self):
|
def view(self):
|
||||||
|
|
||||||
path = getParam('path', '/')
|
path = getParam('path', '/')
|
||||||
|
home = getUserDir()
|
||||||
# Set proper home dir for some systems
|
|
||||||
try:
|
|
||||||
import pwd
|
|
||||||
os.environ['HOME'] = pwd.getpwuid(os.geteuid()).pw_dir
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
home = os.path.expanduser('~')
|
|
||||||
|
|
||||||
if not path:
|
if not path:
|
||||||
path = home
|
path = home
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ Page.Wizard = new Class({
|
|||||||
},
|
},
|
||||||
'downloaders': {
|
'downloaders': {
|
||||||
'title': 'What download apps are you using?',
|
'title': 'What download apps are you using?',
|
||||||
'description': 'CP needs an external download app to work with. Choose one below. For more downloaders check settings after you have filled in the wizard. If your download app isn\'t in the list, use Blackhole.'
|
'description': 'CP needs an external download app to work with. Choose one below. For more downloaders check settings after you have filled in the wizard. If your download app isn\'t in the list, use the default Blackhole.'
|
||||||
},
|
},
|
||||||
'providers': {
|
'providers': {
|
||||||
'title': 'Are you registered at any of these sites?',
|
'title': 'Are you registered at any of these sites?',
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ config = [{
|
|||||||
{
|
{
|
||||||
'name': 'enabled',
|
'name': 'enabled',
|
||||||
'type': 'enabler',
|
'type': 'enabler',
|
||||||
'default': False,
|
'default': True,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ config = [{
|
|||||||
{
|
{
|
||||||
'name': 'enabled',
|
'name': 'enabled',
|
||||||
'type': 'enabler',
|
'type': 'enabler',
|
||||||
|
'default': True,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ config = [{
|
|||||||
{
|
{
|
||||||
'name': 'enabled',
|
'name': 'enabled',
|
||||||
'type': 'enabler',
|
'type': 'enabler',
|
||||||
'default': False,
|
'default': True,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ class KickAssTorrents(TorrentProvider):
|
|||||||
is_correct_movie = fireEvent('searcher.correct_movie',
|
is_correct_movie = fireEvent('searcher.correct_movie',
|
||||||
nzb = new, movie = movie, quality = quality,
|
nzb = new, movie = movie, quality = quality,
|
||||||
imdb_results = True, single = True)
|
imdb_results = True, single = True)
|
||||||
|
|
||||||
if is_correct_movie:
|
if is_correct_movie:
|
||||||
results.append(new)
|
results.append(new)
|
||||||
self.found(new)
|
self.found(new)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ config = [{
|
|||||||
{
|
{
|
||||||
'name': 'enabled',
|
'name': 'enabled',
|
||||||
'type': 'enabler',
|
'type': 'enabler',
|
||||||
'default': False,
|
'default': True,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ config = [{
|
|||||||
{
|
{
|
||||||
'name': 'enabled',
|
'name': 'enabled',
|
||||||
'type': 'enabler',
|
'type': 'enabler',
|
||||||
'default': False
|
'default': True
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'domain',
|
'name': 'domain',
|
||||||
|
|||||||
+41
-19
@@ -95,7 +95,6 @@ class Event(object):
|
|||||||
(None, None, handler), ... # asynchronous execution
|
(None, None, handler), ... # asynchronous execution
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
self.in_order = False
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self.asynchronous = asynch
|
self.asynchronous = asynch
|
||||||
self.exc_info = exc_info
|
self.exc_info = exc_info
|
||||||
@@ -142,11 +141,16 @@ class Event(object):
|
|||||||
def fire(self, *args, **kwargs):
|
def fire(self, *args, **kwargs):
|
||||||
""" Stores all registered handlers in a queue for processing """
|
""" Stores all registered handlers in a queue for processing """
|
||||||
self.queue = Queue.Queue()
|
self.queue = Queue.Queue()
|
||||||
self.result = {}
|
result = {}
|
||||||
|
|
||||||
if self.handlers:
|
if self.handlers:
|
||||||
|
|
||||||
max_threads = self._threads()
|
max_threads = 1 if kwargs.get('event_order_lock') else self._threads()
|
||||||
|
|
||||||
|
# Set global result
|
||||||
|
def add_to(key, value):
|
||||||
|
result[key] = value
|
||||||
|
kwargs['event_add_to_result'] = add_to
|
||||||
|
|
||||||
for i in range(max_threads):
|
for i in range(max_threads):
|
||||||
t = threading.Thread(target = self._execute,
|
t = threading.Thread(target = self._execute,
|
||||||
@@ -159,17 +163,12 @@ class Event(object):
|
|||||||
|
|
||||||
if self.asynchronous:
|
if self.asynchronous:
|
||||||
handler_, memoize, timeout = self.handlers[handler]
|
handler_, memoize, timeout = self.handlers[handler]
|
||||||
self.result[handler] = (None, None, handler_)
|
result[handler] = (None, None, handler_)
|
||||||
|
|
||||||
if not self.asynchronous:
|
if not self.asynchronous:
|
||||||
self.queue.join()
|
self.queue.join()
|
||||||
|
|
||||||
res = self.result or None
|
return result
|
||||||
|
|
||||||
# Cleanup
|
|
||||||
self.result = {}
|
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
def count(self):
|
def count(self):
|
||||||
""" Returns the count of registered handlers """
|
""" Returns the count of registered handlers """
|
||||||
@@ -181,24 +180,47 @@ class Event(object):
|
|||||||
self.memoize.clear()
|
self.memoize.clear()
|
||||||
|
|
||||||
def _execute(self, *args, **kwargs):
|
def _execute(self, *args, **kwargs):
|
||||||
|
|
||||||
|
# Remove get and set from kwargs
|
||||||
|
add_to_result = kwargs.get('event_add_to_result')
|
||||||
|
del kwargs['event_add_to_result']
|
||||||
|
|
||||||
|
# Get and remove order lock
|
||||||
|
order_lock = kwargs.get('event_order_lock')
|
||||||
|
try: del kwargs['event_order_lock']
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
# Get and remove return on first
|
||||||
|
return_on_result = kwargs.get('event_return_on_result')
|
||||||
|
try: del kwargs['event_return_on_result']
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
got_results = False
|
||||||
|
|
||||||
""" Executes all handlers stored in the queue """
|
""" Executes all handlers stored in the queue """
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
h_ = self.queue.get(timeout = 2)
|
h_ = self.queue.get(timeout = 2)
|
||||||
handler, memoize, timeout = self.handlers[h_]
|
handler, memoize, timeout = self.handlers[h_]
|
||||||
|
|
||||||
if self.lock and self.in_order:
|
if return_on_result and got_results:
|
||||||
self.lock.acquire()
|
continue
|
||||||
|
|
||||||
|
if order_lock:
|
||||||
|
order_lock.acquire()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = self._memoize(memoize, timeout, handler, *args, **kwargs)
|
r = self._memoize(memoize, timeout, handler, *args, **kwargs)
|
||||||
if not self.asynchronous:
|
if not self.asynchronous:
|
||||||
self.result[h_] = tuple(r)
|
if not return_on_result or (return_on_result and r[1]):
|
||||||
|
add_to_result(h_, tuple(r))
|
||||||
|
got_results = True
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
if not self.asynchronous:
|
if not self.asynchronous:
|
||||||
self.result[h_] = (False, self._error(sys.exc_info()),
|
add_to_result(h_, (False, self._error(sys.exc_info()),
|
||||||
handler)
|
handler))
|
||||||
else:
|
else:
|
||||||
self.error_handler(sys.exc_info())
|
self.error_handler(sys.exc_info())
|
||||||
finally:
|
finally:
|
||||||
@@ -206,8 +228,8 @@ class Event(object):
|
|||||||
if not self.asynchronous:
|
if not self.asynchronous:
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
|
|
||||||
if self.lock and self.in_order:
|
if order_lock:
|
||||||
self.lock.release()
|
order_lock.release()
|
||||||
|
|
||||||
if self.queue.empty():
|
if self.queue.empty():
|
||||||
raise Queue.Empty
|
raise Queue.Empty
|
||||||
@@ -257,7 +279,7 @@ class Event(object):
|
|||||||
args.insert(0, self.sender)
|
args.insert(0, self.sender)
|
||||||
|
|
||||||
if not memoize:
|
if not memoize:
|
||||||
if timeout <= 0: #no time restriction
|
if timeout <= 0: #no time restriction
|
||||||
result = [True, handler(*args, **kwargs), handler]
|
result = [True, handler(*args, **kwargs), handler]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -273,7 +295,7 @@ class Event(object):
|
|||||||
if args_ == args and kwargs_ == kwargs:
|
if args_ == args and kwargs_ == kwargs:
|
||||||
return [True, result, handler]
|
return [True, result, handler]
|
||||||
|
|
||||||
if timeout <= 0: #no time restriction
|
if timeout <= 0: #no time restriction
|
||||||
result = handler(*args, **kwargs)
|
result = handler(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
result = self._timeout(timeout, handler, *args, **kwargs)
|
result = self._timeout(timeout, handler, *args, **kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user