diff --git a/Cargo.lock b/Cargo.lock index ca67db5..18725f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -615,6 +615,8 @@ dependencies = [ "once_cell", "rustls 0.21.12", "rustls-webpki 0.101.7", + "serde", + "serde_json", "webpki-roots 0.25.4", ] @@ -649,6 +651,7 @@ dependencies = [ "minreq", "semver", "serde", + "serde_json", "toml", "ureq", "zip", @@ -758,9 +761,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.16" +version = "0.23.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" +checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1" dependencies = [ "log", "once_cell", @@ -1042,27 +1045,30 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "ureq" -version = "2.10.1" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b74fc6b57825be3373f7054754755f03ac3a8f5d70015ccad699ba2029956f4a" +checksum = "b30e6f97efe1fa43535ee241ee76967d3ff6ff3953ebb430d8d55c5393029e7b" dependencies = [ "base64", "flate2", + "litemap", "log", "once_cell", - "rustls 0.23.16", + "rustls 0.23.19", "rustls-pki-types", "serde", "serde_json", "url", - "webpki-roots 0.26.6", + "webpki-roots 0.26.7", + "yoke", + "zerofrom", ] [[package]] name = "url" -version = "2.5.3" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ "form_urlencoded", "idna", @@ -1107,9 +1113,9 @@ checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" [[package]] name = "webpki-roots" -version = "0.26.6" +version = "0.26.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +checksum = "5d642ff16b7e79272ae451b7322067cdc17cadf68c23264be9d94a32319efe7e" dependencies = [ "rustls-pki-types", ] @@ -1222,9 +1228,9 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", @@ -1264,9 +1270,9 @@ dependencies = [ [[package]] name = "zerofrom-derive" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 54d6a3d..d24154b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ home = "0.5.9" minreq = { version = "2.12.0", features = ["https", "json-using-serde"] } semver = { version = "1.0.23", features = ["serde"] } serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" toml = "0.8.19" ureq = { version = "2.10.1", features = ["json"] } zip = "2.2.0" diff --git a/src/utils/utils.rs b/src/utils/utils.rs index c3a0f9b..611c58d 100644 --- a/src/utils/utils.rs +++ b/src/utils/utils.rs @@ -9,6 +9,7 @@ use std::{ path::PathBuf, process, }; +use serde_json::{Value}; // todo docstring pub fn user_string_to_version(version: Option<&String>) -> Version { @@ -120,6 +121,42 @@ pub fn download_file(file_url: &str, file_path: &PathBuf) { } } +/// Takes the major and minor version and returns the full version using https://endoflife.date/api/python.json +/// +/// # Arguments +/// - `major_minor_version` : a string representing the "x.y" part of the release +/// +/// # Output +/// - Will output the full version from the provided major & minor +/// +/// #Termination +/// - An error should be thrown if the file for checking is not found, or if the version is not found. +/// +/// # Limitations +/// - The function assumes that all data passed to it is in the correct format +pub fn get_full_python_version(major_minor_version : &str) -> Option { + let response = match minreq::get("https://endoflife.date/api/python.json").send() { + Ok(res) if (res.status_code == 200) => res, + Ok(_) => abort("todo", None), + Err(e) =>abort("todo", Some(&e)) + }; + + let json = response.json::().unwrap(); + + if let Some(json) = json.as_array() { + for item in json { + for (key, value) in item.as_object().unwrap() { + if (key == "cycle") && (value == major_minor_version){ + // returns the latest + return Some(item["latest"].to_string()); + } + } + } + } + return None; +} + + /// Checks if the specified dependencies are installed by running their `--help` command. /// /// # Arguments