feature(keyringctl): improve packet_join to optionally return the result

This commit is contained in:
Levente Polyak 2021-10-21 20:19:33 +02:00
parent deaa312b7d
commit 52178f38d5
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8

View File

@ -668,17 +668,22 @@ def packet_split(working_dir: Path, certificate: Path) -> Iterable[Path]:
return natural_sort_path(packet_dir.iterdir())
def packet_join(packets: List[Path], output: Path, force: bool = False) -> None:
def packet_join(packets: List[Path], output: Optional[Path] = None, force: bool = False) -> str:
"""Join PGP packet data in files to a single output file
Parameters
----------
packets: List[Path]
A list of paths to files that contain PGP packet data
output: Path
A file to which all PGP packet data is written
output: Optional[Path]
Path to a file to which all PGP packet data is written, return the result instead if None
force: bool
Whether to force the execution of sq (defaults to False)
Returns
-------
str
The result if no output file has been used
"""
cmd = ["sq", "packet", "join"]
@ -687,7 +692,7 @@ def packet_join(packets: List[Path], output: Path, force: bool = False) -> None:
packets_str = list(map(lambda path: str(path), packets))
cmd.extend(packets_str)
cmd.extend(["--output", str(output)])
system(cmd, exit_on_error=False)
return system(cmd, exit_on_error=False)
def simplify_user_id(user_id: Uid) -> Uid: