Use proper sorting
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from axl.axel import Event
|
||||
from couchpotato.core.helpers.variable import mergeDicts, natcmp
|
||||
from couchpotato.core.helpers.variable import mergeDicts, natsortKey
|
||||
from couchpotato.core.logger import CPLog
|
||||
import threading
|
||||
import traceback
|
||||
@@ -51,11 +51,6 @@ def addEvent(name, handler, priority = 100):
|
||||
})
|
||||
|
||||
|
||||
def removeEvent(name, handler):
|
||||
e = events[name]
|
||||
e -= handler
|
||||
|
||||
|
||||
def fireEvent(name, *args, **kwargs):
|
||||
if name not in events: return
|
||||
|
||||
@@ -106,7 +101,7 @@ def fireEvent(name, *args, **kwargs):
|
||||
result = e(*args, **kwargs)
|
||||
|
||||
result_keys = result.keys()
|
||||
result_keys.sort(natcmp)
|
||||
result_keys.sort(key = natsortKey)
|
||||
|
||||
if options['single'] and not options['merge']:
|
||||
results = None
|
||||
|
||||
@@ -214,16 +214,9 @@ def tryFloat(s):
|
||||
return float(s)
|
||||
except: return 0
|
||||
|
||||
|
||||
def natsortKey(s):
|
||||
return map(tryInt, re.findall(r'(\d+|\D+)', s))
|
||||
|
||||
|
||||
def natcmp(a, b):
|
||||
a2 = natsortKey(a)
|
||||
b2 = natsortKey(b)
|
||||
|
||||
return (a2 > b2) - (a2 < b2)
|
||||
def natsortKey(string_):
|
||||
"""See http://www.codinghorror.com/blog/archives/001018.html"""
|
||||
return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', string_)]
|
||||
|
||||
|
||||
def toIterable(value):
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# Source: http://pypi.python.org/pypi/axel
|
||||
# Docs: http://packages.python.org/axel
|
||||
|
||||
from couchpotato.core.helpers.variable import natcmp
|
||||
from couchpotato.core.helpers.variable import natsortKey
|
||||
import Queue
|
||||
import hashlib
|
||||
import sys
|
||||
@@ -158,7 +158,10 @@ class Event(object):
|
||||
t.daemon = True
|
||||
t.start()
|
||||
|
||||
for handler in sorted(self.handlers.iterkeys(), cmp = natcmp):
|
||||
handler_keys = self.handlers.keys()
|
||||
handler_keys.sort(key = natsortKey)
|
||||
|
||||
for handler in handler_keys:
|
||||
self.queue.put(handler)
|
||||
|
||||
if self.asynchronous:
|
||||
|
||||
Reference in New Issue
Block a user