Skip to content

Commit

Permalink
Run ruff check --fix --unsafe-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaily committed Dec 23, 2024
1 parent 078bfe3 commit be98541
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 39 deletions.
5 changes: 2 additions & 3 deletions awscli/customizations/gamelift/getlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def _run_main(self, args, parsed_globals):
contents = urlopen(url)

sys.stdout.write(
'Downloading log archive for game session %s...\r' %
args.game_session_id
f'Downloading log archive for game session {args.game_session_id}...\r'
)

with open(args.save_as, 'wb') as f:
Expand All @@ -53,6 +52,6 @@ def _run_main(self, args, parsed_globals):

sys.stdout.write(
'Successfully downloaded log archive for game '
'session %s to %s\n' % (args.game_session_id, args.save_as))
f'session {args.game_session_id} to {args.save_as}\n')

return 0
14 changes: 5 additions & 9 deletions awscli/customizations/gamelift/uploadbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ def _run_main(self, args, parsed_globals):
# Validate a build directory
if not validate_directory(args.build_root):
sys.stderr.write(
'Fail to upload %s. '
f'Fail to upload {args.build_root}. '
'The build root directory is empty or does not exist.\n'
% (args.build_root)
)

return 255
Expand Down Expand Up @@ -92,7 +91,7 @@ def _run_main(self, args, parsed_globals):
s3_transfer_mgr = S3Transfer(s3_client)

try:
fd, temporary_zipfile = tempfile.mkstemp('%s.zip' % build_id)
fd, temporary_zipfile = tempfile.mkstemp(f'{build_id}.zip')
zip_directory(temporary_zipfile, args.build_root)
s3_transfer_mgr.upload_file(
temporary_zipfile, bucket, key,
Expand All @@ -106,8 +105,8 @@ def _run_main(self, args, parsed_globals):
os.remove(temporary_zipfile)

sys.stdout.write(
'Successfully uploaded %s to AWS GameLift\n'
'Build ID: %s\n' % (args.build_root, build_id))
f'Successfully uploaded {args.build_root} to AWS GameLift\n'
f'Build ID: {build_id}\n')

return 0

Expand Down Expand Up @@ -156,9 +155,6 @@ def __call__(self, bytes_amount):
if self._size > 0:
percentage = (self._seen_so_far / self._size) * 100
sys.stdout.write(
"\r%s %s / %s (%.2f%%)" % (
self._label, human_readable_size(self._seen_so_far),
human_readable_size(self._size), percentage
)
f"\r{self._label} {human_readable_size(self._seen_so_far)} / {human_readable_size(self._size)} ({percentage:.2f}%)"
)
sys.stdout.flush()
2 changes: 1 addition & 1 deletion awscli/customizations/history/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

class HistorySubcommand(BasicCommand):
def __init__(self, session, db_reader=None, output_stream_factory=None):
super(HistorySubcommand, self).__init__(session)
super().__init__(session)
self._db_reader = db_reader
self._output_stream_factory = output_stream_factory
if output_stream_factory is None:
Expand Down
21 changes: 9 additions & 12 deletions awscli/customizations/history/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _remove_non_unicode_stings(self, obj):

def encode(self, obj):
try:
return super(PayloadSerializer, self).encode(obj)
return super().encode(obj)
except UnicodeDecodeError:
# This happens in PY2 in the case where a record payload has some
# binary data in it that is not utf-8 encodable. PY2 will not call
Expand All @@ -114,7 +114,7 @@ def encode(self, obj):
# ourselves and replace all strings that are not utf-8 decodable
# and try to encode again.
scrubbed_obj = self._remove_non_unicode_stings(obj)
return super(PayloadSerializer, self).encode(scrubbed_obj)
return super().encode(scrubbed_obj)

def default(self, obj):
if isinstance(obj, datetime.datetime):
Expand Down Expand Up @@ -167,12 +167,12 @@ def _create_db_record(self, record):

class DatabaseRecordReader:
_ORDERING = 'ORDER BY timestamp'
_GET_LAST_ID_RECORDS = """
_GET_LAST_ID_RECORDS = f"""
SELECT * FROM records
WHERE id =
(SELECT id FROM records WHERE timestamp =
(SELECT max(timestamp) FROM records)) %s;""" % _ORDERING
_GET_RECORDS_BY_ID = 'SELECT * from records where id = ? %s' % _ORDERING
(SELECT max(timestamp) FROM records)) {_ORDERING};"""
_GET_RECORDS_BY_ID = f'SELECT * from records where id = ? {_ORDERING}'
_GET_ALL_RECORDS = (
'SELECT a.id AS id_a, '
' b.id AS id_b, '
Expand All @@ -183,7 +183,7 @@ class DatabaseRecordReader:
'where a.event_type == "CLI_ARGUMENTS" AND '
' b.event_type = "CLI_RC" AND '
' id_a == id_b '
'%s DESC' % _ORDERING
f'{_ORDERING} DESC'
)

def __init__(self, connection):
Expand All @@ -204,18 +204,15 @@ def _row_factory(self, cursor, row):

def iter_latest_records(self):
cursor = self._connection.execute(self._GET_LAST_ID_RECORDS)
for row in cursor:
yield row
yield from cursor

def iter_records(self, record_id):
cursor = self._connection.execute(self._GET_RECORDS_BY_ID, [record_id])
for row in cursor:
yield row
yield from cursor

def iter_all_records(self):
cursor = self._connection.execute(self._GET_ALL_RECORDS)
for row in cursor:
yield row
yield from cursor


class RecordBuilder:
Expand Down
4 changes: 2 additions & 2 deletions awscli/customizations/history/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ def _format_args(self, args, arg_width):
json_value = json.loads(args)
formatted = ' '.join(json_value[:2])
if len(formatted) >= arg_width:
formatted = '%s...' % formatted[:arg_width-4]
formatted = f'{formatted[:arg_width-4]}...'
return formatted

def _format_record(self, record):
fmt_string = "{0:<%s}{1:<%s}{2:<%s}{3}\n" % (
fmt_string = "{{0:<{}}}{{1:<{}}}{{2:<{}}}{{3}}\n".format(
self._col_widths['id_a'],
self._col_widths['timestamp'],
self._col_widths['args']
Expand Down
4 changes: 2 additions & 2 deletions awscli/customizations/history/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class DetailedFormatter(Formatter):
}

def __init__(self, output=None, include=None, exclude=None, colorize=True):
super(DetailedFormatter, self).__init__(output, include, exclude)
super().__init__(output, include, exclude)
self._request_id_to_api_num = {}
self._num_api_calls = 0
self._colorize = colorize
Expand Down Expand Up @@ -219,7 +219,7 @@ def _format_section_title(self, title, event_record):
formatted_title = title
api_num = self._get_api_num(event_record)
if api_num is not None:
formatted_title = ('[%s] ' % api_num) + formatted_title
formatted_title = (f'[{api_num}] ') + formatted_title
formatted_title = self._color_if_configured(formatted_title, 'title')
formatted_title += '\n'

Expand Down
2 changes: 1 addition & 1 deletion awscli/customizations/logs/startlivetail.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ class StartLiveTailCommand(BasicCommand):
]

def __init__(self, session):
super(StartLiveTailCommand, self).__init__(session)
super().__init__(session)
self._output = get_stdout_text_writer()

def _get_client(self, parsed_globals):
Expand Down
16 changes: 7 additions & 9 deletions awscli/customizations/logs/tail.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _ensure_single_newline_ending(self, log):

class ShortLogEventsFormatter(BaseLogEventsFormatter):
def display_log_event(self, log_event):
log_event = '%s %s' % (
log_event = '{} {}'.format(
self._format_timestamp(log_event['timestamp']),
log_event['message']
)
Expand All @@ -67,7 +67,7 @@ def _format_timestamp(self, timestamp):

class DetailedLogEventsFormatter(BaseLogEventsFormatter):
def display_log_event(self, log_event):
log_event = '%s %s %s' % (
log_event = '{} {} {}'.format(
self._format_timestamp(log_event['timestamp']),
self._color_if_configured(
log_event['logStreamName'], self._STREAM_NAME_COLOR),
Expand All @@ -84,7 +84,7 @@ def _format_timestamp(self, timestamp):

class PrettyJSONLogEventsFormatter(BaseLogEventsFormatter):
def display_log_event(self, log_event):
log_event = '%s %s %s' % (
log_event = '{} {} {}'.format(
self._format_timestamp(log_event['timestamp']),
self._color_if_configured(
log_event['logStreamName'], self._STREAM_NAME_COLOR),
Expand All @@ -95,7 +95,7 @@ def display_log_event(self, log_event):
def _format_pretty_json(self, log_message):
try:
loaded_json = json.loads(log_message)
return '\n%s' % json.dumps(loaded_json, indent=4)
return f'\n{json.dumps(loaded_json, indent=4)}'
except json.decoder.JSONDecodeError:
pass
return log_message
Expand Down Expand Up @@ -328,23 +328,21 @@ class NoFollowLogEventsGenerator(BaseLogEventsGenerator):
def _filter_log_events(self, filter_logs_events_kwargs):
paginator = self._client.get_paginator('filter_log_events')
for page in paginator.paginate(**filter_logs_events_kwargs):
for log_event in page['events']:
yield log_event
yield from page['events']


class FollowLogEventsGenerator(BaseLogEventsGenerator):
_TIME_TO_SLEEP = 5

def __init__(self, client, timestamp_utils, sleep=None):
super(FollowLogEventsGenerator, self).__init__(client, timestamp_utils)
super().__init__(client, timestamp_utils)
self._sleep = sleep
if sleep is None:
self._sleep = time.sleep

def _filter_log_events(self, filter_logs_events_kwargs):
try:
for event in self._do_filter_log_events(filter_logs_events_kwargs):
yield event
yield from self._do_filter_log_events(filter_logs_events_kwargs)
except KeyboardInterrupt:
# The only way to exit from the --follow is to Ctrl-C. So
# we should exit the iterator rather than having the
Expand Down

0 comments on commit be98541

Please sign in to comment.