From: Marcin Koziej Date: Mon, 30 Jan 2012 09:07:04 +0000 (+0100) Subject: Merge branch 'master' of github.com:fnp/librarian into pretty X-Git-Tag: 1.7~170 X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/5f2702eda7a1b36f4d29658b5468b6b78745218c?hp=30d14a324bb0e8a99c54cbceea01476e59748b33 Merge branch 'master' of github.com:fnp/librarian into pretty --- diff --git a/librarian/cover.py b/librarian/cover.py index 63e4aa0..53d59bd 100644 --- a/librarian/cover.py +++ b/librarian/cover.py @@ -192,6 +192,8 @@ class WLCover(Cover): bar_width = 35 background_color = '#444' author_color = '#444' + default_background = get_resource('res/webtreatsetc-5647576127-ccby.png') + format = 'JPEG' epochs = { u'Starożytność': 0, @@ -217,6 +219,8 @@ class WLCover(Cover): bg_src = urlopen(book_info.cover_url) self.background_img = StringIO(bg_src.read()) bg_src.close() + else: + self.background_img = self.default_background def pretty_author(self): return self.author.upper() diff --git a/librarian/dcparser.py b/librarian/dcparser.py index a0eaa04..5a571ec 100644 --- a/librarian/dcparser.py +++ b/librarian/dcparser.py @@ -248,7 +248,7 @@ class WorkInfo(object): if not field.multiple: raise "OUCH!! for field %s" % name - return value[0] + return value[0] if value else None except (KeyError, AttributeError): return object.__getattribute__(self, name) @@ -347,9 +347,12 @@ class BookInfo(WorkInfo): Field( DCNS('audience'), 'audiences', salias='audience', multiple=True, required=False), - Field( DCNS('subject.period'), 'epochs', salias='epoch', multiple=True), - Field( DCNS('subject.type'), 'kinds', salias='kind', multiple=True), - Field( DCNS('subject.genre'), 'genres', salias='genre', multiple=True), + Field( DCNS('subject.period'), 'epochs', salias='epoch', multiple=True, + required=False), + Field( DCNS('subject.type'), 'kinds', salias='kind', multiple=True, + required=False), + Field( DCNS('subject.genre'), 'genres', salias='genre', multiple=True, + required=False), Field( DCNS('contributor.translator'), 'translators', \ as_person, salias='translator', multiple=True, default=[]), @@ -358,9 +361,9 @@ class BookInfo(WorkInfo): Field( DCNS('relation.isVariantOf'), 'variant_of', WLURI, strict=as_wluri_strict, required=False), - Field( DCNS('relation.cover_image.url'), 'cover_url', required=False), - Field( DCNS('relation.cover_image.attribution'), 'cover_by', required=False), - Field( DCNS('relation.cover_image.source'), 'cover_source', required=False), + Field( DCNS('relation.coverImage.url'), 'cover_url', required=False), + Field( DCNS('relation.coverImage.attribution'), 'cover_by', required=False), + Field( DCNS('relation.coverImage.source'), 'cover_source', required=False), ) diff --git a/librarian/html.py b/librarian/html.py index 39e5a01..b126638 100644 --- a/librarian/html.py +++ b/librarian/html.py @@ -163,7 +163,8 @@ def extract_fragments(input_filename): # Process all elements except begin and end else: # Omit annotation tags - if len(element.get('name', '')) or element.get('class', '') == 'annotation': + if (len(element.get('name', '')) or + element.get('class', '') in ('annotation', 'anchor')): if event == 'end' and element.tail: for fragment_id in open_fragments: open_fragments[fragment_id].append('text', element.tail) diff --git a/librarian/packagers.py b/librarian/packagers.py index 36a7b60..ddfd7c8 100644 --- a/librarian/packagers.py +++ b/librarian/packagers.py @@ -75,7 +75,7 @@ class PrestigioPdfPackager(PdfPackager): flags = ('less-advertising',) -class VirtualoEpubPackager(Packager): +class VirtualoPackager(Packager): @staticmethod def utf_trunc(text, limit): """ truncates text to at most `limit' bytes in utf-8 """ @@ -133,9 +133,16 @@ class VirtualoEpubPackager(Packager): cover.VirtualoCover(info).save(os.path.join(outfile_dir, slug+'.jpg')) outfile = os.path.join(outfile_dir, '1.epub') outfile_sample = os.path.join(outfile_dir, '1.sample.epub') - doc.save_output_file(epub.transform(doc), + doc.save_output_file(doc.as_epub(), output_path=outfile) - doc.save_output_file(epub.transform(doc, sample=25), + doc.save_output_file(doc.as_epub(doc, sample=25), + output_path=outfile_sample) + outfile = os.path.join(outfile_dir, '1.mobi') + outfile_sample = os.path.join(outfile_dir, '1.sample.mobi') + doc.save_output_file(doc.as_mobi(cover=cover.VirtualoCover), + output_path=outfile) + doc.save_output_file( + doc.as_mobi(doc, cover=cover.VirtualoCover, sample=25), output_path=outfile_sample) except ParseError, e: print '%(file)s:%(name)s:%(message)s' % { diff --git a/librarian/res/webtreatsetc-5647576127-ccby.png b/librarian/res/webtreatsetc-5647576127-ccby.png new file mode 100644 index 0000000..caadf5d Binary files /dev/null and b/librarian/res/webtreatsetc-5647576127-ccby.png differ diff --git a/scripts/book2cover b/scripts/book2cover index d2befc3..49cd539 100755 --- a/scripts/book2cover +++ b/scripts/book2cover @@ -33,7 +33,7 @@ if __name__ == '__main__': if options.verbose: print input_filename - output_filename = os.path.splitext(input_filename)[0] + '.png' + output_filename = os.path.splitext(input_filename)[0] + '.jpg' doc = WLDocument.from_file(input_filename) WLCover(doc.book_info).save(output_filename) diff --git a/scripts/book2html b/scripts/book2html index 1e88823..8adeb38 100755 --- a/scripts/book2html +++ b/scripts/book2html @@ -22,6 +22,8 @@ if __name__ == '__main__': help='print status messages to stdout') parser.add_option('-i', '--ignore-dublin-core', action='store_false', dest='parse_dublincore', default=True, help='don\'t try to parse dublin core metadata') + parser.add_option('-r', '--raw', action='store_false', dest='full_page', default=True, + help='outpu raw text for use in templates') options, input_filenames = parser.parse_args() @@ -38,7 +40,8 @@ if __name__ == '__main__': try: doc = WLDocument.from_file(input_filename, parse_dublincore=options.parse_dublincore) - html = doc.as_html(flags=('full-page',)) + flags = ('full-page',) if options.full_page else None + html = doc.as_html(flags=flags) doc.save_output_file(html, output_path=output_filename) except ParseError, e: print '%(file)s:%(name)s:%(message)s' % { diff --git a/scripts/book2partner b/scripts/book2partner index 0488273..4b84c2f 100755 --- a/scripts/book2partner +++ b/scripts/book2partner @@ -46,7 +46,7 @@ if __name__ == '__main__': if options.gandalf_pdf: packagers.GandalfPdfPackager.prepare(input_filenames, options.output_dir, options.verbose) if options.virtualo: - packagers.VirtualoEpubPackager.prepare(input_filenames, options.output_dir, options.verbose) + packagers.VirtualoPackager.prepare(input_filenames, options.output_dir, options.verbose) if options.prestigio: packagers.PrestigioEpubPackager.prepare(input_filenames, options.output_dir, options.verbose) if options.prestigio_pdf: