Skip to content

Commit 730f79e

Browse files
committed
f-stringify part 2
1 parent cc7c5cb commit 730f79e

17 files changed

+50
-59
lines changed

examples/bamboo/bamboo_label_based_cleaner.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,28 @@ def get_plans_from_project(project_key):
3131
if __name__ == "__main__":
3232
bamboo = Bamboo(url=BAMBOO_URL, username=BAMBOO_LOGIN, password=BAMBOO_PASSWORD, timeout=180)
3333
projects = get_all_projects()
34-
print(("Start analyzing the {} projects".format(len(projects))))
34+
print((f"Start analyzing the {len(projects)} projects"))
3535
for project in projects:
36-
print(("Inspecting {} project".format(project)))
36+
print((f"Inspecting {project} project"))
3737
plans = get_plans_from_project(project)
38-
print(("Start analyzing the {} plans".format(len(plans))))
38+
print((f"Start analyzing the {len(plans)} plans"))
3939
for plan in plans:
40-
print(("Inspecting {} plan".format(plan)))
40+
print((f"Inspecting {plan} plan"))
4141
build_results = [
4242
x for x in bamboo.results(plan_key=plan, label=LABEL, max_results=100, include_all_states=True)
4343
]
4444
for build in build_results:
4545
build_key = build.get("buildResultKey") or None
46-
print(("Inspecting {} build".format(build_key)))
46+
print((f"Inspecting {build_key} build"))
4747
build_value = bamboo.build_result(build_key)
4848
build_complete_time = build_value.get("buildCompletedTime") or None
4949
if not build_complete_time:
5050
continue
5151
datetimeObj = datetime.strptime(build_complete_time.split("+")[0] + "000", "%Y-%m-%dT%H:%M:%S.%f")
5252
if datetime.now() > datetimeObj + timedelta(days=OLDER_DAYS):
5353
print((
54-
"Build is old {} as build complete date {}".format(
55-
build_key, build_complete_time.strftime("%Y-%m-%d")
56-
)
54+
f"Build is old {build_key} as build complete date {build_complete_time.strftime('%Y-%m-%d')}"
5755
))
5856
if not DRY_RUN:
59-
print(("Removing {} build".format(build_key)))
57+
print((f"Removing {build_key} build"))
6058
bamboo.delete_build_result(build_key)

examples/bamboo/bamboo_remove_old_failed_results.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ def remove_build_result(build_key, status):
4343
datetime_obj = datetime.strptime(build_complete_time.split("+")[0] + "000", "%Y-%m-%dT%H:%M:%S.%f")
4444
if datetime.now() > datetime_obj + timedelta(days=OLDER_DAYS):
4545
if build_value.get("buildState") == status:
46-
print(("Removing build result - {}".format(build_key)))
46+
print((f"Removing build result - {build_key}"))
4747
if not DRY_RUN:
4848
bamboo.delete_build_result(build_key=build_key)
4949

5050

5151
def project_review(plans):
5252
for plan in plans:
53-
print(("Inspecting {} plan".format(plan)))
53+
print((f"Inspecting {plan} plan"))
5454
branches = get_branches_from_plan(plan)
5555
for branch in branches:
5656
build_results = get_results_from_branch(branch)
5757
for build in build_results:
5858
build_key = build.get("buildResultKey") or None
59-
print(("Inspecting build - {}".format(build_key)))
59+
print((f"Inspecting build - {build_key}"))
6060
if build_key:
6161
for status in STATUS_CLEANED_RESULTS:
6262
remove_build_result(build_key=build_key, status=status)
@@ -68,7 +68,7 @@ def project_review(plans):
6868
for project in projects:
6969
if project in EXCLUDED_PROJECTS:
7070
continue
71-
print(("Inspecting project - {}".format(project)))
71+
print((f"Inspecting project - {project}"))
7272
results = []
7373
all_plans_of_project = get_plans_from_project(project)
7474
project_review(plans=all_plans_of_project)

examples/bamboo/bamboo_remove_unknown_status_build_results.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ def get_results_from_branch(plan_key):
3535
def remove_build_result(build_key, status):
3636
result = bamboo.build_result(build_key=build_key)
3737
if result.get("buildState") == status:
38-
print(("Removing build result - {}".format(build_key)))
38+
print(f"Removing build result - {build_key}")
3939
if REMOVE:
4040
bamboo.delete_build_result(build_key=build_key)
4141

4242

4343
def project_review(plans):
4444
for plan in plans:
45-
print(("Inspecting {} plan".format(plan)))
45+
print((f"Inspecting {plan} plan"))
4646
branches = get_branches_from_plan(plan)
4747
for branch in branches:
4848
build_results = get_results_from_branch(branch)
4949
for build in build_results:
5050
build_key = build.get("buildResultKey") or None
51-
print(("Inspecting build - {}".format(build_key)))
51+
print(f"Inspecting build - {build_key}")
5252
if build_key:
5353
for status in STATUS_CLEANED_RESULTS:
5454
remove_build_result(build_key=build_key, status=status)
@@ -60,7 +60,7 @@ def project_review(plans):
6060
for project in projects:
6161
if project in EXCLUDED_PROJECTS:
6262
continue
63-
print(("Inspecting project - {}".format(project)))
63+
print(f"Inspecting project - {project}")
6464
results = []
6565
all_plans_of_project = get_plans_from_project(project)
6666
project_review(plans=all_plans_of_project)

examples/bamboo/bamboo_trigger_builds_console_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def execute_build(build_key, params):
2525
params: dict
2626
"""
2727
started_build = bamboo.execute_build(build_key, **params)
28-
logging.info("Build execution status: {}".format(started_build.status_code))
28+
logging.info(f"Build execution status: {started_build.status_code}")
2929
if started_build.status_code == 200:
30-
logging.info("Build key: {}".format(started_build.json().get("buildResultKey")))
30+
logging.info(f"Build key: {started_build.json().get('buildResultKey')}")
3131
logging.info(started_build.json().get("link", {}).get("href"))
3232
else:
3333
logging.error("Execution failed!")

examples/bitbucket/bitbucket_check_last_auth_users.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def report(all=False, non_auth=False, limit=20):
2525
else:
2626
full_date = None
2727
if full_date:
28-
output = "{} ({}) authenticated on {}".format(user.get("displayName"), user.get("emailAddress"), full_date)
28+
output = f"{user.get('displayName')} ({user.get('emailAddress')}) authenticated on {full_date}"
2929
if all:
3030
print(output)
3131
else:
32-
output = "{} ({}) not authenticated yet".format(user.get("displayName"), user.get("emailAddress"))
32+
output = f"{user.get('displayName')} ({user.get('emailAddress')}) not authenticated yet"
3333
if non_auth or all:
3434
print(output)
3535

examples/bitbucket/bitbucket_clean_jira_branches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def is_can_removed_branch(branch_candidate):
9696
name=display_id,
9797
end_point=branch["latestCommit"],
9898
)
99-
log.write("{},{},{}\n".format(display_id, last_date_commit, True))
99+
log.write(f"{display_id},{last_date_commit},{True}\n")
100100
step += 1
101101
log.close()
102102
print("Done")

examples/bitbucket/bitbucket_manage_pull_request.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66

77
pr = bitbucket.get_pullrequest("project_name", "repository_name", pr_id)
88
ver = pr.json().get("version")
9-
print(("PR version: {}".format(ver)))
9+
print(f"PR version: {ver}")
1010

1111
response = bitbucket.decline_pull_request("project_name", "repository_name", pr_id, ver)
12-
print(("Declined: {}".format(response)))
12+
print(f"Declined: {response}")
1313
ver = response.json().get("version")
14-
print(("PR version: {}".format(ver)))
14+
print(f"PR version: {ver}")
1515

1616
response = bitbucket.reopen_pull_request("project_name", "repository_name", pr_id, ver)
17-
print(("Reopen: {}".format(response)))
17+
print(f"Reopen: {response}")
1818
ver = response.json().get("version")
19-
print(("PR version: {}".format(ver)))
19+
print(f"PR version: {ver}")
2020

2121
response = bitbucket.is_pull_request_can_be_merged("project_name", "repository_name", pr_id)
22-
print(("Reopen: {}".format(response)))
23-
print(("PR version: {}".format(ver)))
22+
print(f"Reopen: {response}")
23+
print(f"PR version: {ver}")
2424

2525
response = bitbucket.merge_pull_request("project_name", "repository_name", pr_id, ver)
26-
print(("Merged: {}".format(response)))
26+
print(f"Merged: {response}")

examples/bitbucket/bitbucket_oauth2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def callback():
4343
bitbucket = OAuth2Session(client_id, state=session["oauth_state"])
4444
token = bitbucket.fetch_token(token_url, client_secret=client_secret, authorization_response=request.url)
4545

46-
return "Token: {}<p />Workspaces: {}".format(token, ", ".join(get_workspaces(token)))
46+
return f"Token: {token}<p />Workspaces: {', '.join(get_workspaces(token))}"
4747

4848

4949
# 4. Token used for Bitbucket Python API

examples/bitbucket/stash_user_auth_report.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def report(limit=200, include_in_active=False):
2929
else:
3030
full_date = None
3131
if include_in_active or user.get("active"):
32-
output = "|{}|{}|{}|{}|".format(
33-
user.get("active"), user.get("displayName"), user.get("emailAddress"), full_date
34-
)
32+
output = f"|{user.get('active')}|{user.get('displayName')}|{user.get('emailAddress')}|{full_date}|"
3533
print(output)
3634

3735

examples/confluence/confluence_attach_file_as_link.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818

1919
confluence.attach_file(filename, page_id="123456789")
2020

21-
link = """<p>
21+
link = f"""<p>
2222
<ac:link>
23-
<ri:attachment ri:filename="{}"/>
23+
<ri:attachment ri:filename="{filename}"/>
2424
</ac:link>
25-
</p>""".format(
26-
filename
27-
)
25+
</p>"""
2826

2927
confluence.append_page(123456789, "Page Title", link)

0 commit comments

Comments
 (0)