Skip to content

Commit ad59d0b

Browse files
authored
Refactor duplicate file upload code (#182)
1 parent 6ec0cb7 commit ad59d0b

File tree

1 file changed

+15
-36
lines changed

1 file changed

+15
-36
lines changed

run_release.py

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def mkdir(
671671
raise
672672

673673

674-
def upload_files_to_server(db: ReleaseShelf) -> None:
674+
def upload_files_to_server(db: ReleaseShelf, server: str) -> None:
675675
client = paramiko.SSHClient()
676676
client.load_system_host_keys()
677677
client.set_missing_host_key_policy(paramiko.WarningPolicy)
@@ -702,12 +702,20 @@ def upload_subdir(subdir: str) -> None:
702702
progress=progress,
703703
)
704704

705-
upload_subdir("src")
706-
if (artifacts_path / "docs").exists():
705+
if server == DOCS_SERVER:
707706
upload_subdir("docs")
707+
elif server == DOWNLOADS_SERVER:
708+
upload_subdir("src")
709+
if (artifacts_path / "docs").exists():
710+
upload_subdir("docs")
711+
708712
ftp_client.close()
709713

710714

715+
def upload_files_to_downloads_server(db: ReleaseShelf) -> None:
716+
upload_files_to_server(db, DOWNLOADS_SERVER)
717+
718+
711719
def place_files_in_download_folder(db: ReleaseShelf) -> None:
712720
client = paramiko.SSHClient()
713721
client.load_system_host_keys()
@@ -752,38 +760,7 @@ def upload_docs_to_the_docs_server(db: ReleaseShelf) -> None:
752760
if not (release_tag.is_final or release_tag.is_release_candidate):
753761
return
754762

755-
client = paramiko.SSHClient()
756-
client.load_system_host_keys()
757-
client.set_missing_host_key_policy(paramiko.WarningPolicy)
758-
client.connect(DOCS_SERVER, port=22, username=db["ssh_user"])
759-
transport = client.get_transport()
760-
assert transport is not None, f"SSH transport to {DOCS_SERVER} is None"
761-
762-
destination = Path(f"/home/psf-users/{db['ssh_user']}/{db['release']}")
763-
ftp_client = MySFTPClient.from_transport(transport)
764-
assert ftp_client is not None, f"SFTP client to {DOCS_SERVER} is None"
765-
766-
client.exec_command(f"rm -rf {destination}")
767-
768-
with contextlib.suppress(OSError):
769-
ftp_client.mkdir(str(destination))
770-
771-
artifacts_path = Path(db["git_repo"] / str(db["release"]))
772-
773-
shutil.rmtree(artifacts_path / f"Python-{db['release']}", ignore_errors=True)
774-
775-
def upload_subdir(subdir: str) -> None:
776-
with contextlib.suppress(OSError):
777-
ftp_client.mkdir(str(destination / subdir))
778-
with alive_bar(len(tuple((artifacts_path / subdir).glob("**/*")))) as progress:
779-
ftp_client.put_dir(
780-
artifacts_path / subdir,
781-
str(destination / subdir),
782-
progress=progress,
783-
)
784-
785-
upload_subdir("docs")
786-
ftp_client.close()
763+
upload_files_to_server(db, DOCS_SERVER)
787764

788765

789766
def unpack_docs_in_the_docs_server(db: ReleaseShelf) -> None:
@@ -1304,7 +1281,9 @@ def _api_key(api_key: str) -> str:
13041281
Task(check_doc_unreleased_version, "Check docs for `(unreleased)`"),
13051282
Task(build_sbom_artifacts, "Building SBOM artifacts"),
13061283
*([] if no_gpg else [Task(sign_source_artifacts, "Sign source artifacts")]),
1307-
Task(upload_files_to_server, "Upload files to the PSF server"),
1284+
Task(
1285+
upload_files_to_downloads_server, "Upload files to the PSF downloads server"
1286+
),
13081287
Task(place_files_in_download_folder, "Place files in the download folder"),
13091288
Task(upload_docs_to_the_docs_server, "Upload docs to the PSF docs server"),
13101289
Task(unpack_docs_in_the_docs_server, "Place docs files in the docs folder"),

0 commit comments

Comments
 (0)