def main(): # Options initialisation usage = ( "%prog [--styles] [--meta] [--no-content] [--rst] <file>\n" " %prog -o <DIR> [--rst] <file>" ) description = ( "Dump text from an OpenDocument file to the standard " "output, optionally styles and meta (and the Pictures/* " 'in "-o <DIR>" mode)' ) parser = OptionParser(usage, version=__version__, description=description) # --meta parser.add_option( "-m", "--meta", action="store_true", default=False, help="dump metadata to stdout", ) # --styles parser.add_option( "-s", "--styles", action="store_true", default=False, help="dump styles to stdout", ) # --no-content parser.add_option( "-n", "--no-content", action="store_true", default=False, help="do not dump content to stdout", ) # --rst parser.add_option( "-r", "--rst", action="store_true", default=False, help="Dump the content file with a reST syntax", ) # --output add_option_output(parser, metavar="DIR") # Parse ! options, args = parser.parse_args() # Container if len(args) != 1: parser.print_help() exit(1) container_url = args[0] # Open it! doc = Document(container_url) doc_type = doc.get_type() # Test it! XXX for TEXT only # if doc_type == 'text': # result = test_document(document) # if result is not True: # print('This file is malformed: %s' % result) # print('Please use lpod-clean.py to fix it') # exit(1) if options.output: output = options.output check_target_directory(output) if exists(output): rmtree(output) makedirs(output) with open(join(output, "meta.txt"), "w") as f: f.write(doc.get_formated_meta()) with open(join(output, "styles.txt"), "w") as f: f.write(doc.show_styles()) dump_pictures(doc, output) else: if options.meta: print(doc.get_formated_meta()) if options.styles: print(doc.show_styles()) # text if doc_type in {"text", "text-template", "presentation", "presentation-template"}: if options.output: with open(join(output, "content.rst"), "w") as f: f.write(doc.get_formatted_text(rst_mode=options.rst)) elif not options.no_content: print(doc.get_formatted_text(rst_mode=options.rst)) # spreadsheet elif doc_type in {"spreadsheet", "spreadsheet-template"}: if options.output: spreadsheet_to_csv(doc) elif not options.no_content: spreadsheet_to_stdout(doc) else: printerr("The OpenDocument format", doc_type, "is not supported yet.") sys.exit(1)
action='store_true', help="show properties of styles") # --delete help = ("return a copy with all styles (except default) deleted from " "<file>") parser.add_option('-d', '--delete', action='store_true', help=help) # --merge help = ('copy styles from FILE to <file>. Any style with the same name ' 'will be replaced.') parser.add_option('-m', '--merge-styles-from', dest='merge', metavar='FILE', help=help) # --output add_option_output(parser) #Parse options options, args = parser.parse_args() if len(args) != 1: parser.print_help() exit(1) document = Document(args[0]) if options.delete: target = options.output if target is None: printerr("Will not delete in-place: ", 'output file needed or "-" for stdout') exit(1) elif target == "-": target = StdoutWriter() else:
def main(): # Options initialisation usage = "%prog [options] <file>" description = "A command line interface to manipulate styles of OpenDocument files." parser = OptionParser(usage, version=__version__, description=description) # --automatic parser.add_option( "-a", "--automatic", action="store_true", default=False, help="show automatic styles only", ) # --common parser.add_option( "-c", "--common", action="store_true", default=False, help="show common styles only", ) # --properties parser.add_option("-p", "--properties", action="store_true", help="show properties of styles") # --delete msg = "return a copy with all styles (except default) deleted from <file>" parser.add_option("-d", "--delete", action="store_true", help=msg) # --merge msg = ("copy styles from FILE to <file>. Any style with the same " "name will be replaced.") parser.add_option("-m", "--merge-styles-from", dest="merge", metavar="FILE", help=msg) # --output add_option_output(parser) # Parse options options, args = parser.parse_args() if len(args) != 1: parser.print_help() sys.exit(1) doc = Document(args[0]) if options.delete: target = options.output if target is None: printerr("Will not delete in-place: ", 'output file needed or "-" for stdout') sys.exit(1) elif target == "-": target = StdoutWriter() else: check_target_file(target) delete_styles(doc, target) elif options.merge: merge_styles(doc, options.merge, target=options.output) else: automatic = options.automatic common = options.common if not automatic ^ common: automatic, common = True, True show_styles( doc, options.output, automatic=automatic, common=common, properties=options.properties, )
def main(): # Options initialisation usage = '%prog [options] <file>' description = ('A command line interface to manipulate styles of ' 'OpenDocument files.') parser = OptionParser(usage, version=__version__, description=description) # --automatic parser.add_option('-a', '--automatic', action='store_true', default=False, help='show automatic styles only') # --common parser.add_option('-c', '--common', action='store_true', default=False, help='show common styles only') # --properties parser.add_option('-p', '--properties', action='store_true', help='show properties of styles') # --delete msg = ('return a copy with all styles (except default) deleted from ' '<file>') parser.add_option('-d', '--delete', action='store_true', help=msg) # --merge msg = ('copy styles from FILE to <file>. Any style with the same ' 'name will be replaced.') parser.add_option('-m', '--merge-styles-from', dest='merge', metavar='FILE', help=msg) # --output add_option_output(parser) # Parse options options, args = parser.parse_args() if len(args) != 1: parser.print_help() sys.exit(1) doc = Document(args[0]) if options.delete: target = options.output if target is None: printerr('Will not delete in-place: ', 'output file needed or "-" for stdout') sys.exit(1) elif target == '-': target = StdoutWriter() else: check_target_file(target) delete_styles(doc, target) elif options.merge: merge_styles(doc, options.merge, target=options.output) else: automatic = options.automatic common = options.common if not automatic ^ common: automatic, common = True, True show_styles(doc, options.output, automatic=automatic, common=common, properties=options.properties)