ruff: Fix G003 Logging statement uses +.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-28 16:05:44 -07:00
parent 02e0555e0d
commit d85ace8e7e
3 changed files with 25 additions and 29 deletions

View file

@ -109,14 +109,14 @@ class JabberToZulipBot(ClientXMPP):
def join_muc(self, room: str) -> None: def join_muc(self, room: str) -> None:
if room in self.rooms: if room in self.rooms:
return return
logging.debug("Joining " + room) logging.debug("Joining %s", room)
self.rooms.add(room) self.rooms.add(room)
muc_jid = JID(local=room, domain=options.conference_domain) muc_jid = JID(local=room, domain=options.conference_domain)
xep0045 = self.plugin["xep_0045"] xep0045 = self.plugin["xep_0045"]
try: try:
xep0045.joinMUC(muc_jid, self.nick, wait=True) xep0045.joinMUC(muc_jid, self.nick, wait=True)
except InvalidJID: except InvalidJID:
logging.error("Could not join room: " + str(muc_jid)) logging.error("Could not join room: %s", muc_jid)
return return
# Configure the room. Really, we should only do this if the room is # Configure the room. Really, we should only do this if the room is
@ -129,12 +129,12 @@ class JabberToZulipBot(ClientXMPP):
if form: if form:
xep0045.configureRoom(muc_jid, form) xep0045.configureRoom(muc_jid, form)
else: else:
logging.error("Could not configure room: " + str(muc_jid)) logging.error("Could not configure room: %s", muc_jid)
def leave_muc(self, room: str) -> None: def leave_muc(self, room: str) -> None:
if room not in self.rooms: if room not in self.rooms:
return return
logging.debug("Leaving " + room) logging.debug("Leaving %s", room)
self.rooms.remove(room) self.rooms.remove(room)
muc_jid = JID(local=room, domain=options.conference_domain) muc_jid = JID(local=room, domain=options.conference_domain)
self.plugin["xep_0045"].leaveMUC(muc_jid, self.nick) self.plugin["xep_0045"].leaveMUC(muc_jid, self.nick)

View file

@ -707,11 +707,11 @@ def send_zephyr(zwrite_args: List[str], content: str) -> Tuple[int, str]:
p.returncode, p.returncode,
) )
if stdout: if stdout:
logger.info("stdout: " + stdout) logger.info("stdout: %s", stdout)
elif stderr: elif stderr:
logger.warning("zwrite command %r printed the following warning:", zwrite_args) logger.warning("zwrite command %r printed the following warning:", zwrite_args)
if stderr: if stderr:
logger.warning("stderr: " + stderr) logger.warning("stderr: %s", stderr)
return (p.returncode, stderr) return (p.returncode, stderr)
@ -1027,8 +1027,7 @@ def add_zulip_subscriptions(verbose: bool) -> None:
logger.info("\nSuccessfully subscribed to: %s", ", ".join(list(new.values())[0])) logger.info("\nSuccessfully subscribed to: %s", ", ".join(list(new.values())[0]))
if unauthorized is not None and len(unauthorized) > 0: if unauthorized is not None and len(unauthorized) > 0:
logger.info( logger.info(
"\n" "\n%s\n\n %s",
+ "\n".join(
textwrap.wrap( textwrap.wrap(
"""\ """\
The following streams you have NOT been subscribed to, The following streams you have NOT been subscribed to,
@ -1040,16 +1039,15 @@ If you wish to read these streams in Zulip, you need to contact the people who a
on these streams and already use Zulip. They can subscribe you to them via the on these streams and already use Zulip. They can subscribe you to them via the
"streams" page in the Zulip web interface: "streams" page in the Zulip web interface:
""" """
) ),
) ", ".join(unauthorized),
+ "\n\n {}".format(", ".join(unauthorized))
) )
if len(skipped) > 0: if len(skipped) > 0:
if verbose: if verbose:
logger.info( logger.info(
"\n" "\n%s\n",
+ "\n".join( "\n".join(
textwrap.wrap( textwrap.wrap(
"""\ """\
You have some lines in ~/.zephyr.subs that could not be You have some lines in ~/.zephyr.subs that could not be
@ -1062,8 +1060,7 @@ stream, so this tool has not created a corresponding
Zulip subscription to these lines in ~/.zephyr.subs: Zulip subscription to these lines in ~/.zephyr.subs:
""" """
) )
) ),
+ "\n"
) )
for cls, instance, recipient, reason in skipped: for cls, instance, recipient, reason in skipped:
@ -1075,8 +1072,8 @@ Zulip subscription to these lines in ~/.zephyr.subs:
if len(skipped) > 0: if len(skipped) > 0:
if verbose: if verbose:
logger.info( logger.info(
"\n" "\n%s\n",
+ "\n".join( "\n".join(
textwrap.wrap( textwrap.wrap(
"""\ """\
If you wish to be subscribed to any Zulip streams related If you wish to be subscribed to any Zulip streams related
@ -1084,8 +1081,7 @@ to these .zephyrs.subs lines, please do so via the Zulip
web interface. web interface.
""" """
) )
) ),
+ "\n"
) )
@ -1265,15 +1261,15 @@ if __name__ == "__main__":
else: else:
if not os.path.exists(options.api_key_file): if not os.path.exists(options.api_key_file):
logger.error( logger.error(
"\n" "\n%s",
+ "\n".join( "\n".join(
textwrap.wrap( textwrap.wrap(
f"""\ f"""\
Could not find API key file. Could not find API key file.
You need to either place your api key file at {options.api_key_file}, You need to either place your api key file at {options.api_key_file},
or specify the --api-key-file option.""" or specify the --api-key-file option."""
) )
) ),
) )
sys.exit(1) sys.exit(1)
api_key = open(options.api_key_file).read().strip() api_key = open(options.api_key_file).read().strip()
@ -1282,7 +1278,7 @@ or specify the --api-key-file option."""
os.environ["HUMBUG_API_KEY"] = api_key os.environ["HUMBUG_API_KEY"] = api_key
if options.nagios_path is None and options.nagios_class is not None: if options.nagios_path is None and options.nagios_class is not None:
logger.error("\n" + "nagios_path is required with nagios_class\n") logger.error("\nnagios_path is required with nagios_class\n")
sys.exit(1) sys.exit(1)
zulip_account_email = options.user + "@mit.edu" zulip_account_email = options.user + "@mit.edu"

View file

@ -48,10 +48,10 @@ def make_API_request(
and "error" in r.json() and "error" in r.json()
and r.json()["error"] == "Invalid API Authentication" and r.json()["error"] == "Invalid API Authentication"
): ):
logging.error("Error authenticating, please check key " + str(r.url)) logging.error("Error authenticating, please check key %s", r.url)
raise AuthenticationException raise AuthenticationException
else: else:
logging.error("Error make API request, code " + str(r.status_code) + ". json: " + r.json()) logging.error("Error make API request, code %s. json: %s", r.status_code, r.json())
raise UnspecifiedProblemException raise UnspecifiedProblemException
@ -242,9 +242,9 @@ Below are some of the commands you can use, and what they do.
"Sorry, I don't understand what your trying to say. Use `@mention help` to see my help. " "Sorry, I don't understand what your trying to say. Use `@mention help` to see my help. "
+ e.detail + e.detail
) )
except Exception as e: # catches UnspecifiedProblemException, and other problems except Exception: # catches UnspecifiedProblemException, and other problems
reply = "Oh dear, I'm having problems processing your request right now. Perhaps you could try again later :grinning:" reply = "Oh dear, I'm having problems processing your request right now. Perhaps you could try again later :grinning:"
logging.error("Exception caught: " + str(e)) logging.exception("Exception caught")
return reply return reply