Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nameless filter options #150

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/unoserver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 20 additions & 5 deletions src/unoserver/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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:
Expand Down