~ubuntu-branches/debian/wheezy/calibre/wheezy

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/metadata/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2010-08-11 11:30:57 UTC
  • mfrom: (1.3.14 upstream)
  • mto: (29.3.2 oneiric)
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: james.westby@ubuntu.com-20100811113057-2jhbcbavxw7wlt0c
Tags: 0.7.13+dfsg-1
* New upstream version.
* debian/control: Add python-routes recommends. (Closes: #590561)
* Convert to 3.0 (quilt) source format.
* Bump debhelper compat level to 7, and drop now obsolete
  DEB_DH_INSTALL_SOURCEDIR in debian/rules.
* debian/control: Add missing ${misc:Depends}.
* debian/control: Bump Standards-Version to 3.9.1.
* debian/copyright: Replace obsolete reference to
  /usr/share/common-licenses/BSD with their verbatim text from the original
  source.
* debian/rules: Remove invalid hashbang lines from *.recipe, these have no
  __main__.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    return ' & '.join(map(author_to_author_sort, authors))
47
47
 
48
48
_title_pat = re.compile('^(A|The|An)\s+', re.IGNORECASE)
 
49
 
49
50
def title_sort(title):
50
51
    match = _title_pat.search(title)
51
52
    if match:
268
269
                  ):
269
270
            prints(x, getattr(self, x, 'None'))
270
271
 
271
 
    def smart_update(self, mi, replace_tags=False):
 
272
    def smart_update(self, mi, replace_metadata=False):
272
273
        '''
273
 
        Merge the information in C{mi} into self. In case of conflicts, the information
274
 
        in C{mi} takes precedence, unless the information in mi is NULL.
 
274
        Merge the information in C{mi} into self. In case of conflicts, the
 
275
        information in C{mi} takes precedence, unless the information in mi is
 
276
        NULL. If replace_metadata is True, then the information in mi always
 
277
        takes precedence.
275
278
        '''
276
279
        if mi.title and mi.title != _('Unknown'):
277
280
            self.title = mi.title
285
288
                     'cover', 'guide', 'book_producer',
286
289
                     'timestamp', 'lccn', 'lcc', 'ddc', 'pubdate', 'rights',
287
290
                     'publication_type', 'uuid'):
288
 
            if hasattr(mi, attr):
 
291
            if replace_metadata:
 
292
                setattr(self, attr, getattr(mi, attr, 1.0 if \
 
293
                        attr == 'series_index' else None))
 
294
            elif hasattr(mi, attr):
289
295
                val = getattr(mi, attr)
290
296
                if val is not None:
291
297
                    setattr(self, attr, val)
292
298
 
293
 
        if mi.tags:
294
 
            if replace_tags:
295
 
                self.tags = mi.tags
296
 
            else:
297
 
                self.tags += mi.tags
 
299
        if replace_metadata:
 
300
            self.tags = mi.tags
 
301
        elif mi.tags:
 
302
            self.tags += mi.tags
298
303
        self.tags = list(set(self.tags))
299
304
 
300
305
        if mi.author_sort_map:
308
313
            if len(other_cover) > len(self_cover):
309
314
                self.cover_data = mi.cover_data
310
315
 
311
 
        my_comments = getattr(self, 'comments', '')
312
 
        other_comments = getattr(mi, 'comments', '')
313
 
        if not my_comments:
314
 
            my_comments = ''
315
 
        if not other_comments:
316
 
            other_comments = ''
317
 
        if len(other_comments.strip()) > len(my_comments.strip()):
318
 
            self.comments = other_comments
 
316
        if replace_metadata:
 
317
            self.comments = getattr(mi, 'comments', '')
 
318
        else:
 
319
            my_comments = getattr(self, 'comments', '')
 
320
            other_comments = getattr(mi, 'comments', '')
 
321
            if not my_comments:
 
322
                my_comments = ''
 
323
            if not other_comments:
 
324
                other_comments = ''
 
325
            if len(other_comments.strip()) > len(my_comments.strip()):
 
326
                self.comments = other_comments
319
327
 
320
328
        other_lang = getattr(mi, 'language', None)
321
329
        if other_lang and other_lang.lower() != 'und':