Пример #1
0
def set_metadata(doc, set_list):
    meta = doc.get_meta()
    for set_info in set_list:
        if '=' not in set_info:
            printerr('Bad argument -s "%s" (must be "name=value")' % set_info)
            exit(1)
        name, value = set_info.split('=', 1)
        name = name.lower().strip()
        value = value.strip()

        if name in ("title", "subject", "initial_creator",
                    "keywords", "generator", "description"):
            value = value.decode(stdin.encoding)
            func = meta.__getattribute__('set_' + name)
            func(value)
        elif name == "language":
            meta.set_language(value)
        elif name in ("modification_date", "creation_date"):
            try:
                if 'T' in value:
                    date = DateTime.decode(value)
                else:
                    date = Date.decode(value)
            except ValueError, error:
                printerr('Bad argument -s "%s": %s' % (set_info, error))
                exit(1)
            func = meta.__getattribute__('set_' + name)
            func(date)
        else:
            printerr('Unknown metadata name "%s", please choose: ' % name)
            printerr("       title, subject, initial_creator, keywords, "
                    "generator, description, modification_date or "
                    "creation_date")
            exit(1)
Пример #2
0
def set_metadata(doc, set_list):
    meta = doc.get_meta()
    for set_info in set_list:
        if '=' not in set_info:
            printerr('Bad argument -s "%s" (must be "name=value")' % set_info)
            exit(1)
        name, value = set_info.split('=', 1)
        name = name.lower().strip()
        value = value.strip()

        if name in ("title", "subject", "initial_creator", "keywords",
                    "generator", "description"):
            value = value.decode(stdin.encoding)
            func = meta.__getattribute__('set_' + name)
            func(value)
        elif name == "language":
            meta.set_language(value)
        elif name in ("modification_date", "creation_date"):
            try:
                if 'T' in value:
                    date = DateTime.decode(value)
                else:
                    date = Date.decode(value)
            except ValueError, error:
                printerr('Bad argument -s "%s": %s' % (set_info, error))
                exit(1)
            func = meta.__getattribute__('set_' + name)
            func(date)
        else:
            printerr('Unknown metadata name "%s", please choose: ' % name)
            printerr("       title, subject, initial_creator, keywords, "
                     "generator, description, modification_date or "
                     "creation_date")
            exit(1)
Пример #3
0
def print_incompatible(filename, type):
    printerr('Cannot merge "%s" in %s document, skipping.' % (filename, type))
Пример #4
0
    usage = "%prog -o FILE <file1> [<file2> ...]"
    description = "Merge all input files in an unique OpenDocument file"
    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
Пример #5
0
    usage = "%prog -o FILE <file1> [<file2> ...]"
    description = "Catalog all input files in a presentation"
    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_document = odf_new_document('presentation')
    output_meta = output_document.get_part(ODF_META)
    output_meta.set_title(u"Interop Budapest Demo")

    # Styles
    styles = output_document.get_part(ODF_STYLES)
    first_master_page = styles.get_master_page()
    if first_master_page is None:
        raise ValueError, "no master page found"

    for i, filename in enumerate(filenames):
        # TODO folders and collections
Пример #6
0
 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 = 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:
Пример #7
0
 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 = 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:
Пример #8
0
        # Meta
        to_file = open(join(target, 'meta.txt'), 'wb')
        dump(document.get_formated_meta(), to_file)
        # Styles
        to_file = open(join(target, 'styles.txt'), 'wb')
        dump(document.show_styles(), to_file)
        # Pictures
        dump_pictures(document, target)
    else:
        if options.meta:
            dump(document.get_formated_meta(), stdout)
        if options.styles:
            dump(document.show_styles(), stdout)
    # text
    if doc_type in ('text', 'text-template', 'presentation',
            'presentation-template'):
        if options.output:
            to_file = open(join(target, 'content.rst'), 'wb')
            dump(document.get_formatted_text(rst_mode=options.rst), to_file)
        elif not options.no_content:
            dump(document.get_formatted_text(rst_mode=options.rst), stdout)
    # spreadsheet
    elif doc_type in ('spreadsheet', 'spreadsheet-template'):
        if options.output:
            spreadsheet_to_csv(document, target)
        elif not options.no_content:
            spreadsheet_to_stdout(document)
    else:
        printerr("The OpenDocument format", doc_type, "is not supported yet.")
        exit(1)
Пример #9
0
def print_incompatible(filename, type):
    printerr('Cannot merge "%s" in %s document, skipping.' % (filename, type))
Пример #10
0
    description = "Merge all input files in an unique OpenDocument file"
    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
Пример #11
0
    description = "Catalog all input files in a presentation"
    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_document = odf_new_document('presentation')
    output_meta = output_document.get_part(ODF_META)
    output_meta.set_title(u"Interop Budapest Demo")

    # Styles
    styles = output_document.get_part(ODF_STYLES)
    first_master_page = styles.get_master_page()
    if first_master_page is None:
        raise ValueError, "no master page found"

    for i, filename in enumerate(filenames):
        # TODO folders and collections
Пример #12
0
        # Meta
        to_file = open(join(target, 'meta.txt'), 'wb')
        dump(document.get_formated_meta(), to_file)
        # Styles
        to_file = open(join(target, 'styles.txt'), 'wb')
        dump(document.show_styles(), to_file)
        # Pictures
        dump_pictures(document, target)
    else:
        if options.meta:
            dump(document.get_formated_meta(), stdout)
        if options.styles:
            dump(document.show_styles(), stdout)
    # text
    if doc_type in ('text', 'text-template', 'presentation',
                    'presentation-template'):
        if options.output:
            to_file = open(join(target, 'content.rst'), 'wb')
            dump(document.get_formatted_text(rst_mode=options.rst), to_file)
        elif not options.no_content:
            dump(document.get_formatted_text(rst_mode=options.rst), stdout)
    # spreadsheet
    elif doc_type in ('spreadsheet', 'spreadsheet-template'):
        if options.output:
            spreadsheet_to_csv(document, target)
        elif not options.no_content:
            spreadsheet_to_stdout(document)
    else:
        printerr("The OpenDocument format", doc_type, "is not supported yet.")
        exit(1)