* Added libcurl downloader and implemented new command style as in smart/svn/cvs

git-svn-id: trunk@5270 -
This commit is contained in:
michael 2006-11-06 23:17:09 +00:00
parent c7147a9412
commit a6a300cbbe
6 changed files with 261 additions and 103 deletions

1
.gitattributes vendored
View File

@ -7864,6 +7864,7 @@ utils/fppkg/fprepos.pp svneol=native#text/plain
utils/fppkg/fpxmlrep.pp svneol=native#text/plain
utils/fppkg/pkgdownload.pp svneol=native#text/plain
utils/fppkg/pkghandler.pp svneol=native#text/plain
utils/fppkg/pkglibcurl.pp svneol=native#text/plain
utils/fppkg/pkglnet.pas svneol=native#text/plain
utils/fppkg/pkgmessages.pp svneol=native#text/plain
utils/fppkg/pkgmkconv.pp svneol=native#text/plain

View File

@ -10,8 +10,9 @@
<MainUnitHasTitleStatement Value="False"/>
</Flags>
<MainUnit Value="0"/>
<IconPath Value="./"/>
<TargetFileExt Value=""/>
<ActiveEditorIndexAtStart Value="3"/>
<ActiveEditorIndexAtStart Value="0"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
@ -35,22 +36,26 @@
<Filename Value="fppkg.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="fppkg"/>
<CursorPos X="1" Y="13"/>
<TopLine Value="1"/>
<CursorPos X="1" Y="244"/>
<TopLine Value="215"/>
<EditorIndex Value="0"/>
<UsageCount Value="20"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
<Filename Value="pkgropts.pp"/>
<IsPartOfProject Value="True"/>
<UsageCount Value="20"/>
<SyntaxHighlighter Value="Text"/>
<UnitName Value="pkgropts"/>
<CursorPos X="3" Y="25"/>
<TopLine Value="1"/>
<EditorIndex Value="1"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit1>
<Unit2>
<Filename Value="fpmkcnst.inc"/>
<IsPartOfProject Value="True"/>
<UsageCount Value="20"/>
<UsageCount Value="21"/>
<SyntaxHighlighter Value="Text"/>
</Unit2>
<Unit3>
@ -59,36 +64,36 @@
<UnitName Value="fpmktype"/>
<CursorPos X="3" Y="41"/>
<TopLine Value="1"/>
<EditorIndex Value="2"/>
<UsageCount Value="20"/>
<EditorIndex Value="3"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
<Filename Value="fpmkunit.pp"/>
<IsPartOfProject Value="True"/>
<UsageCount Value="20"/>
<UsageCount Value="21"/>
<SyntaxHighlighter Value="Text"/>
</Unit4>
<Unit5>
<Filename Value="fprepos.pp"/>
<IsPartOfProject Value="True"/>
<UsageCount Value="20"/>
<UsageCount Value="21"/>
<SyntaxHighlighter Value="Text"/>
</Unit5>
<Unit6>
<Filename Value="fpxmlrep.pp"/>
<IsPartOfProject Value="True"/>
<UsageCount Value="20"/>
<UsageCount Value="21"/>
<SyntaxHighlighter Value="Text"/>
</Unit6>
<Unit7>
<Filename Value="pkghandler.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="pkghandler"/>
<CursorPos X="18" Y="41"/>
<TopLine Value="16"/>
<EditorIndex Value="5"/>
<UsageCount Value="20"/>
<CursorPos X="19" Y="60"/>
<TopLine Value="17"/>
<EditorIndex Value="6"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit7>
<Unit8>
@ -97,151 +102,151 @@
<UnitName Value="pkgmkconv"/>
<CursorPos X="20" Y="7"/>
<TopLine Value="1"/>
<EditorIndex Value="4"/>
<UsageCount Value="20"/>
<EditorIndex Value="5"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit8>
<Unit9>
<Filename Value="pkgdownload.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="pkgdownload"/>
<CursorPos X="34" Y="64"/>
<TopLine Value="59"/>
<EditorIndex Value="3"/>
<UsageCount Value="20"/>
<CursorPos X="13" Y="96"/>
<TopLine Value="56"/>
<EditorIndex Value="4"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit9>
<Unit10>
<Filename Value="pkgmessages.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="pkgmessages"/>
<CursorPos X="1" Y="18"/>
<CursorPos X="26" Y="9"/>
<TopLine Value="1"/>
<EditorIndex Value="1"/>
<UsageCount Value="20"/>
<EditorIndex Value="2"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit10>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="pkgmkconv.pp"/>
<Caret Line="614" Column="12" TopLine="591"/>
<Filename Value="fppkg.pp"/>
<Caret Line="245" Column="5" TopLine="222"/>
</Position1>
<Position2>
<Filename Value="fppkg.pp"/>
<Caret Line="7" Column="37" TopLine="1"/>
<Caret Line="278" Column="1" TopLine="245"/>
</Position2>
<Position3>
<Filename Value="fppkg.pp"/>
<Caret Line="75" Column="34" TopLine="52"/>
<Caret Line="245" Column="5" TopLine="222"/>
</Position3>
<Position4>
<Filename Value="fppkg.pp"/>
<Caret Line="61" Column="19" TopLine="52"/>
<Caret Line="249" Column="12" TopLine="222"/>
</Position4>
<Position5>
<Filename Value="fppkg.pp"/>
<Caret Line="44" Column="31" TopLine="1"/>
<Filename Value="pkghandler.pp"/>
<Caret Line="58" Column="65" TopLine="35"/>
</Position5>
<Position6>
<Filename Value="fppkg.pp"/>
<Caret Line="239" Column="23" TopLine="216"/>
<Filename Value="pkghandler.pp"/>
<Caret Line="47" Column="51" TopLine="24"/>
</Position6>
<Position7>
<Filename Value="fppkg.pp"/>
<Caret Line="282" Column="29" TopLine="243"/>
<Filename Value="pkghandler.pp"/>
<Caret Line="54" Column="1" TopLine="31"/>
</Position7>
<Position8>
<Filename Value="pkgdownload.pp"/>
<Caret Line="14" Column="3" TopLine="1"/>
<Filename Value="pkghandler.pp"/>
<Caret Line="47" Column="1" TopLine="47"/>
</Position8>
<Position9>
<Filename Value="pkghandler.pp"/>
<Caret Line="50" Column="1" TopLine="1"/>
<Caret Line="54" Column="3" TopLine="31"/>
</Position9>
<Position10>
<Filename Value="pkghandler.pp"/>
<Caret Line="42" Column="62" TopLine="18"/>
<Caret Line="59" Column="3" TopLine="36"/>
</Position10>
<Position11>
<Filename Value="pkghandler.pp"/>
<Caret Line="47" Column="24" TopLine="24"/>
<Caret Line="53" Column="6" TopLine="30"/>
</Position11>
<Position12>
<Filename Value="pkghandler.pp"/>
<Caret Line="45" Column="73" TopLine="24"/>
<Caret Line="40" Column="47" TopLine="30"/>
</Position12>
<Position13>
<Filename Value="pkgmkconv.pp"/>
<Caret Line="49" Column="14" TopLine="16"/>
<Filename Value="pkghandler.pp"/>
<Caret Line="53" Column="6" TopLine="30"/>
</Position13>
<Position14>
<Filename Value="pkgmkconv.pp"/>
<Caret Line="1" Column="1" TopLine="1"/>
<Filename Value="pkghandler.pp"/>
<Caret Line="55" Column="10" TopLine="30"/>
</Position14>
<Position15>
<Filename Value="pkgdownload.pp"/>
<Caret Line="30" Column="9" TopLine="4"/>
<Filename Value="pkghandler.pp"/>
<Caret Line="50" Column="14" TopLine="9"/>
</Position15>
<Position16>
<Filename Value="pkgdownload.pp"/>
<Caret Line="36" Column="26" TopLine="13"/>
<Filename Value="pkghandler.pp"/>
<Caret Line="53" Column="6" TopLine="30"/>
</Position16>
<Position17>
<Filename Value="pkgdownload.pp"/>
<Caret Line="26" Column="19" TopLine="3"/>
<Filename Value="pkghandler.pp"/>
<Caret Line="40" Column="10" TopLine="17"/>
</Position17>
<Position18>
<Filename Value="pkghandler.pp"/>
<Caret Line="19" Column="26" TopLine="12"/>
<Filename Value="fppkg.pp"/>
<Caret Line="46" Column="1" TopLine="23"/>
</Position18>
<Position19>
<Filename Value="pkghandler.pp"/>
<Caret Line="56" Column="5" TopLine="12"/>
<Filename Value="fppkg.pp"/>
<Caret Line="289" Column="1" TopLine="266"/>
</Position19>
<Position20>
<Filename Value="pkghandler.pp"/>
<Caret Line="62" Column="11" TopLine="39"/>
<Filename Value="fppkg.pp"/>
<Caret Line="254" Column="1" TopLine="241"/>
</Position20>
<Position21>
<Filename Value="pkgdownload.pp"/>
<Caret Line="22" Column="1" TopLine="1"/>
<Filename Value="fppkg.pp"/>
<Caret Line="46" Column="42" TopLine="23"/>
</Position21>
<Position22>
<Filename Value="pkgdownload.pp"/>
<Caret Line="53" Column="1" TopLine="19"/>
<Filename Value="fppkg.pp"/>
<Caret Line="33" Column="28" TopLine="23"/>
</Position22>
<Position23>
<Filename Value="pkgdownload.pp"/>
<Caret Line="49" Column="5" TopLine="1"/>
<Filename Value="fppkg.pp"/>
<Caret Line="47" Column="42" TopLine="23"/>
</Position23>
<Position24>
<Filename Value="pkgdownload.pp"/>
<Caret Line="10" Column="1" TopLine="1"/>
<Filename Value="fppkg.pp"/>
<Caret Line="253" Column="42" TopLine="230"/>
</Position24>
<Position25>
<Filename Value="pkgdownload.pp"/>
<Caret Line="55" Column="28" TopLine="32"/>
<Filename Value="fppkg.pp"/>
<Caret Line="254" Column="37" TopLine="231"/>
</Position25>
<Position26>
<Filename Value="pkgdownload.pp"/>
<Caret Line="59" Column="1" TopLine="32"/>
<Filename Value="fppkg.pp"/>
<Caret Line="259" Column="9" TopLine="236"/>
</Position26>
<Position27>
<Filename Value="pkgdownload.pp"/>
<Caret Line="73" Column="46" TopLine="50"/>
<Filename Value="fppkg.pp"/>
<Caret Line="234" Column="16" TopLine="203"/>
</Position27>
<Position28>
<Filename Value="pkgdownload.pp"/>
<Caret Line="75" Column="19" TopLine="52"/>
<Filename Value="fppkg.pp"/>
<Caret Line="278" Column="63" TopLine="255"/>
</Position28>
<Position29>
<Filename Value="pkgdownload.pp"/>
<Caret Line="93" Column="7" TopLine="59"/>
<Filename Value="fppkg.pp"/>
<Caret Line="283" Column="1" TopLine="255"/>
</Position29>
<Position30>
<Filename Value="pkgdownload.pp"/>
<Caret Line="94" Column="11" TopLine="59"/>
<Filename Value="fppkg.pp"/>
<Caret Line="282" Column="9" TopLine="259"/>
</Position30>
</JumpHistory>
</ProjectOptions>

View File

@ -4,20 +4,24 @@ program fppkg;
uses
// General
{$ifdef unix}
baseunix,
{$endif}
Classes, SysUtils, TypInfo, custapp,
// Repository handler objects
fprepos, fpxmlrep,fpmktype,
fprepos, fpxmlrep,fpmktype, pkgropts,
// Package Handler components
pkghandler, pkgmkconv, pkgdownload, pkgmessages;
Type
TRunMode = (rmHelp,rmCompile,rmBuild,rmInstall,rmArchive,rmClean,rmDownload);
TRunMode = (rmHelp,rmCompile,rmBuild,rmInstall,rmArchive,rmClean,rmDownload,rmUpdate);
{ TMakeTool }
TMakeTool = Class(TCustomApplication)
Private
FDefaults: TPackagerOptions;
FConvertOnly,
FLogging : Boolean;
FCompiler : String;
@ -26,16 +30,22 @@ Type
FHaveFpmake : Boolean;
FFPMakeSrc : String;
FFPMakeBin : String;
FVerbose: TVerbosities;
FPackages : TStrings;
Procedure Log(Msg : String);
Procedure Error(Msg : String);
Procedure Error(Fmt : String; Args : Array of const);
Function GetCompiler : String;
Public
Procedure DownloadFile(Const URL,Dest : String);
Function GetConfigFileName : String;
Procedure LoadDefaults;
Procedure ProcessCommandLine;
procedure CreateFPMake;
procedure CompileFPMake(Extra : Boolean);
Function RunFPMake : Integer;
Procedure DoRun; Override;
Property Verbose : TVerbosities Read FVerbose Write FVerbose;
end;
EMakeToolError = Class(Exception);
@ -147,6 +157,36 @@ begin
end;
end;
procedure TMakeTool.DownloadFile(const URL, Dest: String);
begin
end;
function TMakeTool.GetConfigFileName: String;
var
G : Boolean;
begin
if HasOption('C','config-file') then
Result:=GetOptionValue('C','config-file')
else
begin
{$ifdef unix}
g:=(fpgetuid=0);
{$else}
G:=true;
{$endif}
Result:=GetAppConfigFile(G,False);
end
end;
procedure TMakeTool.LoadDefaults;
begin
FDefaults:=TPackagerOptions.Create;
FDefaults.LoadFromFile(GetConfigFileName);
end;
procedure TMakeTool.ProcessCommandLine;
@ -191,44 +231,66 @@ procedure TMakeTool.ProcessCommandLine;
Var
I : Integer;
GlobalOpts : Boolean;
cmd : string;
begin
I:=0;
FLogging:=False;
FRunMode:=rmhelp;
FConvertOnly:=False;
GlobalOpts:=True;
FPackages:=TStringList.Create;
// We can't use the TCustomApplication option handling,
// because they cannot handle [general opts] [command] [cmd-opts] [args]
While (I<ParamCount) do
begin
Inc(I);
if Checkoption(I,'n','convert') then
FConvertOnly:=True
else if Checkoption(I,'m','compile') then
FRunMode:=rmCompile
else if Checkoption(I,'b','build') then
FRunMode:=rmBuild
else if CheckOption(I,'i','install') then
FRunMode:=rmInstall
else if CheckOption(I,'c','clean') then
FRunMode:=rmClean
else if CheckOption(I,'a','archive') then
FRunMode:=rmarchive
else if CheckOption(I,'d','download') then
FRunMode:=rmDownload
// Check options.
if CheckOption(I,'r','compiler') then
FDefaults.Compiler:=OptionArg(I)
else if CheckOption(I,'v','verbose') then
Include(FVerbose,StringToVerbosity(OptionArg(I)))
else if CheckOption(I,'h','help') then
FRunMode:=rmhelp
// Check.
else if CheckOption(I,'r','compiler') then
FCompiler:=OptionArg(I)
else if CheckOption(I,'v','verbose') then
Flogging:=Pos('info',Lowercase(OptionArg(I)))<>0;
else if (Length(Paramstr(i))>0) and (Paramstr(I)[1]='-') then
Raise EMakeToolError.CreateFmt(SErrInvalidArgument,[I,ParamStr(i)])
else
If GlobalOpts then
begin
// It's a command.
Cmd:=Paramstr(I);
if (Cmd='convert') then
FConvertOnly:=True
else if (Cmd='compile') then
FRunMode:=rmCompile
else if (Cmd='build') then
FRunMode:=rmBuild
else if (Cmd='install') then
FRunMode:=rmInstall
else if (cmd='clean') then
FRunMode:=rmClean
else if (cmd='archive') then
FRunMode:=rmarchive
else if (cmd='download') then
FRunMode:=rmDownload
else if (cmd='update') then
FRunMode:=rmUpdate
else
Raise EMakeToolError.CreateFmt(SErrInvalidCommand,[Cmd]);
end
else // It's a package name.
begin
FPackages.Add(Paramstr(i));
end;
end;
end;
procedure TMakeTool.DoRun;
begin
LoadDefaults;
Try
ProcessCommandLine;
If FConvertOnly then

View File

@ -35,10 +35,33 @@ Type
end;
EPackageHandler = Class(EInstallerError);
Function StringToVerbosity (S : String) : TVerbosity;
Function VerbosityToString (V : TVerbosity): String;
Implementation
uses pkgmessages;
uses pkgmessages,typinfo;
function StringToVerbosity(S: String): TVerbosity;
Var
I : integer;
begin
I:=GetEnumValue(TypeInfo(TVerbosity),'v'+S);
If (I<>-1) then
Result:=TVerbosity(I)
else
Raise EPackageHandler.CreateFmt(SErrInvalidVerbosity,[S]);
end;
Function VerbosityToString (V : TVerbosity): String;
begin
Result:=GetEnumName(TypeInfo(TVerbosity),Integer(V));
Delete(Result,1,1);// Delete 'v'
end;
{ TPackageHandler }

65
utils/fppkg/pkglibcurl.pp Normal file
View File

@ -0,0 +1,65 @@
{$mode objfpc}
{$h+}
unit pkglibcurl;
interface
uses Classes,pkgdownload;
Type
TLibCurlDownloader = Class(TBasePackageDownloader)
Protected
Procedure LibCurlDownload(Const URL : String; Dest : TStream);
Procedure FTPDownload(Const URL : String; Dest : TStream); override;
Procedure HTTPDownload(Const URL : String; Dest : TStream); override;
end;
implementation
uses sysutils,uriparser,libcurl,pkgmessages,unixtype;
Function DoStreamWrite(Ptr : Pointer; Size : size_t; nmemb: size_t; Data : Pointer) : size_t;cdecl;
begin
Result:=TStream(Data).Write(Ptr^,Size*nmemb);
end;
Procedure TLibCurlDownloader.LibCurlDownload(Const URL : String; Dest : TStream);
Var
HCurl : PCurl;
ErrorBuffer : Array[0..CURL_ERROR_SIZE] of char;
begin
hCurl:= curl_easy_init;
if Assigned(hCurl) then
Try
curl_easy_setopt(hCurl,CURLOPT_ERRORBUFFER, [@ErrorBuffer]);
curl_easy_setopt(hCurl,CURLOPT_URL,[Pchar(URL)]);
curl_easy_setopt(hCurl,CURLOPT_WRITEFUNCTION,[@DoStreamWrite]);
curl_easy_setopt(hCurl,CURLOPT_WRITEDATA,[Pointer(Dest)]);
if Ord(curl_easy_perform(hCurl))<>0 then
Error(SErrDownloadFailed,[StrPas(@ErrorBuffer)])
Finally
curl_easy_cleanup(hCurl);
end
else
Raise Exception.Create('Failed to initialize Curl');
end;
Procedure TLibCurlDownloader.FTPDownload(Const URL : String; Dest : TStream);
begin
LibCurlDownload(URL,Dest);
end;
Procedure TLibCurlDownloader.HTTPDownload(Const URL : String; Dest : TStream);
begin
LibCurlDownload(URL,Dest);
end;
initialization
DownloaderClass:=TLibCurlDownloader;
end.

View File

@ -6,7 +6,7 @@ interface
Resourcestring
// SErrInValidArgument = 'Invalid command-line argument at position %d : %s';
SErrInValidArgument = 'Invalid command-line argument at position %d : %s';
SErrNeedArgument = 'Option at position %d (%s) needs an argument';
SErrMissingConfig = 'Missing configuration Makefile.fpc or fpmake.pp';
SErrRunning = 'The FPC make tool encountered the following error: %s';
@ -18,6 +18,8 @@ Resourcestring
SErrNoSuchFile = 'File "%s" does not exist.';
SErrWGetDownloadFailed = 'Download failed: wget reported exit status %d.';
SErrDownloadFailed = 'Download failed: %s';
SErrInvalidVerbosity = 'Invalid verbosity string: "%s"';
SErrInvalidCommand = 'Invalid command: %s';
SErrHTTPGetFailed = 'HTTP Download failed.';
SErrLoginFailed = 'FTP LOGIN command failed.';