Skip to content
Snippets Groups Projects
Commit 89f6b9de authored by Moul's avatar Moul
Browse files

[mod] #194: {cli,crypto}_tools: Use f-string

parent 4bc8a211
No related branches found
No related tags found
1 merge request!195#194, #376: Use f-string and sys.exit()
...@@ -22,17 +22,16 @@ class MutuallyExclusiveOption(Option): ...@@ -22,17 +22,16 @@ class MutuallyExclusiveOption(Option):
help = kwargs.get("help", "") help = kwargs.get("help", "")
if self.mutually_exclusive: if self.mutually_exclusive:
ex_str = ", ".join(self.mutually_exclusive) ex_str = ", ".join(self.mutually_exclusive)
kwargs["help"] = help + ( kwargs[
" NOTE: This argument is mutually exclusive with " "help"
" arguments: [" + ex_str + "]." ] = f"{help} NOTE: This argument is mutually exclusive with arguments: [{ex_str}]."
)
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def handle_parse_result(self, ctx, opts, args): def handle_parse_result(self, ctx, opts, args):
if self.mutually_exclusive.intersection(opts) and self.name in opts: if self.mutually_exclusive.intersection(opts) and self.name in opts:
arguments = ", ".join(self.mutually_exclusive)
raise UsageError( raise UsageError(
"Usage: `{}` is mutually exclusive with " f"Usage: `{self.name}` is mutually exclusive with arguments `{arguments}`."
"arguments `{}`.".format(self.name, ", ".join(self.mutually_exclusive))
) )
return super().handle_parse_result(ctx, opts, args) return super().handle_parse_result(ctx, opts, args)
...@@ -51,7 +51,7 @@ def check_pubkey_format(pubkey, display_error=True): ...@@ -51,7 +51,7 @@ def check_pubkey_format(pubkey, display_error=True):
elif re.search(re.compile(PUBKEY_CHECKSUM_PATTERN), pubkey): elif re.search(re.compile(PUBKEY_CHECKSUM_PATTERN), pubkey):
return True return True
elif display_error: elif display_error:
message_exit("Error: bad format for following public key: " + pubkey) message_exit(f"Error: bad format for following public key: {pubkey}")
return return
...@@ -65,11 +65,8 @@ def validate_checksum(pubkey_checksum): ...@@ -65,11 +65,8 @@ def validate_checksum(pubkey_checksum):
if checksum == gen_checksum(pubkey): if checksum == gen_checksum(pubkey):
return pubkey return pubkey
message_exit( message_exit(
"Error: public key '" f"Error: public key '{pubkey}' does not match checksum '{checksum}'.\n\
+ pubkey Please verify the public key."
+ "' does not match checksum '"
+ checksum
+ "'.\nPlease verify the public key."
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment