ATBTariffWebInterface/deploy/webiface.lpr

110 lines
3.4 KiB
ObjectPascal
Raw Permalink Normal View History

2024-03-26 17:02:59 +01:00
{%RunFlags MESSAGES+}
{$mode ObjFPC}{$H+}
program webiface(output);
uses
CTypes, LazUtils, LazFileUtils, LazUtf8, SysUtils,
fpjson, jsonparser, ATBWebInterface, ATBUtils, ATBGit;
//type
// PTJSONObject = ^TJSONObject;
var
//jData: TJSONData;
jObject, jObjTemp: TJSONObject;
jEnum: TJSONEnum;
jArray: TJSONArray;
repoRootDir: UTF8String;
fileId: UTF8String;
localRepository: UTF8String;
localRepositoryDir: UTF8String;
fileName: UTF8String;
{$R *.res}
begin
try
jArray := TJSONArray.Create;
jObject := TJSONObject.Create;
//CustomerRepo := 'https://git.mimbach49.de/GerhardHoffmann/customer_999.git';
//LocalCustomerRepo := 'H:\\customer_999';
//LocalBranchName := 'zg1/zone1';
//FileToCommit := 'etc/psa_tariff/tariff01.json';
//CommitMessage := 'TEST TEST';
//UserName := 'GerhardHoffmann';
//PassWord := 'ghlinux12345';
//LocalRepo := 'customer_999';
repoRootDir := 'H:\';
ATBGit.SetReposRootDirectory(repoRootDir);
localRepository := 'customer_999';
fileId := 'customer_999/etc/psa_tariff:zg1/zone1';
//jData := GetJSON('{"F1" : "Hello"}');
// ATBWebInterface.SetFile(localRepository, fileId, jData);
// halt;
if ATBWebInterface.GetFileMenu(localRepository, @jObject) then begin
jArray := jObject['File-Menue'] as TJSONArray;
for jEnum in jArray do begin
jObjTemp := jEnum.Value as TJSONObject;
fileId := jObjTemp.Strings['File-ID'];
fileName := GetFileName(localRepository, fileId);
if fileName <> '' then begin
if FileExistsUTF8(fileName) then begin
writeln();
writeln('file exists: ' + fileName);
if ATBWebInterface.GetFile(localRepository, fileId, @jObject) then begin
writeln(jObject.FormatJSON);
end;
end;
end;
end;
end;
localRepositoryDir := ATBGit.GetLocalRepositoryPath(localRepository);
writeln();
writeln('localRepositoryDir: ' + localRepositoryDir);
if not DirectoryExistsUTF8(localRepositoryDir) then begin
writeln('create localRepositoryDir: ' + localRepositoryDir);
CreateDirUTF8(localRepositoryDir);
end;
halt;
//if InitGitLibrary() > 0 then
// Try
// writeLn('initialized git library') ;
// if not DirectoryExistsUTF8(ExpandFilenameUtf8(LocalCustomerRepo+'\\.git')) then
// CloneRepository(CustomerRepo, LocalCustomerRepo);
// if not CheckoutLocalBranch(LocalCustomerRepo, LocalBranchName) = 0 then
// writeLn('cannot check out') ;
// if not CommitFile(LocalCustomerRepo, LocalBranchName, FileToCommit, CommitMessage) = 0 then
// writeLn('cannot commit') ;
// if not PushLocalRepository(LocalCustomerRepo, LocalBranchName, UserName, PassWord) = 0 then
// writeLn('cannot push') ;
// Finally
// if ShutdownGitLibrary() >= 0 then
// writeLn('shutdown git library') ;
// end
//else
// begin
// writeLn('initializing git library FAILED') ;
// Readln;
// end;
finally
jArray.Free;
end;
end.