Skip to content

Commit 9d09d7e

Browse files
Ramkishor ChaladiRamkishor Chaladi
authored andcommitted
added f{} strings
1 parent 4e3debe commit 9d09d7e

File tree

20 files changed

+40
-58
lines changed

20 files changed

+40
-58
lines changed

SoftLayer/CLI/call_api.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ def _validate_filter(ctx, param, value): # pylint: disable=unused-argument
7777
try:
7878
_filter = json.loads(value)
7979
if not isinstance(_filter, dict):
80-
raise exceptions.CLIAbort("\"{}\" should be a JSON object, but is a {} instead.".
81-
format(_filter, type(_filter)))
80+
raise exceptions.CLIAbort(f"\"{_filter}\" should be a JSON object, but is a {type(_filter)} instead.")
8281
except json.JSONDecodeError as error:
83-
raise exceptions.CLIAbort("\"{}\" is not valid JSON. {}".format(value, error))
82+
raise exceptions.CLIAbort(f"\"{value}\" is not valid JSON. {error}")
8483

8584
return _filter
8685

@@ -96,8 +95,8 @@ def _validate_parameters(ctx, param, value): # pylint: disable=unused-argument
9695
try:
9796
parameter = json.loads(parameter)
9897
except json.JSONDecodeError as error:
99-
click.secho("{} looked like json, but was invalid, passing to API as is. {}".
100-
format(parameter, error), fg='red')
98+
click.secho(f"{parameter} looked like json, but was invalid, passing to API as is. {error}",
99+
fg='red')
101100
validated_values.append(parameter)
102101
return validated_values
103102

SoftLayer/CLI/cdn/delete.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ def cli(env, unique_id):
1818
cdn = manager.delete_cdn(unique_id)
1919

2020
if cdn:
21-
env.fout("Cdn with uniqueId: {} was deleted.".format(unique_id))
21+
env.fout(f"Cdn with uniqueId: {unique_id} was deleted.")

SoftLayer/CLI/config/setup.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def ibmid_login(env):
171171
user = client.call('SoftLayer_Account', 'getCurrentUser', mask="mask[id,username,apiAuthenticationKeys]")
172172

173173
if len(user.get('apiAuthenticationKeys', [])) == 0:
174-
env.fout("Creating a Classic Infrastrucutre API key for {}".format(user['username']))
174+
env.fout(f"Creating a Classic Infrastrucutre API key for {user['username']}")
175175
api_key = client.call('User_Customer', 'addApiAuthenticationKey', id=user['id'])
176176
else:
177177
api_key = user['apiAuthenticationKeys'][0]['authenticationKey']
@@ -188,7 +188,7 @@ def get_accounts(env, a_token):
188188
'User-Agent': USER_AGENT,
189189
'Accept': 'application/json'
190190
}
191-
headers['Authorization'] = 'Bearer {}'.format(a_token)
191+
headers['Authorization'] = f'Bearer {a_token}'
192192
response = iam_client.request(
193193
'GET',
194194
'https://accounts.cloud.ibm.com/v1/accounts',
@@ -212,7 +212,7 @@ def get_accounts(env, a_token):
212212
ims_id = link.get('id')
213213
if ims_id is None:
214214
ims_id = "Unlinked"
215-
env.fout("{}: {} ({})".format(counter, utils.lookup(selected, 'entity', 'name'), ims_id))
215+
env.fout(f"{counter}: {utils.lookup(selected, 'entity', 'name')} ({ims_id})")
216216
counter = counter + 1
217217
ims_id = None # Reset ims_id to avoid any mix-match or something.
218218
choice = click.prompt('Enter a number', type=int)
@@ -225,7 +225,7 @@ def get_accounts(env, a_token):
225225
if link.get('origin') == "IMS":
226226
ims_id = link.get('id')
227227

228-
print("Using account {}".format(utils.lookup(selected, 'entity', 'name')))
228+
print(f"Using account {utils.lookup(selected, 'entity', 'name')}")
229229
return {"account_id": account_id, "ims_id": ims_id}
230230

231231

@@ -253,7 +253,7 @@ def get_sso_url():
253253
def sso_login(env):
254254
"""Uses a SSO token to get a SL apikey"""
255255
passcode_url = get_sso_url()
256-
env.fout("Get a one-time code from {} to proceed.".format(passcode_url))
256+
env.fout(f"Get a one-time code from {passcode_url} to proceed.")
257257
open_browser = env.input("Open the URL in the default browser? [Y/n]", default='Y')
258258
if open_browser.lower() == 'y':
259259
webbrowser.open(passcode_url)
@@ -274,7 +274,7 @@ def sso_login(env):
274274
user = client.call('SoftLayer_Account', 'getCurrentUser', mask="mask[id,username,apiAuthenticationKeys]")
275275

276276
if len(user.get('apiAuthenticationKeys', [])) == 0:
277-
env.fout("Creating a Classic Infrastrucutre API key for {}".format(user['username']))
277+
env.fout(f"Creating a Classic Infrastrucutre API key for {user['username']}")
278278
api_key = client.call('User_Customer', 'addApiAuthenticationKey', id=user['id'])
279279
else:
280280
api_key = user['apiAuthenticationKeys'][0]['authenticationKey']

SoftLayer/CLI/core.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def get_latest_version():
4646
try:
4747
result = requests.get('https://pypi.org/pypi/SoftLayer/json', timeout=60)
4848
json_result = result.json()
49-
latest = 'v{}'.format(json_result['info']['version'])
49+
latest = f"v{json_result['info']['version']}"
5050
except Exception:
5151
latest = "Unable to get version from pypi."
5252
return latest
@@ -65,8 +65,7 @@ def get_version_message(ctx, param, value):
6565
return
6666
current = SoftLayer.consts.VERSION
6767
latest = get_latest_version()
68-
click.secho("Current: {prog} {current}\nLatest: {prog} {latest}".format(
69-
prog=PROG_NAME, current=current, latest=latest))
68+
click.secho(f"Current: {PROG_NAME} {current}\nLatest: {PROG_NAME} {latest}")
7069
ctx.exit()
7170

7271

@@ -158,7 +157,7 @@ def output_diagnostics(env, result, verbose=0, **kwargs):
158157

159158
if verbose > 1:
160159
for call in env.client.transport.get_last_calls():
161-
call_table = formatting.Table(['', '{}::{}'.format(call.service, call.method)], align="left")
160+
call_table = formatting.Table([f"'', '{call.service}::{call.method}'"], align="left")
162161
nice_mask = ''
163162
if call.mask is not None:
164163
nice_mask = call.mask

SoftLayer/CLI/custom_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ def convert(self, value, param, ctx):
3030
ip_address, cidr = address
3131
return (ip_address, int(cidr))
3232
except ValueError:
33-
self.fail('{} is not a valid network'.format(value), param, ctx)
33+
self.fail(f'{value} is not a valid network', param, ctx)

SoftLayer/CLI/dns/zone_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def cli(env):
2424
zone_date = zone.get('updateDate', None)
2525
if zone_date is None:
2626
# The serial is just YYYYMMDD##, and since there is no createDate, just format it like it was one.
27-
zone_date = "{}-{}-{}T00:00:00-06:00".format(zone_serial[0:4], zone_serial[4:6], zone_serial[6:8])
27+
zone_date = f"{zone_serial[0:4]}-{zone_serial[4:6]}-{zone_serial[6:8]}T00:00:00-06:00"
2828
table.add_row([
2929
zone['id'],
3030
zone['name'],

SoftLayer/CLI/event_log/get.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,13 @@ def cli(env, date_min, date_max, obj_event, obj_id, obj_type, utc_offset, metada
7070
if metadata:
7171
metadata_data = log['metaData'].strip("\n\t")
7272

73-
click.secho("'{0}','{1}','{2}','{3}','{4}','{5}'".format(
74-
log['eventName'],
75-
label,
76-
log['objectName'],
77-
utils.clean_time(log['eventCreateDate'], in_format=log_time),
78-
user,
79-
metadata_data))
73+
click.secho(f"'{log['eventName']}','{label}','{log['objectName']}',"
74+
f"'{utils.clean_time(log['eventCreateDate'], in_format=log_time)}',"
75+
f"'{user}','{metadata_data}'")
8076
else:
81-
click.secho("'{0}','{1}','{2}','{3}','{4}'".format(
82-
log['eventName'],
83-
label,
84-
log['objectName'],
85-
utils.clean_time(log['eventCreateDate'], in_format=log_time),
86-
user))
77+
click.secho(f"'{log['eventName']}','{label}','{log['objectName']}',"
78+
f"'{utils.clean_time(log['eventCreateDate'],in_format=log_time)}',"
79+
f"'{user}'")
8780

8881
row_count = row_count + 1
8982
if row_count >= limit and limit != -1:

SoftLayer/CLI/file/access/list.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
@click.option('--sortby', help='Column to sort by', default='name')
1616
@click.option('--columns',
1717
callback=column_helper.get_formatter(storage_utils.COLUMNS),
18-
help='Columns to display. Options: {0}'.format(
19-
', '.join(column.name for column in storage_utils.COLUMNS)),
18+
help=f"Columns to display. Options: { ', '.join(column.name for column in storage_utils.COLUMNS)}",
2019
default=','.join(storage_utils.DEFAULT_COLUMNS))
2120
@environment.pass_env
2221
def cli(env, columns, sortby, volume_id):

SoftLayer/CLI/file/detail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def cli(env, volume_id):
134134
original_volume_info.add_row(['Original Snapshot Name', file_volume['originalSnapshotName']])
135135
table.add_row(['Original Volume Properties', original_volume_info])
136136

137-
notes = '{}'.format(file_volume.get('notes', ''))
137+
notes = f"{file_volume.get('notes', '')}"
138138
table.add_row(['Notes', notes])
139139

140140
env.fout(table)

SoftLayer/CLI/file/duplicate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
8787
raise exceptions.ArgumentError(str(ex))
8888

8989
if 'placedOrder' in order.keys():
90-
click.echo("Order #{0} placed successfully!".format(
91-
order['placedOrder']['id']))
90+
click.echo(f"Order #{order['placedOrder']['id']} placed successfully!")
9291
for item in order['placedOrder']['items']:
9392
click.echo(" > %s" % item['description'])
9493
else:

0 commit comments

Comments
 (0)