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.
'''
import os, re, time, json, uuid
import os, re, time, json, uuid, functools
from itertools import cycle
from calibre.constants import numeric_version
@ -372,15 +372,21 @@ class USBMS(CLI, Device):
@classmethod
def build_template_regexp(cls):
def replfunc(match):
if match.group(1) in ['title', 'series', 'series_index', 'isbn']:
return '(?P<' + match.group(1) + '>.+?)'
elif match.group(1) in ['authors', 'author_sort']:
return '(?P<author>.+?)'
else:
return '(.+?)'
def replfunc(match, seen=None):
v = match.group(1)
if v in ['title', 'series', 'series_index', 'isbn']:
if v not in seen:
seen |= set([v])
return '(?P<' + v + '>.+?)'
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]
return re.compile(re.sub('{([^}]*)}', replfunc, template) + '([_\d]*$)')
return re.compile(re.sub('{([^}]*)}', f, template) + '([_\d]*$)')
@classmethod
def path_to_unicode(cls, path):