save cache into $XDG_CACHE_HOME/rust2rpm

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
This commit is contained in:
Igor Gnatenko 2017-02-05 13:56:50 +01:00
parent 281f6f3c89
commit 619f221cc0

View file

@ -10,6 +10,8 @@ import requests
import cargodeps import cargodeps
XDG_CACHE_HOME = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache"))
CACHEDIR = os.path.join(XDG_CACHE_HOME, "rust2rpm")
API_URL = "https://crates.io/api/v1/" API_URL = "https://crates.io/api/v1/"
TEMPLATE = """# Generated by rust2rpm TEMPLATE = """# Generated by rust2rpm
%bcond_without check %bcond_without check
@ -111,7 +113,9 @@ if __name__ == "__main__":
req.raise_for_status() req.raise_for_status()
args.version = req.json()["versions"][0]["num"] args.version = req.json()["versions"][0]["num"]
cratef = "{}-{}.crate".format(args.crate, args.version) if not os.path.isdir(CACHEDIR):
os.mkdir(CACHEDIR)
cratef = os.path.join(CACHEDIR, "{}-{}.crate".format(args.crate, args.version))
if not os.path.isfile(cratef): if not os.path.isfile(cratef):
url = requests.compat.urljoin(API_URL, "crates/{}/{}/download#".format(args.crate, args.version)) url = requests.compat.urljoin(API_URL, "crates/{}/{}/download#".format(args.crate, args.version))
req = requests.get(url, stream=True) req = requests.get(url, stream=True)