From: <mat...@us...> - 2009-01-10 02:23:02
|
Author: matt_harrison Date: 2009-01-10 02:39:00 +0100 (Sat, 10 Jan 2009) New Revision: 5843 Modified: trunk/sandbox/rst2odp/bin/rst2odp trunk/sandbox/rst2odp/odplib/preso.py Log: add --pages-to-export option (useful for debugging and limiting pages) Modified: trunk/sandbox/rst2odp/bin/rst2odp =================================================================== --- trunk/sandbox/rst2odp/bin/rst2odp 2009-01-09 21:38:09 UTC (rev 5842) +++ trunk/sandbox/rst2odp/bin/rst2odp 2009-01-10 01:39:00 UTC (rev 5843) @@ -69,6 +69,24 @@ rst.directives.register_directive('code-block', SyntaxHighlightCodeBlock) +class ImportNode(nodes.General, nodes.Inline, nodes.Element): pass + +class ImportSlideBlock(rst.Directive): + required_arguments = 2 + optional_arguments = 0 + has_content = False + node_class = ImportNode + # + # See visit_literal_block for code that processes the node + # created here. + def run(self): + odp_path = self.arguments[0] + page_num = self.arguments[1] + node = ImportNode(odp_path=odp_path, page_num=page_num) + return [node] + +rst.directives.register_directive('importslide', ImportSlideBlock) + class Writer(writers.Writer): settings_spec = ( 'ODP Specific Options', # option group title @@ -81,7 +99,11 @@ ('Specify a monospace font to use ("Courier New" default)', ['--mono-font'], {'action': 'store', - 'dest': 'mono_font'}) + 'dest': 'mono_font'}), + ('Specify pages to export (2,3,9-10)', + ['--pages-to-output'], + {'action': 'store', + 'dest': 'pages_to_output'}) ) ) def __init__(self): @@ -102,6 +124,9 @@ self.settings = document.settings self.preso = preso.Preso() + if self.settings.pages_to_output: + self.preso.limit_pages = num_string_to_list(self.settings.pages_to_output) + if self.settings.mono_font: preso.MONO_FONT = self.settings.mono_font @@ -641,6 +666,11 @@ #self.cur_slide.insert_line_break = True pass + def visit_importslide(self, node): + pass + + + def _get_text_attribs(self, node): classes = node.attributes.get('classes', []) attribs = {} @@ -651,6 +681,33 @@ attribs['fo:font-size'] = S5_SIZES[c] return attribs +def num_string_to_list(numstr): + """ + >>> num_string_to_list('2,5-7') + [2, 5, 6, 7] + >>> num_string_to_list('1') + [1] + + """ + nums = [] + if ',' in numstr: + comma_delim = numstr.split(',') + for part in comma_delim: + if '-' in part: + start, end = [int(x) for x in part.split('-')] + for num in range(start, end+1): + nums.append(num) + else: + nums.append(int(part)) + elif '-' in numstr: + start, end = [int(x) for x in numstr.split('-')] + for num in range(start, end+1): + nums.append(num) + else: + nums.append(int(numstr)) + return nums + + class BinaryFileOutput(io.FileOutput): """ A version of docutils.io.FileOutput which writes to a binary file. @@ -696,5 +753,12 @@ enable_exit_status=enable_exit_status) +def _test(): + import doctest + doctest.testmod() + if __name__ == "__main__": - sys.exit(main(sys.argv) or 0) + if '--doctest' in sys.argv: + _test() + else: + sys.exit(main(sys.argv) or 0) Modified: trunk/sandbox/rst2odp/odplib/preso.py =================================================================== --- trunk/sandbox/rst2odp/odplib/preso.py 2009-01-09 21:38:09 UTC (rev 5842) +++ trunk/sandbox/rst2odp/odplib/preso.py 2009-01-10 01:39:00 UTC (rev 5843) @@ -134,6 +134,7 @@ def __init__(self): self.slides = [] + self.limit_pages = [] # can be list of page numbers (not indexes to export) self._pictures = [] # list of Picture instances self._footer_count = 0 # xml elements @@ -260,6 +261,9 @@ def to_xml(self): for i, slide in enumerate(self.slides): + if self.limit_pages and i+1 not in self.limit_pages: + + continue if slide.footer: footer_node = slide.footer.get_node() self._presentation.append(footer_node) |