-
Notifications
You must be signed in to change notification settings - Fork 8
/
WebInstall.m
63 lines (51 loc) · 1.98 KB
/
WebInstall.m
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
(* ::Package:: *)
(* ::Subsection:: *)
(*Update code*)
Needs["JLink`"];
Needs["Utilities`URLTools`"];
InstallJava[];
httpGet[url_String]:=
JavaBlock@Module[{http,get},
http=JavaNew["org.apache.commons.httpclient.HttpClient"];
get=JavaNew["org.apache.commons.httpclient.methods.GetMethod",url];
http@executeMethod[get];
get@addRequestHeader["content-type","application/json"];
get@getResponseBodyAsString[]
];
latestRelease[]:=
Module[{code,tags},
code = httpGet["https://api.github.com/repos/opencobra/MASS-Toolbox/releases"];
tags = StringTake[Select[StringSplit[code,","],StringMatchQ[#,"\"tag_name"~~___]&],14;;-2];
First[tags]
];
Clear[Global`progress];
Module[{version,directory,fileName,url,progFunction,task1,task2,newDirectory,installNotebook,nb},
(* Find latest version *)
version = latestRelease[];
(* Download tar file *)
directory = $TemporaryDirectory;
fileName=directory<>"/MASS-Toolbox-"<>version<>".tar.gz";
Print["Please wait. Downloading Toolbox v"<>version<>"..."];
url="https://github.com/opencobra/MASS-Toolbox/archive/v"<>version<>".tar.gz";
Global`progress= 0.;
Monitor[Null,Null];
progFunction[_, "progress", {dlnow_, dltotal_, _, _}]:= Quiet[Global`progress = dlnow/dltotal];
task1=URLDownload[url, fileName];
Print["Download Complete!"];
(* Extract files *)
newDirectory=FileNameJoin[{directory,"MASS-Toolbox-"<>version}];
Quiet@DeleteFile[FileNameJoin[{directory,"pax_global_header"}]];
Quiet@DeleteDirectory[newDirectory,DeleteContents->True];
Print["Please wait. Extracting Files..."];
task2=ExtractArchive[fileName,directory];
WaitAsynchronousTask[task2];
(* Install new Toolbox *)
Print["Installing Toolbox..."];
installNotebook=FileNameJoin[{newDirectory,"Installer.nb"}];
nb=NotebookOpen[installNotebook];
SelectionMove[nb,Next,Cell,3];
SelectionEvaluate[nb];
SelectionMove[nb,Next,Cell,1];
SelectionEvaluate[nb];
Print["The MASS Toolbox was successfully installed! To load the Toolbox, quit the kernel and run \"<<Toolbox`\""];
];