Skip to content

Commit

Permalink
support logging on Python 3.13 fixed #546
Browse files Browse the repository at this point in the history
As linked on #546,
Python 3.13 finally removed the deprecate `.warn()`, so we now need
to use `.warning()` instead.
  • Loading branch information
Stefan Betz committed Jun 7, 2024
1 parent 8eda9c8 commit c17f6e8
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ara/api/management/commands/prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def add_arguments(self, parser):
)

def handle(self, *args, **options):
logger.warn("This command has been replaced by 'ara playbook prune' in 1.5. It will be removed in 1.6.")
logger.warning("This command has been replaced by 'ara playbook prune' in 1.5. It will be removed in 1.6.")

client = options.get("client")
endpoint = options.get("endpoint")
Expand Down
4 changes: 3 additions & 1 deletion ara/cli/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ def get_parser(self, prog_name):
def take_action(self, args):
# TODO: Render json properly in pretty tables
if args.with_facts and args.formatter == "table":
self.log.warn("Rendering using default table formatter, use '-f yaml' or '-f json' for improved display.")
self.log.warning(
"Rendering using default table formatter, use '-f yaml' or '-f json' for improved display."
)

verify = False if args.insecure else True
if args.ssl_ca:
Expand Down
4 changes: 3 additions & 1 deletion ara/cli/playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ def get_parser(self, prog_name):
def take_action(self, args):
# TODO: Render json properly in pretty tables
if args.formatter == "table":
self.log.warn("Rendering using default table formatter, use '-f yaml' or '-f json' for improved display.")
self.log.warning(
"Rendering using default table formatter, use '-f yaml' or '-f json' for improved display."
)

verify = False if args.insecure else True
if args.ssl_ca:
Expand Down
4 changes: 3 additions & 1 deletion ara/cli/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def get_parser(self, prog_name):
def take_action(self, args):
# TODO: Render json properly in pretty tables
if args.formatter == "table":
self.log.warn("Rendering using default table formatter, use '-f yaml' or '-f json' for improved display.")
self.log.warning(
"Rendering using default table formatter, use '-f yaml' or '-f json' for improved display."
)

verify = False if args.insecure else True
if args.ssl_ca:
Expand Down
4 changes: 3 additions & 1 deletion ara/cli/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ def get_parser(self, prog_name):
def take_action(self, args):
# TODO: Render json properly in pretty tables
if args.with_content and args.formatter == "table":
self.log.warn("Rendering using default table formatter, use '-f yaml' or '-f json' for improved display.")
self.log.warning(
"Rendering using default table formatter, use '-f yaml' or '-f json' for improved display."
)

verify = False if args.insecure else True
if args.ssl_ca:
Expand Down
8 changes: 4 additions & 4 deletions ara/plugins/callback/ara_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def v2_playbook_on_play_start(self, play):
# https://github.com/ansible-community/ara/issues/185
# https://github.com/ansible-community/ara/issues/265
if len(play_vars["ara_playbook_name"]) >= 255:
self.log.warn("Truncating playbook name before recording: it's longer than 255 characters")
self.log.warning("Truncating playbook name before recording: it's longer than 255 characters")

self.playbook = self.client.patch(
"/api/v1/playbooks/%s" % self.playbook["id"], name=play_vars["ara_playbook_name"][:254]
Expand All @@ -482,7 +482,7 @@ def v2_playbook_on_play_start(self, play):
# https://github.com/ansible-community/ara/issues/185
# https://github.com/ansible-community/ara/issues/265
if len(play.name) >= 255:
self.log.warn("Truncating play name before recording: it's longer than 255 characters")
self.log.warning("Truncating play name before recording: it's longer than 255 characters")
play.name = play.name[:254]

labels = self.default_labels + self.argument_labels
Expand Down Expand Up @@ -680,7 +680,7 @@ def _set_playbook_labels(self, labels):
expected_labels = []
for label in labels:
if len(label) >= 255:
self.log.warn("Truncating label name before recording: it's longer than 255 characters (%s)" % label)
self.log.warning("Truncating label name before recording: it's longer than 255 characters (%s)" % label)
label = label[:254]
expected_labels.append(label)

Expand Down Expand Up @@ -724,7 +724,7 @@ def _get_or_create_host(self, host):
if len(host) >= 255:
# Only warn about this once so we don't print a warning on every task
if host not in self.warned_about_host_length:
self.log.warn("Truncating hostname before recording: it's longer than 255 characters (%s)" % host)
self.log.warning("Truncating hostname before recording: it's longer than 255 characters (%s)" % host)
self.warned_about_host_length.append(host)
host = host[:254]

Expand Down
8 changes: 4 additions & 4 deletions ara/server/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def distributed_sqlite(environ, start_response):
return default_application(environ, start_response)

if prefix not in path_info:
logger.warn("Ignoring request: URL does not contain delegated prefix (%s)" % prefix)
logger.warning("Ignoring request: URL does not contain delegated prefix (%s)" % prefix)
return handle_404(start_response)

# Slice path_info up until after the prefix to obtain the requested directory
Expand All @@ -75,16 +75,16 @@ def distributed_sqlite(environ, start_response):
# Make sure we aren't escaping outside the root and the directory exists
db_dir = os.path.abspath(os.path.join(root, fs_path.lstrip("/")))
if not db_dir.startswith(root):
logger.warn("Ignoring request: path is outside the root (%s)" % db_dir)
logger.warning("Ignoring request: path is outside the root (%s)" % db_dir)
return handle_404(start_response)
elif not os.path.exists(db_dir):
logger.warn("Ignoring request: database directory not found (%s)" % db_dir)
logger.warning("Ignoring request: database directory not found (%s)" % db_dir)
return handle_404(start_response)

# Find the database file and make sure it exists
db_file = os.path.join(db_dir, "ansible.sqlite")
if not os.path.exists(db_file):
logger.warn("Ignoring request: database file not found (%s)" % db_file)
logger.warning("Ignoring request: database file not found (%s)" % db_file)
return handle_404(start_response)

# Tell Django about the new URLs it should be using
Expand Down

0 comments on commit c17f6e8

Please sign in to comment.