Created
August 15, 2018 23:28
Revisions
-
alexreg created this gist
Aug 15, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ #!/usr/bin/env python3 import io import json from packaging import version import re import subprocess def get_crate_info(crate): with subprocess.Popen(["cargo", "info", "--json", crate], stdout = subprocess.PIPE) as proc: return json.load(proc.stdout) with subprocess.Popen(["cargo", "install", "--list"], stdout = subprocess.PIPE) as proc: re_crate = re.compile(r"(\w+) v([\d.]+):") for line in io.TextIOWrapper(proc.stdout, encoding = "utf-8"): line = line.rstrip() match = re_crate.fullmatch(line) if match: crate = match[1] installed_version = version.parse(match[2]) crate_info = get_crate_info(crate) latest_version = version.parse(crate_info["crate"]["max_version"]) print("Found crate '{}' v{} (latest v{})".format(crate, installed_version, latest_version)) if latest_version > installed_version: print("Updating crate '{}'...".format(crate)) subprocess.run(["cargo", "install", "--force", crate])