Skip to content

Commit

Permalink
Separate download.* files
Browse files Browse the repository at this point in the history
  • Loading branch information
mtorpey committed Sep 4, 2024
1 parent 8dfe082 commit 3a54900
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 105 deletions.
7 changes: 0 additions & 7 deletions gap/PackageManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
49 changes: 0 additions & 49 deletions gap/PackageManager.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions gap/download.gd
Original file line number Diff line number Diff line change
@@ -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", "-"] ] ];
48 changes: 48 additions & 0 deletions gap/download.gi
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions init.g
Original file line number Diff line number Diff line change
Expand Up @@ -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");
1 change: 1 addition & 0 deletions read.g
Original file line number Diff line number Diff line change
Expand Up @@ -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");
49 changes: 0 additions & 49 deletions tst/PackageManager.tst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions tst/download.tst
Original file line number Diff line number Diff line change
@@ -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;;

0 comments on commit 3a54900

Please sign in to comment.