mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
"Impove" sort order of implicit spine items.
This commit is contained in:
parent
b9771763d0
commit
3e9401d2d2
@ -14,6 +14,7 @@ from itertools import izip, count
|
|||||||
from urlparse import urldefrag, urlparse, urlunparse
|
from urlparse import urldefrag, urlparse, urlunparse
|
||||||
from urllib import unquote as urlunquote
|
from urllib import unquote as urlunquote
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from calibre import LoggingInterface
|
from calibre import LoggingInterface
|
||||||
|
|
||||||
@ -266,6 +267,8 @@ class Metadata(object):
|
|||||||
|
|
||||||
class Manifest(object):
|
class Manifest(object):
|
||||||
class Item(object):
|
class Item(object):
|
||||||
|
NUM_RE = re.compile('^(.*)([0-9][0-9.]*)(?=[.]|$)')
|
||||||
|
|
||||||
def __init__(self, id, href, media_type,
|
def __init__(self, id, href, media_type,
|
||||||
fallback=None, loader=str, data=None):
|
fallback=None, loader=str, data=None):
|
||||||
self.id = id
|
self.id = id
|
||||||
@ -314,7 +317,15 @@ class Manifest(object):
|
|||||||
result = cmp(self.spine_position, other.spine_position)
|
result = cmp(self.spine_position, other.spine_position)
|
||||||
if result != 0:
|
if result != 0:
|
||||||
return result
|
return result
|
||||||
return cmp(self.id, other.id)
|
smatch = self.NUM_RE.search(self.href)
|
||||||
|
sref = smatch.group(1) if smatch else self.href
|
||||||
|
snum = float(smatch.group(2)) if smatch else 0.0
|
||||||
|
skey = (sref, snum, self.id)
|
||||||
|
omatch = self.NUM_RE.search(other.href)
|
||||||
|
oref = omatch.group(1) if omatch else other.href
|
||||||
|
onum = float(omatch.group(2)) if omatch else 0.0
|
||||||
|
okey = (oref, onum, other.id)
|
||||||
|
return cmp(skey, okey)
|
||||||
|
|
||||||
def relhref(self, href):
|
def relhref(self, href):
|
||||||
if '/' not in self.href:
|
if '/' not in self.href:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user