From d3dd635a401caec12bd0bd48472cae9e5cdd8935 Mon Sep 17 00:00:00 2001 From: Lennart Regebro Date: Sun, 1 Dec 2024 12:16:25 +0100 Subject: [PATCH] Support nameless filter options --- CHANGES.rst | 2 +- README.rst | 2 +- src/unoserver/client.py | 4 ++-- src/unoserver/converter.py | 25 ++++++++++++++++++++----- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index cf3baad..002e2ae 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,7 +1,7 @@ 3.0.2 (unreleased) ------------------ -- Nothing changed yet. +- Support nameless filter options, eg for CSV export. 3.0.1 (2024-10-26) diff --git a/README.rst b/README.rst index 715dafd..6871884 100644 --- a/README.rst +++ b/README.rst @@ -127,7 +127,7 @@ Unoconvert * `--input-filter`: The LibreOffice input filter to use (ex 'writer8'), if autodetect fails * `--output-filter`: The export filter to use when converting. It is selected automatically if not specified. * `--filter`: Deprecated alias for `--output-filter` -* `--filter-option`: Pass an option for the export filter, in name=value format. Use true/false for boolean values. Can be repeated for multiple options. +* `--filter-option`: Pass an option for the export filter, in name=value format, or for positional parameters, a comma separated list. Use true/false for boolean values. Can be repeated for multiple options. * `--filter-options`: Deprecated alias for `--filter-option`. * `--host`: The host used by the server, defaults to "127.0.0.1" * `--port`: The port used by the server, defaults to "2003" diff --git a/src/unoserver/client.py b/src/unoserver/client.py index 8f39268..95486d0 100644 --- a/src/unoserver/client.py +++ b/src/unoserver/client.py @@ -286,8 +286,8 @@ def converter_main(): "--filter-option", default=[], action="append", - help="Pass an option for the export filter, in name=value format. Use true/false for boolean values. " - "Can be repeated for multiple options.", + help="Pass an option for the export filter, in name=value format, or for positional parameters, " + "a comma separated list. Use true/false for boolean values. Can be repeated for multiple options.", ) parser.add_argument( "--update-index", diff --git a/src/unoserver/converter.py b/src/unoserver/converter.py index 144630e..346f350 100644 --- a/src/unoserver/converter.py +++ b/src/unoserver/converter.py @@ -299,16 +299,28 @@ def convert( f"Using {filtername} export filter from {infiltername} to {export_type}" ) - filter_data = [] + export_filter_data = [] + export_filter_options = [] + for option in filter_options: - option_name, option_value = option.split("=", maxsplit=1) + if "=" in option: + option_name, option_value = option.split("=", maxsplit=1) + else: + option_name = None + option_value = option + if option_value == "false": option_value = False elif option_value == "true": option_value = True elif option_value.isdecimal(): option_value = int(option_value) - filter_data.append(PropertyValue(Name=option_name, Value=option_value)) + + if option_name is not None: + export_filter_data.append(PropertyValue(Name=option_name, Value=option_value)) + else: + export_filter_options.append(PropertyValue(Name="FilterOptions", Value=option_value)) + output_props = ( PropertyValue(Name="FilterName", Value=filtername), PropertyValue(Name="Overwrite", Value=True), @@ -318,15 +330,18 @@ def convert( output_props += ( PropertyValue(Name="OutputStream", Value=output_stream), ) - if filter_data: + if export_filter_data: output_props += ( PropertyValue( Name="FilterData", Value=uno.Any( - "[]com.sun.star.beans.PropertyValue", tuple(filter_data) + "[]com.sun.star.beans.PropertyValue", tuple(export_filter_data) ), ), ) + if export_filter_options: + output_props += tuple(export_filter_options) + document.storeToURL(export_path, output_props) finally: