Fix #9395: Ondevice status not updated, regenerated

This commit is contained in:
Charles Haley 2011-03-14 10:07:07 +00:00
parent c62ad45810
commit 2f6a09e10e

View File

@ -10,7 +10,7 @@ driver. It is intended to be subclassed with the relevant parts implemented
for a particular device. for a particular device.
''' '''
import os, re, time, json, uuid import os, re, time, json, uuid, functools
from itertools import cycle from itertools import cycle
from calibre.constants import numeric_version from calibre.constants import numeric_version
@ -372,15 +372,21 @@ class USBMS(CLI, Device):
@classmethod @classmethod
def build_template_regexp(cls): def build_template_regexp(cls):
def replfunc(match): def replfunc(match, seen=None):
if match.group(1) in ['title', 'series', 'series_index', 'isbn']: v = match.group(1)
return '(?P<' + match.group(1) + '>.+?)' if v in ['title', 'series', 'series_index', 'isbn']:
elif match.group(1) in ['authors', 'author_sort']: if v not in seen:
return '(?P<author>.+?)' seen |= set([v])
else: return '(?P<' + v + '>.+?)'
return '(.+?)' elif v in ['authors', 'author_sort']:
if v not in seen:
seen |= set([v])
return '(?P<author>.+?)'
return '(.+?)'
s = set()
f = functools.partial(replfunc, seen=s)
template = cls.save_template().rpartition('/')[2] template = cls.save_template().rpartition('/')[2]
return re.compile(re.sub('{([^}]*)}', replfunc, template) + '([_\d]*$)') return re.compile(re.sub('{([^}]*)}', f, template) + '([_\d]*$)')
@classmethod @classmethod
def path_to_unicode(cls, path): def path_to_unicode(cls, path):