Exemple #1
0
     parser.print_help()
     exit(1)
 # Open input document
 infile = args[0]
 extension = get_extension(infile)
 if extension == 'rst':
     indoc = open(infile, 'rb').read()
     intype = 'rst'
 else:
     indoc = odf_get_document(infile)
     intype = indoc.get_type()
 # Open output document
 outfile = args[1]
 extension = get_extension(outfile)
 if extension in ('csv', 'html', 'rst', 'txt'):
     check_target_file(outfile)
     target_file_checked = True
     outdoc = open(outfile, 'wb')
     outtype = extension
 else:
     if options.styles_from:
         outdoc = odf_get_document(options.styles_from).clone()
         outdoc.get_body().clear()
         outdoc.path = outfile
         outtype = outdoc.get_type()
     else:
         try:
             mimetype = ODF_EXTENSIONS[extension]
         except KeyError:
             raise ValueError, ("output filename not recognized: " +
                                extension)
    parser = OptionParser(usage, version=__version__, description=description)
    # --output
    add_option_output(parser, complement='("-" for stdout)')

    # Parse !
    options, filenames = parser.parse_args()

    # Arguments
    if not filenames:
        parser.print_help()
        exit(1)
    target = options.output
    if target is None:
        printerr('"-o" option mandatory (use "-" to print to stdout)')
        exit(1)
    check_target_file(target)

    output_doc = None
    output_type = None

    # Concatenate content in the output doc
    for filename in filenames:

        # Exists ?
        if not exists(filename):
            printerr("Skip", filename, "not existing")
            continue

        # A good file => Only text, spreadsheet and CSV
        mimetype = get_mimetype(filename)
        if mimetype not in (ODF_TEXT, ODF_SPREADSHEET, ODF_PRESENTATION,
Exemple #3
0
    # Parse options
    options, args = parser.parse_args()
    if len(args) < 1:
        parser.print_help()
        exit(1)

    # Get the 2 paths
    inname = args[0]
    outname = options.output
    # Default value for the name of the output file.
    if not outname:
        mm_basename = basename(inname)
        outname = '%s.odt' % splitext(mm_basename)[0]
    # Check if the file already exists
    check_target_file(outname)

    # Open the XML file
    mm = parse(open(inname, 'rb'))
    # Get the first node of the mind map
    first_node = mm.xpath('/map/node')[0]
    # Make the structure
    mm_structure = make_mm_structure(first_node, 0)

    # Create a new ODT document
    document = odf_new_document('text')
    body = document.get_body()
    # Remove the default paragraph
    body.clear()
    # Begin with a TOC
    toc = odf_create_toc()
    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 = odf_get_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:
            check_target_file(target)
        delete_styles(document, target)
    elif options.merge:
        merge_styles(document, options.merge, target=options.output)
    else:
        automatic = options.automatic
        common = options.common
        if not automatic ^ common:
            automatic, common = True, True
        target = options.output
        if target is not None:
            target = open(target, "wb")
        show_styles(document, target, automatic=automatic, common=common, properties=options.properties)
    # Parse options
    options, args = parser.parse_args()
    if len(args) < 1:
        parser.print_help()
        exit(1)

    # Get the 2 paths
    inname = args[0]
    outname = options.output
    # Default value for the name of the output file.
    if not outname:
        mm_basename = basename(inname)
        outname = '%s.odt' % splitext(mm_basename)[0]
    # Check if the file already exists
    check_target_file(outname)

    # Open the XML file
    mm = parse(open(inname, 'rb'))
    # Get the first node of the mind map
    first_node = mm.xpath('/map/node')[0]
    # Make the structure
    mm_structure = make_mm_structure(first_node, 0)

    # Create a new ODT document
    document = odf_new_document('text')
    body = document.get_body()
    # Remove the default paragraph
    body.clear()
    # Begin with a TOC
    toc = odf_create_toc()