diff --git a/gap/PackageManager.gd b/gap/PackageManager.gd index f6d4c19..d50ece8 100644 --- a/gap/PackageManager.gd +++ b/gap/PackageManager.gd @@ -175,20 +175,13 @@ DeclareGlobalFunction("PKGMAN_IsValidTargetDir"); DeclareGlobalFunction("PKGMAN_RefreshPackageInfo"); DeclareGlobalFunction("PKGMAN_InsertPackageDirectory"); DeclareGlobalFunction("PKGMAN_SetCustomPackageDir"); -DeclareGlobalFunction("PKGMAN_DownloadURL"); DeclareGlobalFunction("PKGMAN_RemoveDir"); -DeclareGlobalFunction("PKGMAN_DownloadPackageInfo"); DeclareGlobalFunction("PKGMAN_ValidatePackageInfo"); DeclareGlobalFunction("PKGMAN_InfoWithIndent"); # Hidden variables PKGMAN_CustomPackageDir := ""; PKGMAN_ArchiveFormats := [".tar.gz", ".tar.bz2"]; -PKGMAN_DownloadCmds := [ [ "wget", ["--quiet", "-O", "-"] ], - [ "curl", ["--silent", "-L", "--output", "-"] ] ]; -PKGMAN_CurlIntReqVer := - First(PackageInfo("PackageManager")[1].Dependencies.SuggestedOtherPackages, - item -> item[1] = "curlInterface")[2]; PKGMAN_Sysinfo := Filename(DirectoriesLibrary(""), "sysinfo.gap"); # PackageInfo must at least contain the following to pass: diff --git a/gap/PackageManager.gi b/gap/PackageManager.gi index 2aa925d..a3a671f 100644 --- a/gap/PackageManager.gi +++ b/gap/PackageManager.gi @@ -624,33 +624,6 @@ function(dir) # No return value end); -InstallGlobalFunction(PKGMAN_DownloadURL, -function(url) - local tool, exec; - - # Use curlInterface if available - if TestPackageAvailability("curlInterface", PKGMAN_CurlIntReqVer) = true then - Info(InfoPackageManager, 4, "Using curlInterface to download..."); - return ValueGlobal("DownloadURL")(url); - fi; - - # Try command line tools (wget/curl) - for tool in PKGMAN_DownloadCmds do - Info(InfoPackageManager, 4, "Using ", tool[1], " to download..."); - exec := CallFuncList(PKGMAN_Exec, - Concatenation(["."], [tool[1]], tool[2], [url])); - if exec = fail then - Info(InfoPackageManager, 4, tool[1], " unavailable"); - elif exec.code <> 0 then - Info(InfoPackageManager, 4, "Download failed with ", tool[1]); - else - return rec(success := true, result := exec.output); - fi; - od; - - return rec(success := false, error := "no download method is available"); -end); - InstallGlobalFunction(PKGMAN_RemoveDir, function(dir) # this 'if' statement is a paranoid check - it should always be true @@ -661,28 +634,6 @@ function(dir) fi; end); -InstallGlobalFunction(PKGMAN_DownloadPackageInfo, -function(url) - local get, info; - - Info(InfoPackageManager, 3, "Retrieving PackageInfo.g from ", url, " ..."); - get := PKGMAN_DownloadURL(url); - if not get.success then - Info(InfoPackageManager, 1, "Unable to download from ", url); - return fail; - fi; - info := PKGMAN_GetPackageInfo(InputTextString(get.result)); - - # Read the information we want from it - if PKGMAN_ValidatePackageInfo(info) then - Info(InfoPackageManager, 4, "PackageInfo.g validated successfully"); - else - Info(InfoPackageManager, 1, "PackageInfo.g validation failed"); - Info(InfoPackageManager, 1, "There may be problems with the package"); - fi; - return ShallowCopy(info); -end); - InstallGlobalFunction(PKGMAN_ValidatePackageInfo, function(info) local quiet; diff --git a/gap/download.gd b/gap/download.gd new file mode 100644 index 0000000..62138ee --- /dev/null +++ b/gap/download.gd @@ -0,0 +1,11 @@ +DeclareGlobalFunction("PKGMAN_DownloadURL"); +DeclareGlobalFunction("PKGMAN_DownloadPackageInfo"); + +# curlInterface minimum version worth using +PKGMAN_CurlIntReqVer := + First(PackageInfo("PackageManager")[1].Dependencies.SuggestedOtherPackages, + item -> item[1] = "curlInterface")[2]; + +# Shell commands used for downloading if curlInterface not loaded +PKGMAN_DownloadCmds := [ [ "wget", ["--quiet", "-O", "-"] ], + [ "curl", ["--silent", "-L", "--output", "-"] ] ]; diff --git a/gap/download.gi b/gap/download.gi new file mode 100644 index 0000000..4381ea8 --- /dev/null +++ b/gap/download.gi @@ -0,0 +1,48 @@ +InstallGlobalFunction(PKGMAN_DownloadURL, +function(url) + local tool, exec; + + # Use curlInterface if available + if TestPackageAvailability("curlInterface", PKGMAN_CurlIntReqVer) = true then + Info(InfoPackageManager, 4, "Using curlInterface to download..."); + return ValueGlobal("DownloadURL")(url); + fi; + + # Try command line tools (wget/curl) + for tool in PKGMAN_DownloadCmds do + Info(InfoPackageManager, 4, "Using ", tool[1], " to download..."); + exec := CallFuncList(PKGMAN_Exec, + Concatenation(["."], [tool[1]], tool[2], [url])); + if exec = fail then + Info(InfoPackageManager, 4, tool[1], " unavailable"); + elif exec.code <> 0 then + Info(InfoPackageManager, 4, "Download failed with ", tool[1]); + else + return rec(success := true, result := exec.output); + fi; + od; + + return rec(success := false, error := "no download method is available"); +end); + +InstallGlobalFunction(PKGMAN_DownloadPackageInfo, +function(url) + local get, info; + + Info(InfoPackageManager, 3, "Retrieving PackageInfo.g from ", url, " ..."); + get := PKGMAN_DownloadURL(url); + if not get.success then + Info(InfoPackageManager, 1, "Unable to download from ", url); + return fail; + fi; + info := PKGMAN_GetPackageInfo(InputTextString(get.result)); + + # Read the information we want from it + if PKGMAN_ValidatePackageInfo(info) then + Info(InfoPackageManager, 4, "PackageInfo.g validated successfully"); + else + Info(InfoPackageManager, 1, "PackageInfo.g validation failed"); + Info(InfoPackageManager, 1, "There may be problems with the package"); + fi; + return ShallowCopy(info); +end); diff --git a/init.g b/init.g index 797e59f..b7258a1 100644 --- a/init.g +++ b/init.g @@ -8,6 +8,7 @@ ReadPackage("PackageManager", "gap/PackageManager.gd"); ReadPackage("PackageManager", "gap/compile.gd"); ReadPackage("PackageManager", "gap/distro.gd"); ReadPackage("PackageManager", "gap/doc.gd"); +ReadPackage("PackageManager", "gap/download.gd"); ReadPackage("PackageManager", "gap/git.gd"); ReadPackage("PackageManager", "gap/hg.gd"); ReadPackage("PackageManager", "gap/interactive.gd"); diff --git a/read.g b/read.g index 09dc5a7..82d7e11 100644 --- a/read.g +++ b/read.g @@ -8,6 +8,7 @@ ReadPackage("PackageManager", "gap/PackageManager.gi"); ReadPackage("PackageManager", "gap/compile.gi"); ReadPackage("PackageManager", "gap/distro.gi"); ReadPackage("PackageManager", "gap/doc.gi"); +ReadPackage("PackageManager", "gap/download.gi"); ReadPackage("PackageManager", "gap/git.gi"); ReadPackage("PackageManager", "gap/hg.gi"); ReadPackage("PackageManager", "gap/interactive.gi"); diff --git a/tst/PackageManager.tst b/tst/PackageManager.tst index e4cb0a6..2f52c24 100644 --- a/tst/PackageManager.tst +++ b/tst/PackageManager.tst @@ -144,61 +144,12 @@ fail gap> PKGMAN_InsertPackageDirectory("/home"); # not ending in pkg fail -# Missing curlInterface: use wget instead -gap> ver := PKGMAN_CurlIntReqVer;; -gap> PKGMAN_CurlIntReqVer := ">= 100.0";; -gap> InstallPackage("https://gap-packages.github.io/Memoisation/PackageInfo.g"); -true -gap> RemovePackage("Memoisation", false); -true -gap> PKGMAN_CurlIntReqVer := ver;; - -# wget failure -gap> ver := PKGMAN_CurlIntReqVer;; -gap> PKGMAN_CurlIntReqVer := ">= 100.0";; -gap> InstallPackage("www.gap.rubbish/somepackage.tar.gz"); -#I Could not download from www.gap.rubbish/somepackage.tar.gz -false -gap> PKGMAN_CurlIntReqVer := ver;; - -# Missing curlInterface: use curl instead -gap> ver := PKGMAN_CurlIntReqVer;; -gap> PKGMAN_CurlIntReqVer := ">= 100.0";; -gap> tmp := PKGMAN_DownloadCmds[1];; -gap> PKGMAN_DownloadCmds[1] := PKGMAN_DownloadCmds[2];; -gap> PKGMAN_DownloadCmds[2] := tmp;; -gap> PKGMAN_DownloadCmds[1][1]; -"curl" -gap> InstallPackage("uuid"); -true -gap> RemovePackage("uuid", false); -true -gap> PKGMAN_CurlIntReqVer := ver;; - # Install to existing empty directory gap> CreateDir(Filename(Directory(PKGMAN_PackageDir()), "Toric-1.9.5")); true gap> InstallPackage("https://github.com/gap-packages/toric/releases/download/v1.9.5/Toric-1.9.5.tar.gz"); true -# curl failure -gap> ver := PKGMAN_CurlIntReqVer;; -gap> PKGMAN_CurlIntReqVer := ">= 100.0";; -gap> PKGMAN_DownloadCmds[1][1]; -"curl" -gap> InstallPackage("www.gap.rubbish/somepackage.tar.gz"); -#I Could not download from www.gap.rubbish/somepackage.tar.gz -false -gap> PKGMAN_CurlIntReqVer := ver;; - -# Missing first command -gap> ver := PKGMAN_CurlIntReqVer;; -gap> PKGMAN_CurlIntReqVer := ">= 100.0";; -gap> PKGMAN_DownloadCmds[1][1] := "abababaxyz";; -gap> InstallPackage("crypting"); -true -gap> PKGMAN_CurlIntReqVer := ver;; - # Updating old package that doesn't have the version number in its directory name gap> InstallPackage("https://www.math.colostate.edu/~hulpke/transgrp/transgrp3.6.4.tar.gz"); true diff --git a/tst/download.tst b/tst/download.tst new file mode 100644 index 0000000..ca01494 --- /dev/null +++ b/tst/download.tst @@ -0,0 +1,48 @@ +# Missing curlInterface: use wget instead +gap> ver := PKGMAN_CurlIntReqVer;; +gap> PKGMAN_CurlIntReqVer := ">= 100.0";; +gap> InstallPackage("https://gap-packages.github.io/Memoisation/PackageInfo.g"); +true +gap> RemovePackage("Memoisation", false); +true +gap> PKGMAN_CurlIntReqVer := ver;; + +# wget failure +gap> ver := PKGMAN_CurlIntReqVer;; +gap> PKGMAN_CurlIntReqVer := ">= 100.0";; +gap> InstallPackage("www.gap.rubbish/somepackage.tar.gz"); +#I Could not download from www.gap.rubbish/somepackage.tar.gz +false +gap> PKGMAN_CurlIntReqVer := ver;; + +# Missing curlInterface: use curl instead +gap> ver := PKGMAN_CurlIntReqVer;; +gap> PKGMAN_CurlIntReqVer := ">= 100.0";; +gap> tmp := PKGMAN_DownloadCmds[1];; +gap> PKGMAN_DownloadCmds[1] := PKGMAN_DownloadCmds[2];; +gap> PKGMAN_DownloadCmds[2] := tmp;; +gap> PKGMAN_DownloadCmds[1][1]; +"curl" +gap> InstallPackage("uuid"); +true +gap> RemovePackage("uuid", false); +true +gap> PKGMAN_CurlIntReqVer := ver;; + +# curl failure +gap> ver := PKGMAN_CurlIntReqVer;; +gap> PKGMAN_CurlIntReqVer := ">= 100.0";; +gap> PKGMAN_DownloadCmds[1][1]; +"curl" +gap> InstallPackage("www.gap.rubbish/somepackage.tar.gz"); +#I Could not download from www.gap.rubbish/somepackage.tar.gz +false +gap> PKGMAN_CurlIntReqVer := ver;; + +# Missing first command +gap> ver := PKGMAN_CurlIntReqVer;; +gap> PKGMAN_CurlIntReqVer := ">= 100.0";; +gap> PKGMAN_DownloadCmds[1][1] := "abababaxyz";; +gap> InstallPackage("crypting"); +true +gap> PKGMAN_CurlIntReqVer := ver;;