forked from opencobra/COBRA.models
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateModels.jl
103 lines (77 loc) · 2.91 KB
/
updateModels.jl
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using JSON, SHA
function downloadModelZipFile(filename, url=""; fileToBeRenamed="", location=pwd())
# modelName
modelName = "model.zip"
# create a temporary directory
tempDirPath = mktempdir()
# change to the temporary directory
cd(tempDirPath)
println(" > downloadModelZipFile | The directory is: $tempDirPath")
#modelFile = HTTP.get(url)
download(url, modelName)
# unzip the file
run(`unzip -qq $modelName`)
# rename unzipped file if necessary
if ~isempty(fileToBeRenamed)
println(" > downloadModelZipFile | Moving $fileToBeRenamed to $filename")
mv(fileToBeRenamed, filename, force=true);
end
# remove the temporary folder
rm(tempDirPath, recursive=true)
# print feedback message
println(" > downloadModelZipFile | Temporary download folder $tempDirPath removed.")
println(" > downloadModelZipFile | Model from .zip file stored in $location")
end
# set the environment variables
if !("ARTENOLIS_DATA_PATH" in keys(ENV))
ENV["ARTENOLIS_DATA_PATH"] = "/tmp"
end
if !("ARTENOLIS_EMAIL" in keys(ENV))
ENV["ARTENOLIS_EMAIL"] = "[email protected]"
end
# create a temporary directory
tempDirPath = mktempdir()
repoDir = ENV["ARTENOLIS_DATA_PATH"] * "/repos/COBRA.models"
# change directory
cd(repoDir)
# parse the JSON list of models
listModels = JSON.parsefile("models.json")
println(" > The temporary directory is: $tempDirPath")
# counters
counter = 0
# loop through the models and download them
for model in listModels
global counter
modelExt = model["name"][end-3:end]
modelName = tempDirPath*"/"*model["name"]
if model["url"][end-3:end] == ".mat" || model["url"][end-3:end] == ".xml"
# download the file name
download(model["url"], modelName)
# get the original model
modelOrig = modelExt[2:end]*"/"*model["name"]
else
modelOrig = model["name"][end-2:end]*"/"*model["name"]
downloadModelZipFile(modelName, model["url"], fileToBeRenamed=model["fileToBeRenamed"], location=tempDirPath)
end
# save the checksum
checkSum = bytes2hex(sha256(read(modelName)))
checkSumOrig = bytes2hex(sha256(read(repoDir*"/"*modelOrig)))
if checkSum == checkSumOrig
println(" - SAME: $(model["name"]) [new: $checkSum | orig: $checkSumOrig]")
else
println(" + DIFFERENT: $(model["name"]) [new: $checkSum | orig: $checkSumOrig]")
counter = counter + 1
end
end
# print a feedback message
if counter > 0
run(pipeline(`echo "[COBRA.models] Models are different"`, `mail -s "+ [COBRA.models] Models are different" $(ENV["ARTENOLIS_EMAIL"])`))
else
run(pipeline(`echo "[COBRA.models] Models are the same"`, `mail -s "- [COBRA.models] Models are the same" $(ENV["ARTENOLIS_EMAIL"])`))
end
# remove the temporary folder
rm(tempDirPath, recursive=true)
# print feedback message
println(" > Folder $tempDirPath has been removed.\n > Done.")
# exit
exit()