synchronize: Allow user-defined --out-format #428
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SUMMARY
If the user specifes
--out-format
in the synchronize module'srsync_opts
return themsg
andstdout_lines
fields in the requested format. When no--out-format
is specified the default format for--itemize-changes
(%i %n%L
) is used.When the module is called with
diff: true
the returned diff will remain in the default format for--itemize-changes
.This is a change from the current behaviour that always forces an output format of
%i %n%L
regardless of user-specified values for--out-format
. This current behaviour was hard-coded in order to facilitate correctly setting thechanges
return value and having a fixed format fordiff: true
. I've endeavored to maintain the current behaviour for those purposes whilst additionally allowing user-defined formats.ISSUE TYPE
COMPONENT NAME
synchronize
ADDITIONAL INFORMATION
The generated
--out-format
attempts to combine:--out-format
DIFF
%i
itemize-changes field%n%L
filename and link information fields (if we are returning a diff or if no format was specified)seperated by a delimiter of
//
. No delimiter is completely safe for this purpose but I felt this one was sufficiently unlikely to appear the final three fields.I didn't attempt to use field widths for parsing given I've seen
rsync
versions with different widths for the%i
field. In fact this unreliability of the%i
field (added to the fact that it can contain internal spaces making the default pattern,%i %n%L
, also tricky to split on a delimiter) is the motivation for this change. I wanted to pass an--out-format
of{%-16i} %n
to synchronize to make programmatic parsing of the returned output easier but discovered that the module couldn't support it.I've avoided the use of some more modern Python syntax (
str.removeprefix()
,Match.__getitem__()
) because I'm developing against Python 2.7.18 and I imagine that I'm not alone in having to support old versions.