parent
4436a110cf
commit
628fb7c494
1 changed files with 18 additions and 5 deletions
|
@ -150,14 +150,27 @@ def local_crate(crate, version):
|
|||
cratename, version = os.path.basename(crate)[:-6].rsplit("-", 1)
|
||||
return crate, cratename, version
|
||||
|
||||
def query_newest_version(crate):
|
||||
url = requests.compat.urljoin(API_URL, f"crates/{crate}/versions")
|
||||
req = requests.get(url, headers={"User-Agent": "rust2rpm"})
|
||||
req.raise_for_status()
|
||||
versions = req.json()["versions"]
|
||||
for struct in versions:
|
||||
version = struct["num"]
|
||||
if struct["yanked"]:
|
||||
print(f'Ignoring yanked version {version}')
|
||||
elif re.search('alpha|beta|rc|pre', version):
|
||||
print(f'Ignoring pre-release version {version}')
|
||||
else:
|
||||
print(f'Found version {version}')
|
||||
return version
|
||||
|
||||
raise ValueError("Couldn't find any release versions. Specify a version explicitly.")
|
||||
|
||||
def download(crate, version):
|
||||
if version is None:
|
||||
# Now we need to get latest version
|
||||
url = requests.compat.urljoin(API_URL, f"crates/{crate}/versions")
|
||||
req = requests.get(url, headers={"User-Agent": "rust2rpm"})
|
||||
req.raise_for_status()
|
||||
versions = req.json()["versions"]
|
||||
version = next(version["num"] for version in versions if not version["yanked"])
|
||||
version = query_newest_version(crate)
|
||||
|
||||
os.makedirs(CACHEDIR, exist_ok=True)
|
||||
cratef_base = f"{crate}-{version}.crate"
|
||||
|
|
Loading…
Reference in a new issue