diff --git a/alertaclient/api.py b/alertaclient/api.py index 965bb55..4ab8e47 100644 --- a/alertaclient/api.py +++ b/alertaclient/api.py @@ -150,22 +150,22 @@ def alert_note(self, id, text): data = { 'text': text } - r = self.http.put('/alert/{}/note'.format(id), data) + r = self.http.put(f'/alert/{id}/note', data) return Note.parse(r['note']) def get_alert_notes(self, id, page=1, page_size=None): - r = self.http.get('/alert/{}/notes'.format(id), page=page, page_size=page_size) + r = self.http.get(f'/alert/{id}/notes', page=page, page_size=page_size) return [Note.parse(n) for n in r['notes']] def update_alert_note(self, id, note_id, text): data = { 'text': text, } - r = self.http.put('/alert/{}/note/{}'.format(id, note_id), data) + r = self.http.put(f'/alert/{id}/note/{note_id}', data) return Note.parse(r['note']) def delete_alert_note(self, id, note_id): - return self.http.delete('/alert/{}/note/{}'.format(id, note_id)) + return self.http.delete(f'/alert/{id}/note/{note_id}') # Blackouts def create_blackout(self, environment, service=None, resource=None, event=None, group=None, tags=None, @@ -208,7 +208,7 @@ def update_blackout(self, id, **kwargs): 'text': kwargs.get('text'), } - r = self.http.put('/blackout/{}'.format(id), data) + r = self.http.put(f'/blackout/{id}', data) return Blackout.parse(r['blackout']) def delete_blackout(self, id): @@ -235,7 +235,7 @@ def update_customer(self, id, **kwargs): 'match': kwargs.get('match'), 'customer': kwargs.get('customer') } - r = self.http.put('/customer/{}'.format(id), data) + r = self.http.put(f'/customer/{id}', data) return Customer.parse(r['customer']) def delete_customer(self, id): @@ -292,7 +292,7 @@ def update_key(self, id, **kwargs): 'expireTime': kwargs.get('expireTime'), 'customer': kwargs.get('customer') } - r = self.http.put('/key/{}'.format(id), data) + r = self.http.put(f'/key/{id}', data) return ApiKey.parse(r['key']) def delete_key(self, id): @@ -319,7 +319,7 @@ def update_perm(self, id, **kwargs): 'match': kwargs.get('match'), # role 'scopes': kwargs.get('scopes') } - r = self.http.put('/perm/{}'.format(id), data) + r = self.http.put(f'/perm/{id}', data) return Permission.parse(r['permission']) def delete_perm(self, id): @@ -359,7 +359,7 @@ def get_user(self, id): return User.parse(self.http.get('/user/%s' % id)['user']) def get_user_groups(self, id): - r = self.http.get('/user/{}/groups'.format(id)) + r = self.http.get(f'/user/{id}/groups') return [Group.parse(g) for g in r['groups']] def get_me(self): @@ -383,7 +383,7 @@ def update_user(self, id, **kwargs): 'text': kwargs.get('text'), 'email_verified': kwargs.get('email_verified') } - r = self.http.put('/user/{}'.format(id), data) + r = self.http.put(f'/user/{id}', data) return User.parse(r['user']) def update_me(self, **kwargs): @@ -452,7 +452,7 @@ def get_group(self): return Group.parse(self.http.get('/group/%s' % id)['group']) def get_group_users(self, id): - r = self.http.get('/group/{}/users'.format(id)) + r = self.http.get(f'/group/{id}/users') return [User.parse(u) for u in r['users']] def get_users_groups(self, query=None): @@ -464,14 +464,14 @@ def update_group(self, id, **kwargs): 'name': kwargs.get('name'), 'text': kwargs.get('text') } - r = self.http.put('/group/{}'.format(id), data) + r = self.http.put(f'/group/{id}', data) return Group.parse(r['group']) def add_user_to_group(self, group_id, user_id): - return self.http.put('/group/{}/user/{}'.format(group_id, user_id)) + return self.http.put(f'/group/{group_id}/user/{user_id}') def remove_user_from_group(self, group_id, user_id): - return self.http.delete('/group/{}/user/{}'.format(group_id, user_id)) + return self.http.delete(f'/group/{group_id}/user/{user_id}') def delete_group(self, id): return self.http.delete('/group/%s' % id) @@ -500,7 +500,7 @@ def __init__(self, api_key=None, auth_token=None): self.auth_token = auth_token def __call__(self, r): - r.headers['Authorization'] = 'Key {}'.format(self.api_key) + r.headers['Authorization'] = f'Key {self.api_key}' return r @@ -510,7 +510,7 @@ def __init__(self, auth_token=None): self.auth_token = auth_token def __call__(self, r): - r.headers['Authorization'] = 'Bearer {}'.format(self.auth_token) + r.headers['Authorization'] = f'Bearer {self.auth_token}' return r @@ -608,7 +608,7 @@ def delete(self, path): def _handle_error(self, response): if self.debug: - print('\nbody: {}'.format(response.text)) + print(f'\nbody: {response.text}') resp = response.json() status = resp.get('status', None) if status == 'ok': diff --git a/alertaclient/auth/utils.py b/alertaclient/auth/utils.py index 2fa85e1..d966cf5 100644 --- a/alertaclient/auth/utils.py +++ b/alertaclient/auth/utils.py @@ -29,7 +29,7 @@ def save_token(endpoint, username, token): try: info = netrc(NETRC_FILE) except Exception as e: - raise ConfigurationError('{}'.format(e)) + raise ConfigurationError(f'{e}') info.hosts[machine(endpoint)] = (username, None, token) with open(NETRC_FILE, 'w') as f: f.write(dump_netrc(info)) @@ -39,13 +39,13 @@ def clear_token(endpoint): try: info = netrc(NETRC_FILE) except Exception as e: - raise ConfigurationError('{}'.format(e)) + raise ConfigurationError(f'{e}') try: del info.hosts[machine(endpoint)] with open(NETRC_FILE, 'w') as f: f.write(dump_netrc(info)) except KeyError as e: - raise ConfigurationError('No credentials stored for {}'.format(e)) + raise ConfigurationError(f'No credentials stored for {e}') # See https://bugs.python.org/issue30806 diff --git a/alertaclient/commands/cmd_ack.py b/alertaclient/commands/cmd_ack.py index aaf58ee..1797020 100644 --- a/alertaclient/commands/cmd_ack.py +++ b/alertaclient/commands/cmd_ack.py @@ -22,4 +22,4 @@ def cli(obj, ids, query, filters, text): total, _, _ = client.get_count(query) ids = [a.id for a in client.get_alerts(query)] - action_progressbar(client, action='ack', ids=ids, label='Acking {} alerts'.format(total), text=text) + action_progressbar(client, action='ack', ids=ids, label=f'Acking {total} alerts', text=text) diff --git a/alertaclient/commands/cmd_action.py b/alertaclient/commands/cmd_action.py index 55095e9..be4b29b 100644 --- a/alertaclient/commands/cmd_action.py +++ b/alertaclient/commands/cmd_action.py @@ -23,5 +23,5 @@ def cli(obj, action, ids, query, filters, text): total, _, _ = client.get_count(query) ids = [a.id for a in client.get_alerts(query)] - label = 'Action ({}) {} alerts'.format(action, total) + label = f'Action ({action}) {total} alerts' action_progressbar(client, action=action, ids=ids, label=label, text=text) diff --git a/alertaclient/commands/cmd_blackout.py b/alertaclient/commands/cmd_blackout.py index 2810efc..697a4df 100644 --- a/alertaclient/commands/cmd_blackout.py +++ b/alertaclient/commands/cmd_blackout.py @@ -40,6 +40,6 @@ def cli(obj, environment, service, resource, event, group, tags, origin, custome text=text ) except Exception as e: - click.echo('ERROR: {}'.format(e), err=True) + click.echo(f'ERROR: {e}', err=True) sys.exit(1) click.echo(blackout.id) diff --git a/alertaclient/commands/cmd_blackouts.py b/alertaclient/commands/cmd_blackouts.py index 583dd33..edbb77e 100644 --- a/alertaclient/commands/cmd_blackouts.py +++ b/alertaclient/commands/cmd_blackouts.py @@ -27,6 +27,6 @@ def cli(obj, purge): expired = [b for b in blackouts if b.status == 'expired'] if purge: - with click.progressbar(expired, label='Purging {} blackouts'.format(len(expired))) as bar: + with click.progressbar(expired, label=f'Purging {len(expired)} blackouts') as bar: for b in bar: client.delete_blackout(b.id) diff --git a/alertaclient/commands/cmd_close.py b/alertaclient/commands/cmd_close.py index e3576b7..8b7ac78 100644 --- a/alertaclient/commands/cmd_close.py +++ b/alertaclient/commands/cmd_close.py @@ -22,4 +22,4 @@ def cli(obj, ids, query, filters, text): total, _, _ = client.get_count(query) ids = [a.id for a in client.get_alerts(query)] - action_progressbar(client, action='close', ids=ids, label='Closing {} alerts'.format(total), text=text) + action_progressbar(client, action='close', ids=ids, label=f'Closing {total} alerts', text=text) diff --git a/alertaclient/commands/cmd_config.py b/alertaclient/commands/cmd_config.py index f458601..04b7c4e 100644 --- a/alertaclient/commands/cmd_config.py +++ b/alertaclient/commands/cmd_config.py @@ -8,4 +8,4 @@ def cli(obj): for k, v in obj.items(): if isinstance(v, list): v = ', '.join(v) - click.echo('{:20}: {}'.format(k, v)) + click.echo(f'{k:20}: {v}') diff --git a/alertaclient/commands/cmd_customer.py b/alertaclient/commands/cmd_customer.py index 33942f3..51f7540 100644 --- a/alertaclient/commands/cmd_customer.py +++ b/alertaclient/commands/cmd_customer.py @@ -21,6 +21,6 @@ def cli(obj, customer, match, delete): try: customer = client.create_customer(customer, match) except Exception as e: - click.echo('ERROR: {}'.format(e), err=True) + click.echo(f'ERROR: {e}', err=True) sys.exit(1) click.echo(customer.id) diff --git a/alertaclient/commands/cmd_delete.py b/alertaclient/commands/cmd_delete.py index f333203..c3ca575 100644 --- a/alertaclient/commands/cmd_delete.py +++ b/alertaclient/commands/cmd_delete.py @@ -23,6 +23,6 @@ def cli(obj, ids, query, filters): total, _, _ = client.get_count(query) ids = [a.id for a in client.get_alerts(query)] - with click.progressbar(ids, label='Deleting {} alerts'.format(total)) as bar: + with click.progressbar(ids, label=f'Deleting {total} alerts') as bar: for id in bar: client.delete_alert(id) diff --git a/alertaclient/commands/cmd_group.py b/alertaclient/commands/cmd_group.py index 81c9ba8..63ec9a4 100644 --- a/alertaclient/commands/cmd_group.py +++ b/alertaclient/commands/cmd_group.py @@ -56,6 +56,6 @@ def cli(obj, id, name, text, user, users, delete): try: group = client.create_group(name, text) except Exception as e: - click.echo('ERROR: {}'.format(e), err=True) + click.echo(f'ERROR: {e}', err=True) sys.exit(1) click.echo(group.id) diff --git a/alertaclient/commands/cmd_heartbeat.py b/alertaclient/commands/cmd_heartbeat.py index 3c6760a..901c948 100644 --- a/alertaclient/commands/cmd_heartbeat.py +++ b/alertaclient/commands/cmd_heartbeat.py @@ -52,6 +52,6 @@ def cli(obj, origin, environment, severity, service, group, tags, timeout, custo try: heartbeat = client.heartbeat(origin=origin, tags=tags, attributes=attributes, timeout=timeout, customer=customer) except Exception as e: - click.echo('ERROR: {}'.format(e), err=True) + click.echo(f'ERROR: {e}', err=True) sys.exit(1) click.echo(heartbeat.id) diff --git a/alertaclient/commands/cmd_heartbeats.py b/alertaclient/commands/cmd_heartbeats.py index 079f738..db9ffd1 100644 --- a/alertaclient/commands/cmd_heartbeats.py +++ b/alertaclient/commands/cmd_heartbeats.py @@ -48,12 +48,12 @@ def cli(obj, alert, severity, timeout, purge): not_ok = [hb for hb in heartbeats if hb.status != 'ok'] if purge: - with click.progressbar(not_ok, label='Purging {} heartbeats'.format(len(not_ok))) as bar: + with click.progressbar(not_ok, label=f'Purging {len(not_ok)} heartbeats') as bar: for b in bar: client.delete_heartbeat(b.id) if alert: - with click.progressbar(heartbeats, label='Alerting {} heartbeats'.format(len(heartbeats))) as bar: + with click.progressbar(heartbeats, label=f'Alerting {len(heartbeats)} heartbeats') as bar: for b in bar: want_environment = b.attributes.pop('environment', 'Production') @@ -70,8 +70,8 @@ def cli(obj, alert, severity, timeout, purge): correlate=['HeartbeatFail', 'HeartbeatSlow', 'HeartbeatOK'], service=want_service, group=want_group, - value='{}'.format(b.since), - text='Heartbeat not received in {} seconds'.format(b.timeout), + value=f'{b.since}', + text=f'Heartbeat not received in {b.timeout} seconds', tags=b.tags, attributes=b.attributes, origin=origin(), @@ -88,8 +88,8 @@ def cli(obj, alert, severity, timeout, purge): correlate=['HeartbeatFail', 'HeartbeatSlow', 'HeartbeatOK'], service=want_service, group=want_group, - value='{}ms'.format(b.latency), - text='Heartbeat took more than {}ms to be processed'.format(b.max_latency), + value=f'{b.latency}ms', + text=f'Heartbeat took more than {b.max_latency}ms to be processed', tags=b.tags, attributes=b.attributes, origin=origin(), diff --git a/alertaclient/commands/cmd_key.py b/alertaclient/commands/cmd_key.py index a58cc0b..5889b1d 100644 --- a/alertaclient/commands/cmd_key.py +++ b/alertaclient/commands/cmd_key.py @@ -23,6 +23,6 @@ def cli(obj, api_key, username, scopes, duration, text, customer, delete): expires = datetime.utcnow() + timedelta(seconds=duration) if duration else None key = client.create_key(username, scopes, expires, text, customer, key=api_key) except Exception as e: - click.echo('ERROR: {}'.format(e), err=True) + click.echo(f'ERROR: {e}', err=True) sys.exit(1) click.echo(key.key) diff --git a/alertaclient/commands/cmd_login.py b/alertaclient/commands/cmd_login.py index 74191f6..ddbeac3 100644 --- a/alertaclient/commands/cmd_login.py +++ b/alertaclient/commands/cmd_login.py @@ -37,7 +37,7 @@ def cli(obj, username): password = click.prompt('Password', hide_input=True) token = client.login(username, password)['token'] else: - click.echo('ERROR: unknown provider {provider}'.format(provider=provider), err=True) + click.echo(f'ERROR: unknown provider {provider}', err=True) sys.exit(1) except Exception as e: raise AuthError(e) @@ -46,7 +46,7 @@ def cli(obj, username): preferred_username = jwt.parse(token)['preferred_username'] if preferred_username: save_token(client.endpoint, preferred_username, token) - click.echo('Logged in as {}'.format(preferred_username)) + click.echo(f'Logged in as {preferred_username}') else: click.echo('Failed to login.') sys.exit(1) diff --git a/alertaclient/commands/cmd_me.py b/alertaclient/commands/cmd_me.py index 09e7640..e073f73 100644 --- a/alertaclient/commands/cmd_me.py +++ b/alertaclient/commands/cmd_me.py @@ -20,6 +20,6 @@ def cli(obj, name, email, password, status, text): try: user = client.update_me(name=name, email=email, password=password, status=status, attributes=None, text=text) except Exception as e: - click.echo('ERROR: {}'.format(e), err=True) + click.echo(f'ERROR: {e}', err=True) sys.exit(1) click.echo(user.id) diff --git a/alertaclient/commands/cmd_note.py b/alertaclient/commands/cmd_note.py index c469b39..f341163 100644 --- a/alertaclient/commands/cmd_note.py +++ b/alertaclient/commands/cmd_note.py @@ -42,6 +42,6 @@ def cli(obj, alert_ids, query, filters, text, delete): total, _, _ = client.get_count(query) alert_ids = [a.id for a in client.get_alerts(query)] - with click.progressbar(alert_ids, label='Add note to {} alerts'.format(total)) as bar: + with click.progressbar(alert_ids, label=f'Add note to {total} alerts') as bar: for id in bar: client.alert_note(id, text=text) diff --git a/alertaclient/commands/cmd_notes.py b/alertaclient/commands/cmd_notes.py index 7348454..fc57943 100644 --- a/alertaclient/commands/cmd_notes.py +++ b/alertaclient/commands/cmd_notes.py @@ -12,7 +12,7 @@ def cli(obj, alert_id): client = obj['client'] if alert_id: if obj['output'] == 'json': - r = client.http.get('/alert/{}/notes'.format(alert_id)) + r = client.http.get(f'/alert/{alert_id}/notes') click.echo(json.dumps(r['notes'], sort_keys=True, indent=4, ensure_ascii=False)) else: timezone = obj['timezone'] diff --git a/alertaclient/commands/cmd_perm.py b/alertaclient/commands/cmd_perm.py index 361acee..236ee59 100644 --- a/alertaclient/commands/cmd_perm.py +++ b/alertaclient/commands/cmd_perm.py @@ -21,6 +21,6 @@ def cli(obj, role, scopes, delete): try: perm = client.create_perm(role, scopes) except Exception as e: - click.echo('ERROR: {}'.format(e), err=True) + click.echo(f'ERROR: {e}', err=True) sys.exit(1) click.echo(perm.id) diff --git a/alertaclient/commands/cmd_query.py b/alertaclient/commands/cmd_query.py index fee7b67..f794cee 100644 --- a/alertaclient/commands/cmd_query.py +++ b/alertaclient/commands/cmd_query.py @@ -72,21 +72,21 @@ def cli(obj, ids, query, filters, display, from_date=None): alert.group, alert.event, alert.value or 'n/a'), fg=color['fg']) - click.secho(' |{}'.format(alert.text), fg=color['fg']) + click.secho(f' |{alert.text}', fg=color['fg']) if display == 'full': click.secho(' severity | {} -> {}'.format(alert.previous_severity, alert.severity), fg=color['fg']) - click.secho(' trend | {}'.format(alert.trend_indication), fg=color['fg']) - click.secho(' status | {}'.format(alert.status), fg=color['fg']) - click.secho(' resource | {}'.format(alert.resource), fg=color['fg']) - click.secho(' group | {}'.format(alert.group), fg=color['fg']) - click.secho(' event | {}'.format(alert.event), fg=color['fg']) - click.secho(' value | {}'.format(alert.value), fg=color['fg']) + click.secho(f' trend | {alert.trend_indication}', fg=color['fg']) + click.secho(f' status | {alert.status}', fg=color['fg']) + click.secho(f' resource | {alert.resource}', fg=color['fg']) + click.secho(f' group | {alert.group}', fg=color['fg']) + click.secho(f' event | {alert.event}', fg=color['fg']) + click.secho(f' value | {alert.value}', fg=color['fg']) click.secho(' tags | {}'.format(' '.join(alert.tags)), fg=color['fg']) for key, value in alert.attributes.items(): - click.secho(' {} | {}'.format(key.ljust(10), value), fg=color['fg']) + click.secho(f' {key.ljust(10)} | {value}', fg=color['fg']) latency = alert.receive_time - alert.create_time @@ -96,18 +96,18 @@ def cli(obj, ids, query, filters, display, from_date=None): DateTime.localtime(alert.receive_time, timezone)), fg=color['fg']) click.secho(' last received | {}'.format( DateTime.localtime(alert.last_receive_time, timezone)), fg=color['fg']) - click.secho(' latency | {}ms'.format(latency.microseconds / 1000), fg=color['fg']) - click.secho(' timeout | {}s'.format(alert.timeout), fg=color['fg']) + click.secho(f' latency | {latency.microseconds / 1000}ms', fg=color['fg']) + click.secho(f' timeout | {alert.timeout}s', fg=color['fg']) - click.secho(' alert id | {}'.format(alert.id), fg=color['fg']) - click.secho(' last recv id | {}'.format(alert.last_receive_id), fg=color['fg']) - click.secho(' customer | {}'.format(alert.customer), fg=color['fg']) - click.secho(' environment | {}'.format(alert.environment), fg=color['fg']) + click.secho(f' alert id | {alert.id}', fg=color['fg']) + click.secho(f' last recv id | {alert.last_receive_id}', fg=color['fg']) + click.secho(f' customer | {alert.customer}', fg=color['fg']) + click.secho(f' environment | {alert.environment}', fg=color['fg']) click.secho(' service | {}'.format(','.join(alert.service)), fg=color['fg']) - click.secho(' resource | {}'.format(alert.resource), fg=color['fg']) - click.secho(' type | {}'.format(alert.event_type), fg=color['fg']) - click.secho(' repeat | {}'.format(alert.repeat), fg=color['fg']) - click.secho(' origin | {}'.format(alert.origin), fg=color['fg']) + click.secho(f' resource | {alert.resource}', fg=color['fg']) + click.secho(f' type | {alert.event_type}', fg=color['fg']) + click.secho(f' repeat | {alert.repeat}', fg=color['fg']) + click.secho(f' origin | {alert.origin}', fg=color['fg']) click.secho(' correlate | {}'.format(','.join(alert.correlate)), fg=color['fg']) return auto_refresh, last_time diff --git a/alertaclient/commands/cmd_send.py b/alertaclient/commands/cmd_send.py index 00ba2a3..bf01a2c 100644 --- a/alertaclient/commands/cmd_send.py +++ b/alertaclient/commands/cmd_send.py @@ -48,15 +48,15 @@ def send_alert(resource, event, **kwargs): customer=kwargs.get('customer') ) except Exception as e: - click.echo('ERROR: {}'.format(e), err=True) + click.echo(f'ERROR: {e}', err=True) sys.exit(1) if alert: if alert.repeat: - message = '{} duplicates'.format(alert.duplicate_count) + message = f'{alert.duplicate_count} duplicates' else: - message = '{} -> {}'.format(alert.previous_severity, alert.severity) - click.echo('{} ({})'.format(id, message)) + message = f'{alert.previous_severity} -> {alert.severity}' + click.echo(f'{id} ({message})') # read raw data from file or stdin if raw_data and raw_data.startswith('@') or raw_data == '-': @@ -71,7 +71,7 @@ def send_alert(resource, event, **kwargs): try: payload = json.loads(line) except Exception as e: - click.echo("ERROR: JSON parse failure - input must be in 'json_lines' format: {}".format(e), err=True) + click.echo(f"ERROR: JSON parse failure - input must be in 'json_lines' format: {e}", err=True) sys.exit(1) send_alert(**payload) sys.exit(0) diff --git a/alertaclient/commands/cmd_shelve.py b/alertaclient/commands/cmd_shelve.py index 8c19faf..20a4e40 100644 --- a/alertaclient/commands/cmd_shelve.py +++ b/alertaclient/commands/cmd_shelve.py @@ -24,4 +24,4 @@ def cli(obj, ids, query, filters, timeout, text): ids = [a.id for a in client.get_alerts(query)] action_progressbar(client, action='shelve', ids=ids, - label='Shelving {} alerts'.format(total), text=text, timeout=timeout) + label=f'Shelving {total} alerts', text=text, timeout=timeout) diff --git a/alertaclient/commands/cmd_signup.py b/alertaclient/commands/cmd_signup.py index dfa736d..cf6be9c 100644 --- a/alertaclient/commands/cmd_signup.py +++ b/alertaclient/commands/cmd_signup.py @@ -22,7 +22,7 @@ def cli(obj, name, email, password, status, text): try: r = client.signup(name=name, email=email, password=password, status=status, attributes=None, text=text) except Exception as e: - click.echo('ERROR: {}'.format(e), err=True) + click.echo(f'ERROR: {e}', err=True) sys.exit(1) if 'token' in r: click.echo('Signed Up.') diff --git a/alertaclient/commands/cmd_tag.py b/alertaclient/commands/cmd_tag.py index ce749a3..f98c678 100644 --- a/alertaclient/commands/cmd_tag.py +++ b/alertaclient/commands/cmd_tag.py @@ -22,6 +22,6 @@ def cli(obj, ids, query, filters, tags): total, _, _ = client.get_count(query) ids = [a.id for a in client.get_alerts(query)] - with click.progressbar(ids, label='Tagging {} alerts'.format(total)) as bar: + with click.progressbar(ids, label=f'Tagging {total} alerts') as bar: for id in bar: client.tag_alert(id, tags) diff --git a/alertaclient/commands/cmd_token.py b/alertaclient/commands/cmd_token.py index a66cf55..044bbae 100644 --- a/alertaclient/commands/cmd_token.py +++ b/alertaclient/commands/cmd_token.py @@ -16,6 +16,6 @@ def cli(obj, decode): for k, v in jwt.parse(token).items(): if isinstance(v, list): v = ', '.join(v) - click.echo('{:20}: {}'.format(k, v)) + click.echo(f'{k:20}: {v}') else: click.echo(token) diff --git a/alertaclient/commands/cmd_unack.py b/alertaclient/commands/cmd_unack.py index 23e26d7..64b25d5 100644 --- a/alertaclient/commands/cmd_unack.py +++ b/alertaclient/commands/cmd_unack.py @@ -22,4 +22,4 @@ def cli(obj, ids, query, filters, text): total, _, _ = client.get_count(query) ids = [a.id for a in client.get_alerts(query)] - action_progressbar(client, action='unack', ids=ids, label='Un-acking {} alerts'.format(total), text=text) + action_progressbar(client, action='unack', ids=ids, label=f'Un-acking {total} alerts', text=text) diff --git a/alertaclient/commands/cmd_unshelve.py b/alertaclient/commands/cmd_unshelve.py index 30348cb..278a8e7 100644 --- a/alertaclient/commands/cmd_unshelve.py +++ b/alertaclient/commands/cmd_unshelve.py @@ -22,4 +22,4 @@ def cli(obj, ids, query, filters, text): total, _, _ = client.get_count(query) ids = [a.id for a in client.get_alerts(query)] - action_progressbar(client, 'unshelve', ids, label='Un-shelving {} alerts'.format(total), text=text) + action_progressbar(client, 'unshelve', ids, label=f'Un-shelving {total} alerts', text=text) diff --git a/alertaclient/commands/cmd_untag.py b/alertaclient/commands/cmd_untag.py index 3214934..d2026cd 100644 --- a/alertaclient/commands/cmd_untag.py +++ b/alertaclient/commands/cmd_untag.py @@ -22,6 +22,6 @@ def cli(obj, ids, query, filters, tags): total, _, _ = client.get_count(query) ids = [a.id for a in client.get_alerts(query)] - with click.progressbar(ids, label='Untagging {} alerts'.format(total)) as bar: + with click.progressbar(ids, label=f'Untagging {total} alerts') as bar: for id in bar: client.untag_alert(id, tags) diff --git a/alertaclient/commands/cmd_update.py b/alertaclient/commands/cmd_update.py index 2873262..90c0155 100644 --- a/alertaclient/commands/cmd_update.py +++ b/alertaclient/commands/cmd_update.py @@ -22,6 +22,6 @@ def cli(obj, ids, query, filters, attributes): total, _, _ = client.get_count(query) ids = [a.id for a in client.get_alerts(query)] - with click.progressbar(ids, label='Updating {} alerts'.format(total)) as bar: + with click.progressbar(ids, label=f'Updating {total} alerts') as bar: for id in bar: client.update_attributes(id, dict(a.split('=') for a in attributes)) diff --git a/alertaclient/commands/cmd_user.py b/alertaclient/commands/cmd_user.py index 532a757..491853e 100644 --- a/alertaclient/commands/cmd_user.py +++ b/alertaclient/commands/cmd_user.py @@ -56,7 +56,7 @@ def cli(obj, id, name, email, password, status, roles, text, email_verified, gro roles=roles, attributes=None, text=text, email_verified=email_verified ) except Exception as e: - click.echo('ERROR: {}'.format(e), err=True) + click.echo(f'ERROR: {e}', err=True) sys.exit(1) click.echo(user.id) else: @@ -70,6 +70,6 @@ def cli(obj, id, name, email, password, status, roles, text, email_verified, gro roles=roles, attributes=None, text=text, email_verified=email_verified ) except Exception as e: - click.echo('ERROR: {}'.format(e), err=True) + click.echo(f'ERROR: {e}', err=True) sys.exit(1) click.echo(user.id) diff --git a/alertaclient/commands/cmd_version.py b/alertaclient/commands/cmd_version.py index b576353..60f639e 100644 --- a/alertaclient/commands/cmd_version.py +++ b/alertaclient/commands/cmd_version.py @@ -11,7 +11,7 @@ def cli(ctx, obj): """Show Alerta server and client versions.""" client = obj['client'] click.echo('alerta {}'.format(client.mgmt_status()['version'])) - click.echo('alerta client {}'.format(client_version)) - click.echo('requests {}'.format(requests_version)) - click.echo('click {}'.format(click.__version__)) + click.echo(f'alerta client {client_version}') + click.echo(f'requests {requests_version}') + click.echo(f'click {click.__version__}') ctx.exit() diff --git a/alertaclient/commands/cmd_whoami.py b/alertaclient/commands/cmd_whoami.py index 7feef78..f3861ac 100644 --- a/alertaclient/commands/cmd_whoami.py +++ b/alertaclient/commands/cmd_whoami.py @@ -12,6 +12,6 @@ def cli(obj, show_userinfo): for k, v in userinfo.items(): if isinstance(v, list): v = ', '.join(v) - click.echo('{:20}: {}'.format(k, v)) + click.echo(f'{k:20}: {v}') else: click.echo(userinfo['preferred_username']) diff --git a/alertaclient/config.py b/alertaclient/config.py index 9c46f38..43953d1 100644 --- a/alertaclient/config.py +++ b/alertaclient/config.py @@ -64,8 +64,8 @@ def get_remote_config(self, endpoint=None): r.raise_for_status() remote_config = r.json() except requests.RequestException as e: - raise ClientException('Failed to get config from {}. Reason: {}'.format(config_url, e)) + raise ClientException(f'Failed to get config from {config_url}. Reason: {e}') except json.decoder.JSONDecodeError: - raise ClientException('Failed to get config from {}: Reason: not a JSON object'.format(config_url)) + raise ClientException(f'Failed to get config from {config_url}: Reason: not a JSON object') self.options = {**remote_config, **self.options} diff --git a/alertaclient/models/blackout.py b/alertaclient/models/blackout.py index 8323dea..856f0ce 100644 --- a/alertaclient/models/blackout.py +++ b/alertaclient/models/blackout.py @@ -129,9 +129,9 @@ def tabular(self, timezone=None): 'customer': self.customer, 'startTime': DateTime.localtime(self.start_time, timezone), 'endTime': DateTime.localtime(self.end_time, timezone), - 'duration': '{}s'.format(self.duration), + 'duration': f'{self.duration}s', 'status': self.status, - 'remaining': '{}s'.format(self.remaining), + 'remaining': f'{self.remaining}s', 'user': self.user, 'createTime': DateTime.localtime(self.create_time, timezone), 'text': self.text diff --git a/alertaclient/models/enums.py b/alertaclient/models/enums.py index 46eb45c..5eff97b 100644 --- a/alertaclient/models/enums.py +++ b/alertaclient/models/enums.py @@ -55,7 +55,7 @@ def from_str(action: str, resource: str = None): :return: Scope """ if resource: - return Scope('{}:{}'.format(action, resource)) + return Scope(f'{action}:{resource}') else: return Scope(action) diff --git a/alertaclient/models/heartbeat.py b/alertaclient/models/heartbeat.py index 4b8f56f..1f13809 100644 --- a/alertaclient/models/heartbeat.py +++ b/alertaclient/models/heartbeat.py @@ -70,8 +70,8 @@ def tabular(self, timezone=None): 'createTime': DateTime.localtime(self.create_time, timezone), 'receiveTime': DateTime.localtime(self.receive_time, timezone), 'since': self.since, - 'timeout': '{}s'.format(self.timeout), - 'latency': '{:.0f}ms'.format(self.latency), - 'maxLatency': '{}ms'.format(self.max_latency), + 'timeout': f'{self.timeout}s', + 'latency': f'{self.latency:.0f}ms', + 'maxLatency': f'{self.max_latency}ms', 'status': self.status } diff --git a/alertaclient/top.py b/alertaclient/top.py index c3756fe..702dc51 100644 --- a/alertaclient/top.py +++ b/alertaclient/top.py @@ -84,7 +84,7 @@ def update(self): # draw header self._addstr(0, 0, self.client.endpoint, curses.A_BOLD) - self._addstr(0, 'C', 'alerta {}'.format(version), curses.A_BOLD) + self._addstr(0, 'C', f'alerta {version}', curses.A_BOLD) self._addstr(0, 'R', '{}'.format(now.strftime('%H:%M:%S %d/%m/%y')), curses.A_BOLD) # TODO - draw bars diff --git a/alertaclient/utils.py b/alertaclient/utils.py index 12549d7..9577073 100644 --- a/alertaclient/utils.py +++ b/alertaclient/utils.py @@ -50,7 +50,7 @@ def action_progressbar(client, action, ids, label, text=None, timeout=None): def show_skipped(id): if not id and skipped: - return '(skipped {})'.format(skipped) + return f'(skipped {skipped})' with click.progressbar(ids, label=label, show_eta=True, item_show_func=show_skipped) as bar: for id in bar: @@ -62,4 +62,4 @@ def show_skipped(id): def origin(): prog = os.path.basename(sys.argv[0]) - return '{}/{}'.format(prog, platform.uname()[1]) + return f'{prog}/{platform.uname()[1]}'