From 2f6a09e10e77c181512524f5ca13fabc6e4bffa9 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 14 Mar 2011 10:07:07 +0000 Subject: [PATCH] Fix #9395: Ondevice status not updated, regenerated --- src/calibre/devices/usbms/driver.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index a19df07abf..578c28b894 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -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.+?)' - 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.+?)' + 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):