Spaces:
Starting
on
L40S
Starting
on
L40S
File size: 2,532 Bytes
d7e58f0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
import subprocess
from pathlib import Path
from typing import List
dest = "s3://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/"
output = Path("output")
def aws_s3_cmd(args) -> List[str]:
"""
This function returns the full args for subprocess to do a command
with aws.
"""
cmd_args = ["aws", "s3", "--profile", "saml"] + args
return cmd_args
def fs3_exists(path) -> bool:
"""
Returns True if the path exists inside dest on S3.
In fact, will also return True if there is a file which has the given
path as a prefix, but we are careful about this.
"""
out = subprocess.check_output(aws_s3_cmd(["ls", path]))
return len(out) != 0
def get_html_wrappers() -> None:
for directory in sorted(output.iterdir()):
output_wrapper = directory / "download.html"
assert not output_wrapper.exists()
dest_wrapper = dest + directory.name + "/download.html"
if fs3_exists(dest_wrapper):
subprocess.check_call(aws_s3_cmd(["cp", dest_wrapper, str(output_wrapper)]))
def write_html_wrappers() -> None:
html = """
<a href="$">$</a><br>
"""
for directory in sorted(output.iterdir()):
files = list(directory.glob("*.whl"))
assert len(files) == 1, files
[wheel] = files
this_html = html.replace("$", wheel.name)
output_wrapper = directory / "download.html"
if output_wrapper.exists():
contents = output_wrapper.read_text()
if this_html not in contents:
with open(output_wrapper, "a") as f:
f.write(this_html)
else:
output_wrapper.write_text(this_html)
def to_aws() -> None:
for directory in output.iterdir():
for file in directory.iterdir():
print(file)
subprocess.check_call(
aws_s3_cmd(["cp", str(file), dest + str(file.relative_to(output))])
)
if __name__ == "__main__":
# Uncomment this for subsequent releases.
# get_html_wrappers()
write_html_wrappers()
to_aws()
# see all files with
# aws s3 --profile saml ls --recursive s3://dl.fbaipublicfiles.com/pytorch3d/
# empty current with
# aws s3 --profile saml rm --recursive
# s3://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/
|