mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-12-09 15:57:43 +01:00
* downloader registration
git-svn-id: trunk@9283 -
This commit is contained in:
parent
47ecdea412
commit
ed3d9e1e5f
@ -17,6 +17,7 @@ uses
|
||||
// Downloaders
|
||||
{$if defined(unix) or defined(windows)}
|
||||
,pkgwget
|
||||
,pkglnet
|
||||
{$endif}
|
||||
;
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
unit pkgdownload;
|
||||
unit pkgDownload;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
@ -33,8 +33,8 @@ Type
|
||||
Function Execute(const Args:TActionArgs):boolean;override;
|
||||
end;
|
||||
|
||||
Var
|
||||
DownloaderClass : TBaseDownloaderClass;
|
||||
procedure RegisterDownloader(const AName:string;Downloaderclass:TBaseDownloaderClass);
|
||||
function GetDownloader(const AName:string):TBaseDownloaderClass;
|
||||
|
||||
procedure DownloadFile(const RemoteFile,LocalFile:String);
|
||||
|
||||
@ -42,13 +42,39 @@ procedure DownloadFile(const RemoteFile,LocalFile:String);
|
||||
implementation
|
||||
|
||||
uses
|
||||
contnrs,
|
||||
uriparser,
|
||||
pkgglobals,
|
||||
pkgoptions,
|
||||
pkgmessages;
|
||||
|
||||
var
|
||||
DownloaderList : TFPHashList;
|
||||
|
||||
procedure RegisterDownloader(const AName:string;Downloaderclass:TBaseDownloaderClass);
|
||||
begin
|
||||
if DownloaderList.Find(AName)<>nil then
|
||||
begin
|
||||
Error('Downloader already registered');
|
||||
exit;
|
||||
end;
|
||||
DownloaderList.Add(AName,Downloaderclass);
|
||||
end;
|
||||
|
||||
|
||||
function GetDownloader(const AName:string):TBaseDownloaderClass;
|
||||
begin
|
||||
result:=TBaseDownloaderClass(DownloaderList.Find(AName));
|
||||
if result=nil then
|
||||
Error('Downloader %s not supported',[AName]);
|
||||
end;
|
||||
|
||||
|
||||
procedure DownloadFile(const RemoteFile,LocalFile:String);
|
||||
var
|
||||
DownloaderClass : TBaseDownloaderClass;
|
||||
begin
|
||||
DownloaderClass:=GetDownloader(GlobalOptions.Downloader);
|
||||
with DownloaderClass.Create(nil) do
|
||||
try
|
||||
Download(RemoteFile,LocalFile);
|
||||
@ -132,7 +158,10 @@ end;
|
||||
{ TDownloadPackage }
|
||||
|
||||
function TDownloadPackage.Execute(const Args:TActionArgs):boolean;
|
||||
var
|
||||
DownloaderClass : TBaseDownloaderClass;
|
||||
begin
|
||||
DownloaderClass:=GetDownloader(GlobalOptions.Downloader);
|
||||
with DownloaderClass.Create(nil) do
|
||||
try
|
||||
Log(vCommands,SLogDownloading,[PackageRemoteArchive,PackageLocalArchive]);
|
||||
@ -144,9 +173,10 @@ end;
|
||||
|
||||
|
||||
initialization
|
||||
// Default value.
|
||||
DownloaderClass := TBaseDownloader;
|
||||
|
||||
RegisterPkgHandler('downloadpackage',TDownloadPackage);
|
||||
DownloaderList:=TFPHashList.Create;
|
||||
RegisterDownloader('base',TBaseDownloader);
|
||||
RegisterPkgHandler('Downloadpackage',TDownloadPackage);
|
||||
finalization
|
||||
FreeAndNil(DownloaderList);
|
||||
end.
|
||||
|
||||
|
||||
@ -175,6 +175,5 @@ begin
|
||||
end;
|
||||
|
||||
initialization
|
||||
DownloaderClass:=TLNetDownloader;
|
||||
|
||||
RegisterDownloader('lnet',TLNetDownloader);
|
||||
end.
|
||||
|
||||
@ -38,6 +38,7 @@ Type
|
||||
FPackagesDir,
|
||||
FBuildDir,
|
||||
FDefaultVerbosity,
|
||||
FDownloader,
|
||||
FDefaultCompilerConfig,
|
||||
FFPMakeCompilerConfig : String;
|
||||
// Parameter options
|
||||
@ -68,6 +69,7 @@ Type
|
||||
Property DefaultVerbosity : String Index 7 Read GetOptString Write SetOptString;
|
||||
Property DefaultCompilerConfig : String Index 8 Read GetOptString Write SetOptString;
|
||||
Property FPMakeCompilerConfig : String Index 9 Read GetOptString Write SetOptString;
|
||||
Property Downloader: String Index 10 Read GetOptString Write SetOptString;
|
||||
// Parameters
|
||||
Property CompilerConfig : String Read FCompilerConfig Write FCompilerConfig;
|
||||
Property InstallGlobal : Boolean Read FInstallGlobal Write FInstallGlobal;
|
||||
@ -152,6 +154,7 @@ Const
|
||||
KeyVerbosity = 'Verbosity';
|
||||
KeyCompilerConfig = 'CompilerConfig';
|
||||
KeyFPMakeCompilerConfig = 'FPMakeCompilerConfig';
|
||||
KeyDownloader = 'Downloader';
|
||||
|
||||
// Compiler dependent config
|
||||
KeyGlobalInstallDir = 'GlobalInstallDir';
|
||||
@ -185,6 +188,7 @@ begin
|
||||
7 : Result:=FDefaultVerbosity;
|
||||
8 : Result:=FDefaultCompilerConfig;
|
||||
9 : Result:=FFPMakeCompilerConfig;
|
||||
10 : Result:=FDownloader;
|
||||
else
|
||||
Error('Unknown option');
|
||||
end;
|
||||
@ -205,6 +209,7 @@ begin
|
||||
7 : FDefaultVerbosity:=AValue;
|
||||
8 : FDefaultCompilerConfig:=AValue;
|
||||
9 : FFPMakeCompilerConfig:=AValue;
|
||||
10 : FDownloader:=AValue;
|
||||
else
|
||||
Error('Unknown option');
|
||||
end;
|
||||
@ -263,6 +268,12 @@ begin
|
||||
FDefaultVerbosity:='error,warning,info,debug,commands';
|
||||
FDefaultCompilerConfig:='default';
|
||||
FFPMakeCompilerConfig:='default';
|
||||
// Downloader
|
||||
{$if defined(unix) or defined(windows)}
|
||||
FDownloader:='lnet';
|
||||
{$else}
|
||||
FDownloader:='base';
|
||||
{$endif}
|
||||
// Parameter defaults
|
||||
FCompilerConfig:=FDefaultCompilerConfig;
|
||||
FInstallGlobal:=False;
|
||||
@ -286,6 +297,7 @@ begin
|
||||
FDefaultVerbosity:=ReadString(SDefaults,KeyVerbosity,FDefaultVerbosity);
|
||||
FDefaultCompilerConfig:=ReadString(SDefaults,KeyCompilerConfig,FDefaultCompilerConfig);
|
||||
FFPMakeCompilerConfig:=ReadString(SDefaults,KeyFPMakeCompilerConfig,FFPMakeCompilerConfig);
|
||||
FDownloader:=ReadString(SDefaults,KeyDownloader,FDownloader);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -305,6 +317,7 @@ begin
|
||||
WriteString(SDefaults,KeyVerbosity,FDefaultVerbosity);
|
||||
WriteString(SDefaults,KeyCompilerConfig,FDefaultCompilerConfig);
|
||||
WriteString(SDefaults,KeyFPMakeCompilerConfig,FFPMakeCompilerConfig);
|
||||
WriteString(SDefaults,KeyDownloader,FDownloader);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
@ -72,5 +72,5 @@ begin
|
||||
end;
|
||||
|
||||
initialization
|
||||
DownloaderClass:=TWGetDownloader;
|
||||
RegisterDownloader('wget',TWGetDownloader);
|
||||
end.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user