Merge changes from master to Aigrain publishing code - that will be used for new...
authorMarcin Koziej <marcinkoziej@nowoczesnapolska.org.pl>
Wed, 7 Aug 2013 10:03:14 +0000 (12:03 +0200)
committerMarcin Koziej <marcinkoziej@nowoczesnapolska.org.pl>
Wed, 7 Aug 2013 10:03:14 +0000 (12:03 +0200)
1  2 
librarian/cover.py
librarian/dcparser.py
librarian/epub.py
librarian/epub/xsltLast.xsl
librarian/mobi.py
librarian/pdf/wl.cls
librarian/pdf/wl2tex.xslt
scripts/book2pdf

@@@ -212,16 -254,16 +254,15 @@@ class WLCover(Cover)
          u'Współczesność': '#06393d',
      }
  
-     def __init__(self, book_info):
-         super(WLCover, self).__init__(book_info)
+     def __init__(self, book_info, format=None, width=None, height=None, with_logo=False):
+         super(WLCover, self).__init__(book_info, format=format, width=width, height=height)
          self.kind = book_info.kind
          self.epoch = book_info.epoch
-         print book_info.cover_url
 -        self.with_logo = with_logo
          if book_info.cover_url:
-             from urllib2 import urlopen
-             from StringIO import StringIO
-             bg_src = urlopen(book_info.cover_url)
+             url = book_info.cover_url
+             bg_src = None
+             if bg_src is None:
+                 bg_src = URLOpener().open(url)
              self.background_img = StringIO(bg_src.read())
              bg_src.close()
          else:
Simple merge
@@@ -411,20 -444,12 +444,12 @@@ def transform(wldoc, verbose=False
      if cover:
          if cover is True:
              cover = WLCover
-         if cover.uses_dc_cover:
-             if document.book_info.cover_by:
-                 document.edoc.getroot().set('data-cover-by', document.book_info.cover_by)
-             if document.book_info.cover_source:
-                 document.edoc.getroot().set('data-cover-source', document.book_info.cover_source)
  
          cover_file = StringIO()
 -        bound_cover = cover(document.book_info)
 -        bound_cover.save(cover_file)
 -        cover_name = 'cover.%s' % bound_cover.ext()
 -        zip.writestr(os.path.join('OPS', cover_name), cover_file.getvalue())
 +        c = cover(document.book_info)
-         import Image
-         c.im = Image.open('cover.jpg')
-         c.ext = lambda: 'jpg'
 +        c.save(cover_file)
 +        c_name = 'cover.%s' % c.ext()
 +        zip.writestr(os.path.join('OPS', c_name), cover_file.getvalue())
          del cover_file
  
          cover_tree = etree.parse(get_resource('epub/cover.html'))
              </xsl:choose>
              </p>
            </xsl:if>
++          <div class="info">
++          <img src="jedenprocent.png" alt="Logo 1%" />
++          <div>Przekaż 1% podatku na rozwój Wolnych Lektur.</div>
++          <div>Nazwa organizacji: Fundacja Nowoczesna Polska</div>
++          <div>KRS 0000070056</div>
++          </div>
++
+           <p class="info">&#160;</p>
+           <p class="minor info">
+               Plik wygenerowany dnia <span id="file_date"><xsl:value-of select="substring(date:date(), 1, 10)" /></span>.
+           </p>
          </div>
        </body>
      </html>
index 6de72b3,d98b838..99b724e
mode 100755,100644..100644
@@@ -30,15 -30,12 +30,12 @@@ def transform(wldoc, verbose=False
      # provide a cover by default
      if not cover:
          cover = WLCover
 -    bound_cover = cover(book_info)
 -    bound_cover.save(cover_file)
+     cover_file = NamedTemporaryFile(suffix='.png', delete=False)
-     import Image
-     c.im = Image.open('cover.jpg')
-     c.ext = lambda: 'jpg'
-     cover_file = NamedTemporaryFile(suffix='.' + c.ext(), delete=False)
 +    c = cover(book_info)
 +    c.save(cover_file)
  
-     if cover.uses_dc_cover:
-         if document.book_info.cover_by:
+     if bound_cover.uses_dc_cover:
 -        if document.book_info.cover_by:
++        if document.remobook_info.cover_by:
              document.edoc.getroot().set('data-cover-by', document.book_info.cover_by)
          if document.book_info.cover_source:
              document.edoc.getroot().set('data-cover-source', document.book_info.cover_source)
@@@ -201,36 -189,11 +197,32 @@@ Letters={SmallCaps,UppercaseSmallCaps
  
          \noindent\hspace*{-\PictHOffset}%
          \raisebox{\PictVOffset}[0pt][0pt]{\makebox[0pt][l]{%
-             \includegraphics[height=#2,width=#1]{cover.jpg}}}
-         %\clearpage
-         \vspace{#2}
+             \includegraphics[height=\pdfpageheight,width=\pdfpagewidth]{cover.png}}}
+         \clearpage
  
-         \hspace{-36mm}\parbox{16cm}{
 -        \setlength{\pdfpagewidth}{210mm}
 -        \setlength{\pdfpageheight}{297mm}
++ 
++%% Strona tytułowa %% XXX
++       \hspace{-36mm}\parbox{16cm}{
 +        {\addfontfeature{LetterSpace=-4.0}{\scalefont{4}%
 +            \noindent Philippe Aigrain}}
 +
 +       {\addfontfeature{LetterSpace=-4.0}{\scalefont{2.5}%
 +            przy współpracy Suzanne Aigrain
 +        }}
 +
 +        \vspace{2em}
 +        {\addfontfeature{LetterSpace=-4.0}{\scalefont{6}%
 +            Dzielenie się
 +        }}
 +        
 +        \vspace{2em}
 +        {\addfontfeature{LetterSpace=-4.0}{\scalefont{3}%
 +            Kultura i gospodarka epoki internetu
 +        }}
-         
- %\emph{\thankyou}\\
- %\indent\emph{You made this book possible.}
 +        }
 +
-         %\setlength{\pdfpagewidth}{210mm}
-         %\setlength{\pdfpageheight}{297mm}
++       \setlength{\pdfpagewidth}{210mm}
++       \setlength{\pdfpageheight}{297mm}
  }
  
  
      }
  }
  
 +\usepackage{printlen}
 +
  \newcommand{\editorialsection}{
 -  \begin{figure}[b!]
 -  {
 -    \footnotesize
 -    \color{theme}
 -    \noindent \rule{\linewidth}{0.4pt}
++%% XXX % sprawdzic czy czegos nie zgubilem z master
++%% szczegolnie jesli chodzi o makra wstawiajace dane z DC, jak np \editors
 +\clearpage
 +        \thispagestyle{empty}
  
 -    \rightsinfo
 -    \vspace{.6em}
 +% Pusta strona 
 +\clearpage
 +        \thispagestyle{empty}
  
 -    Źródło: \href{\bookurl}{\bookurl}
 +\vspace{2em}
 +      \hspace{0mm}\parbox{16cm}{
 +\centering
 +      {\addfontfeature{LetterSpace=-4.0}{\scalefont{6}%
 +           Dzielenie się
 +      }}
 +
 +  \vspace{2em}
 +         {\addfontfeature{LetterSpace=-4.0}{\scalefont{3}%
 +             Kultura i gospodarka epoki internetu
 +         }}
 +}
  
 -    \vspace{.6em}
 -    \sourceinfo
 +\clearpage
 +        \thispagestyle{empty}
  
 -    \description
 -    \vspace{.6em}
 +\clearpage
 +        \thispagestyle{empty}
  
 -    \editors
 +%\parbox{10cm}{
 +%  \centering
 +
 +  \hspace{-36mm}\parbox{16cm}{
 +\centering
 +
 +  {\addfontfeature{LetterSpace=-4.0}{\scalefont{4}%
 +      \noindent Philippe Aigrain
 +  }}
 +
 +  {\addfontfeature{LetterSpace=-4.0}{\scalefont{2.5}%
 +      przy współpracy Suzanne Aigrain
 +  }}
 +  
 +  \vspace{2em}
 +         {\addfontfeature{LetterSpace=-4.0}{\scalefont{6}%
 +             Dzielenie się
 +         }}
 +         
 +  \vspace{2em}
 +         {\addfontfeature{LetterSpace=-4.0}{\scalefont{4}%
 +             Kultura i gospodarka epoki internetu
 +         }}
 +
 +  \vspace{2em}
 +         {\addfontfeature{LetterSpace=-4.0}{\scalefont{2}%
 +             Z języka angielskiego przełożył \\
 +             \emph{Wojciech Pędzich}
 +         }}
 +
 +\vspace{22em}
 +
 +\includegraphics[scale=.2]{logo.eps}
 +}
  
 -    \ifdefined\coverby
 -        \vspace{.6em}
 -        \coverby
 -    \fi
++    Przekaż darowiznę na konto:
++    \href{http://nowoczesnapolska.org.pl/pomoz-nam/wesprzyj-nas/}{szczegóły na stronie Fundacji}.
  
 -    \vspace{.6em}
 -    \emph{Wesprzyj Wolne Lektury!}
 +\clearpage
 +        \thispagestyle{empty}
  
 -    Wolne Lektury to projekt fundacji Nowoczesna Polska – organizacji
 -    pożytku publicznego działającej na rzecz wolności korzystania
 -    z dóbr kultury.
 +\noindent Tytuł oryginału
  
 -    Co roku do domeny publicznej przechodzi twórczość kolejnych autorów.
 -    Dzięki Twojemu wsparciu będziemy je mogli udostępnić wszystkim bezpłatnie.
 +\noindent \emph{Sharing. Culture and the Economy in the Internet Age}
  
 -    \vspace{.6em}
 -    \emph{Jak możesz pomóc?}
 +\vspace{1em}
  
 -    Przekaż 1\% podatku na rozwój Wolnych Lektur:
 -    Fundacja Nowoczesna Polska, KRS 0000070056.
 +\noindent \editors
  
 -    Pomóż uwolnić konkretną książkę, wspierając
 -    \href{http://www.wolnelektury.pl/wesprzyj/}{zbiórkę na stronie wolnelektury.pl}.
 +\vspace{1em}
  
 -    Przekaż darowiznę na konto:
 -    \href{http://nowoczesnapolska.org.pl/pomoz-nam/wesprzyj-nas/}{szczegóły na stronie Fundacji}.
  
 -    \color{black}
 -  }
 -  \end{figure}
 +\noindent \rightsinfo
 +
 +\vspace{1em}
 +
 +\noindent \coverby
 +
 +
 +%\set\textwidth=450pt
 +%\printlength\textwidth
 +
 +
 +%% {\scalefont{1.5}Drogi czytelniku!}
 +
 +
 +
 +%% \vspace{1em}
 +
 +\vspace{1em}
 +
 +\noindent Tłumaczenie książki powstało w ramach projektu "Przyszłość prawa autorskiego" finansowanego przez {\it Trust for Civil Society in Central and Eastern Europe}.
 +
 +\vspace{1em}
 +
 +\noindent \includegraphics[scale=.4]{cce_trust.eps}
 +
 +\vspace{1em}
 +
 +\noindent Wydawca: Fundacja Nowoczesna Polska, Warszawa 2012
 +
 +\vspace{1em}
 +\includegraphics[scale=.2]{logo.eps}
 +\vspace{1em}
 +
 +\noindent \href{http://nowoczesnapolska.org.pl/}{http://nowoczesnapolska.org.pl/}
 +
 +
 +
 +%\vspace{4em}
 +%\box{\tableofcontents}
 +
 +%%   \begin{figure}[b!]
 +%%   {
 +%%     \footnotesize
 +%%     \color{theme}
 +%%     \noindent \rule{\linewidth}{0.4pt}
 +
 +%%     \rightsinfo
 +%% %    \vspace{.6em}
 +
 +%%     %Źródło: \href{\bookurl}{\bookurl}
 +
 +%%     %\vspace{.6em}
 +%%     %\sourceinfo
 +
 +%%     %\description
 +%%     %\vspace{.6em}
 +
 +%%     Opublikowano przez \href{http://nowoczesnapolska.org.pl}{Fundację Nowoczesna Polska}, 2012.
 +
 +%%     \editors
 +
 +%%     %\vspace{.6em}
 +%%     \coverby
 +    
 +%%     \color{black}
 +%%   }
 +%%   \end{figure}
 +\clearpage
  }
  
  
Simple merge
@@@ -4,61 -4,21 +4,23 @@@
  # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
  # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
  #
+ from librarian.book2anything import Book2Anything, Option
 +import os.path
 +from optparse import OptionParser
  
- from librarian import DirDocProvider, ParseError
- from librarian.parser import WLDocument
  
+ class Book2Pdf(Book2Anything):
+     format_name = "PDF"
+     ext = "pdf"
+     uses_cover = True
+     uses_provider = True
+     transform_args = [
+         Option('-t', '--save-tex', dest='save_tex', metavar='FILE',
+                 help='path to save the intermediary LaTeX file to'),
+         Option('-m', '--morefloats', dest='morefloats', metavar='old/new/none',
+                 help='force morefloats in old (<1.0c), new (>=1.0c) or none')
+     ]
  
- if __name__ == '__main__':
-     usage = """Usage: %prog [options] SOURCE [SOURCE...]
-     Convert SOURCE files to PDF format."""
-     parser = OptionParser(usage)
-     parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
-                       help='make lots of noise and revert to default interaction in LaTeX')
-     parser.add_option('-c', '--with-cover', action='store_true', dest='with_cover', default=False,
-                       help='create default cover')
-     parser.add_option('-d', '--make-dir', action='store_true', dest='make_dir', default=False,
-                       help='create a directory for author and put the PDF in it')
-     parser.add_option('-t', '--save-tex', dest='save_tex', metavar='FILE',
-                       help='path to save the intermediary LaTeX file to')
-     parser.add_option('-o', '--output-file', dest='output_file', metavar='FILE',
-                       help='specifies the output file')
-     parser.add_option('-O', '--output-dir', dest='output_dir', metavar='DIR',
-                       help='specifies the directory for output')
-     parser.add_option('-m', '--morefloats', dest='morefloats', metavar='old/new/none',
-                       help='force morefloats in old (<1.0c), new (>=1.0c) or none')
-     (options, args) = parser.parse_args()
-     if len(args) < 1:
-         parser.print_help()
-         exit(1)
-     if options.output_dir and options.output_file:
-         raise ValueError("Either --output-dir or --output file should be specified")
  
-     try:
-         for main_input in args:
-             path, fname = os.path.realpath(main_input).rsplit('/', 1)
-             provider = DirDocProvider(path)
-             output_file, output_dir = options.output_file, options.output_dir
-             if not (options.output_file or options.output_dir):
-                 output_file = os.path.splitext(main_input)[0] + '.pdf'
-             else:
-                 output_file = None
-             doc = WLDocument.from_file(main_input, provider=provider)
-             pdf = doc.as_pdf(save_tex=options.save_tex,
-                         cover=options.with_cover,
-                         morefloats=options.morefloats, verbose=options.verbose)
-             doc.save_output_file(pdf,
-                 output_file, options.output_dir, options.make_dir, 'pdf')
-     except ParseError, e:
-         print '%(file)s:%(name)s:%(message)s; use -v to see more output' % {
-             'file': main_input,
-             'name': e.__class__.__name__,
-             'message': e
-         }
+ if __name__ == '__main__':
+     Book2Pdf.run()