2 # -*- coding: utf-8 -*-
 
   4 #    This file is part of Librarian.
 
   6 #    Copyright © 2008,2009,2010 Fundacja Nowoczesna Polska <fundacja@nowoczesnapolska.org.pl>
 
   8 #    For full list of contributors see AUTHORS file. 
 
  10 #    This program is free software: you can redistribute it and/or modify
 
  11 #    it under the terms of the GNU Affero General Public License as published by
 
  12 #    the Free Software Foundation, either version 3 of the License, or
 
  13 #    (at your option) any later version.
 
  15 #    This program is distributed in the hope that it will be useful,
 
  16 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  17 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  18 #    GNU Affero General Public License for more details.
 
  20 #    You should have received a copy of the GNU Affero General Public License
 
  21 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
  26 from librarian import html
 
  29 if __name__ == '__main__':
 
  30     # Parse commandline arguments
 
  31     usage = """Usage: %prog [options] SOURCE [SOURCE...]
 
  32     Extract theme fragments from SOURCE."""
 
  34     parser = optparse.OptionParser(usage=usage)
 
  36     parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
 
  37         help='print status messages to stdout')
 
  39     options, input_filenames = parser.parse_args()
 
  41     if len(input_filenames) < 1:
 
  46     for input_filename in input_filenames:
 
  50         output_filename = os.path.splitext(input_filename)[0] + '.fragments.html'
 
  52         closed_fragments, open_fragments = html.extract_fragments(input_filename)
 
  54         for fragment_id in open_fragments:
 
  55             print '%s:warning:unclosed fragment #%s' % (input_filename, fragment_id)
 
  57         output_file = open(output_filename, 'w')
 
  59             <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
  61                 <title>bookfragments output</title>
 
  62                 <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
 
  63                 <link rel="stylesheet" href="master.css" type="text/css" media="screen" charset="utf-8" />
 
  66         for fragment in closed_fragments.values():
 
  67             fragment_html = u'<div class="fragment"><h3>[#%s] %s</h3>%s</div>' % (fragment.id, fragment.themes, fragment)
 
  68             output_file.write(fragment_html.encode('utf-8'))
 
  69         output_file.write('</body></html>')