chore(keyringctl): uniformly use path builder via operator

Instead of partially dealing with strings that contain slashes lets just
use the path builder interface by using the operator for every sub path
layer in a uniform way.
This commit is contained in:
Levente Polyak 2021-10-13 00:09:58 +02:00
parent c86832f3a1
commit cc26ca503c
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8

View File

@ -385,6 +385,7 @@ def persist_public_key(
packets: List[Path] = [pubkey] packets: List[Path] = [pubkey]
output_file = key_dir / f'{certificate_fingerprint}.asc' output_file = key_dir / f'{certificate_fingerprint}.asc'
output_file.parent.mkdir(parents=True, exist_ok=True)
debug(f'Writing file {output_file} from {[str(packet) for packet in packets]}') debug(f'Writing file {output_file} from {[str(packet) for packet in packets]}')
packet_join(packets, output_file) packet_join(packets, output_file)
@ -411,8 +412,8 @@ def persist_uids(
for key in uid_binding_sigs.keys(): for key in uid_binding_sigs.keys():
packets = [uids[key], uid_binding_sigs[key]] packets = [uids[key], uid_binding_sigs[key]]
output_file = key_dir / f'uid/{key}/{key}.asc' output_file = key_dir / 'uid' / key / f'{key}.asc'
(key_dir / Path(f'uid/{key}')).mkdir(parents=True, exist_ok=True) output_file.parent.mkdir(parents=True, exist_ok=True)
debug(f'Writing file {output_file} from {[str(packet) for packet in packets]}') debug(f'Writing file {output_file} from {[str(packet) for packet in packets]}')
packet_join(packets, output_file) packet_join(packets, output_file)
@ -441,9 +442,9 @@ def persist_subkeys(
for signature, subkey in subkeys[certificate_fingerprint].items(): for signature, subkey in subkeys[certificate_fingerprint].items():
packets: List[Path] = [] packets: List[Path] = []
packets.extend([subkey, subkey_binding_sigs[certificate_fingerprint][signature]]) packets.extend([subkey, subkey_binding_sigs[certificate_fingerprint][signature]])
output_file = key_dir / Path(f'subkey/{signature}/{signature}.asc') output_file = key_dir / 'subkey' / signature / f'{signature}.asc'
output_file.parent.mkdir(parents=True, exist_ok=True)
debug(f'Writing file {output_file} from {[str(packet) for packet in packets]}') debug(f'Writing file {output_file} from {[str(packet) for packet in packets]}')
(key_dir / Path(f"subkey/{signature}")).mkdir(parents=True, exist_ok=True)
packet_join(packets=packets, output=output_file) packet_join(packets=packets, output=output_file)
@ -467,9 +468,9 @@ def persist_subkey_revocations(
if subkey_revocations.get(certificate_fingerprint): if subkey_revocations.get(certificate_fingerprint):
for signature, revocation in subkey_revocations[certificate_fingerprint].items(): for signature, revocation in subkey_revocations[certificate_fingerprint].items():
issuer = packet_dump_field(revocation, 'Issuer') issuer = packet_dump_field(revocation, 'Issuer')
output_file = (key_dir / Path(f'subkey/{signature}/revocation/{issuer}.asc')) output_file = key_dir / 'subkey' / signature / 'revocation' / f'{issuer}.asc'
output_file.parent.mkdir(parents=True, exist_ok=True)
debug(f'Writing file {output_file} from {revocation}') debug(f'Writing file {output_file} from {revocation}')
(key_dir / Path(f"subkey/{signature}/revocation")).mkdir(parents=True, exist_ok=True)
packet_join(packets=[revocation], output=output_file) packet_join(packets=[revocation], output=output_file)
@ -496,10 +497,9 @@ def persist_direct_sigs(
for key, current_certifications in direct_sigs.items(): for key, current_certifications in direct_sigs.items():
for issuer, certifications in current_certifications.items(): for issuer, certifications in current_certifications.items():
direct_key_dir = key_dir / sig_type
direct_key_dir.mkdir(parents=True, exist_ok=True)
packets = [pubkey] + certifications packets = [pubkey] + certifications
output_file = direct_key_dir / f'{issuer}.asc' output_file = key_dir / sig_type / f'{issuer}.asc'
output_file.parent.mkdir(parents=True, exist_ok=True)
debug(f'Writing file {output_file} from {[str(cert) for cert in certifications]}') debug(f'Writing file {output_file} from {[str(cert) for cert in certifications]}')
packet_join(packets, output_file) packet_join(packets, output_file)
@ -783,7 +783,7 @@ def keyring_import(working_dir: Path, source: Path, keyring_root: Path) -> None:
keyring_root: Path keyring_root: Path
The root directory path of the local keyring The root directory path of the local keyring
""" """
target_dir = keyring_root / Path('packager') target_dir = keyring_root / 'packager'
target_dir.mkdir(parents=True, exist_ok=True) target_dir.mkdir(parents=True, exist_ok=True)
convert(working_dir, source, target_dir) convert(working_dir, source, target_dir)