SRL Archive - Simba (Testing) Scripts

Simba based SRL installer!


mixster

2010-02-13 21:52:24

I have only tested on Linux and it worked. I ran into the problem of Simba being unable to create directories (which I think is Linux local), so I have attached an Include skeleton containing just the folders (not including Plugins folder - you can make that yourself if missing, though it should be there for Smart).

I have not tested it on Windows, but it should work. If there is a problem with being unable to write files, may be that Simba can't create folders under Windows too, in which case the attached Includes skeleton should be fix it.

Please note the "Linux" const - set it as you need, otherwise it may cause errors. It's primarily just for whether or not it should use '/' or '\', but also has a bit for if you move your plugins so it only moves .so's or .dll's.

For now, ignore the version checking as I am unsure of the state of INI's or indeed whether or not they will be used for long. Maybe I should get version stuff to use Simba settings, but for now I'm lazy and to be honest you probably won't use this - Ray just asked about it earlier since, at the moment, Simba has no SVN stuff.

const
CheckVersion = False;
MoveSRLPlugins = True;
SRLDirectory = 'Includes\SRL\';
Linux = True;

var
SCARDirectory: string;

type
TFile = record
path, filename: string;
end;

TSVNFile = record
local, remote: TFile;
end;

TMatch = record
start, finish: string;
end;

TFilter = record
exp, dir, fil: string;
local, remote: TMatch;
end;

TSVN = record
name: string;
skip: TStringArray;
baseloc: TSVNFile;
files: array of TSVNFile;
filter: TFilter;
rev: TMatch;
col: Boolean;
end;

function Explode(str, del: string): TStringArray;
var
i, l, dL: Integer;
begin
i := 0;
l := -1;
SetLength(Result, 0);
if (str = '') then
Exit;
dL := Length(del) - 1;
repeat
Inc(l);
SetLength(Result, l + 1);
i := Pos(del, str);
if i <= 0 then
Break;
Result[l] := Copy(str, 1, i - 1);
Delete(str, 1, i + dL);
until false
Result[l] := Copy(str, 1, Length(str));
end;

function ReturnPage(svn: TSVN; dir: TSVNFile): string;
var
url: string;
begin
url := svn.baseloc.remote.path + dir.remote.path;

try
Result := GetPage(url);
except
Writeln('Downloading url "' + url + '" failed');
Result := '';
end;
end;

procedure RawCollectSVN(var svn: TSVN; cur_dir: TSVNFile);
var
input, tmpLoc, tmpRem: string;
split: TStringArray;
h, i: Integer;
new_dir: TSVNFile;
sk: Boolean;
begin
input := ReturnPage(svn, cur_dir);
split := Explode(input, svn.filter.exp);

for i := 0 to High(split) do
begin
for h := 0 to High(svn.skip) do
begin
sk := Pos(svn.skip[h], split[i]) > 0;
if sk then
Break;
end;

if sk then
Continue;

tmpLoc := Between(svn.filter.local.start, svn.filter.local.finish, split[i]);
tmpRem := Between(svn.filter.remote.start, svn.filter.remote.finish, split[i]);

if (tmpLoc = '') or (tmpRem = '') then
Continue;

if Pos(svn.filter.dir, split[i]) > 0 then // Handle directory
begin
new_dir.local.path := cur_dir.local.path + tmpLoc;
if (Linux) then
new_dir.local.path := new_dir.local.path + '/'
else
new_dir.local.path := new_dir.local.path + '\';
new_dir.remote.path := cur_dir.remote.path + tmpRem;
Writeln('Discovered directory "' + cur_dir.local.path + tmpLoc + '"');
RawCollectSVN(svn, new_dir);
end
else if Pos(svn.filter.fil, split[i]) > 0 then // Handle file
begin;
h := Length(svn.files);
SetLength(svn.files, h + 1);
svn.files[h].local.path := cur_dir.local.path;
svn.files[h].local.filename := tmpLoc;
svn.files[h].remote.path := cur_dir.remote.path;
svn.files[h].remote.filename := tmpRem;
end;
end;
end;

procedure CollectSVN(var svn: TSVN);
var
start: TSVNFile;
t: Integer;
begin
Writeln('Now starting to collect "' + svn.name + '"');
t := GetSystemTime;
RawCollectSVN(svn, start);
svn.col := True;
t := GetSystemTime - t;
Writeln('Finished collecting "' + svn.name + '" in ' + IntToStr(t) + ' ms');
Writeln('A total of ' + IntToStr(Length(svn.files)) + ' files were collected');
end;

procedure DownloadSVN(svn: TSVN);
var
i, f, l, t: Integer;
s: string;
opt: TReplaceFlags;
begin
Writeln('Now starting to download "' + svn.name + '"');
Writeln('');

opt := [rfReplaceAll];

t := GetSystemTime;
l := Length(svn.files);
for i := 0 to l - 1 do
try
s := svn.baseloc.local.path + svn.files[i].local.path + svn.files[i].local.filename;

f := RewriteFile(s, False);
if (f = -1) then
begin
Writeln('Error writing ''' + s + '''' + ' (' + IntToStr(i) + ' of ' + IntToStr(l - 1) + ')');
Continue;
end
else
Writeln(s + ' (' + IntToStr(i) + ' of ' + IntToStr(l - 1) + ')');

WriteFileString(f, GetPage(svn.baseloc.remote.path + svn.files[i].remote.path + svn.files[i].remote.filename));
CloseFile(f);
except
Writeln('Failed to download file.');
end;
t := GetSystemTime - t;
Writeln('Finished downloading "' + svn.name + '" in ' + IntToStr(t) + ' ms');
end;

function ReturnSRLSVN: TSVN;
var
opt: TReplaceFlags;
begin
Result.name := 'SRL';
Result.baseloc.remote.path := 'http://www.villavu.com/repositories/srl-opendev/';
opt := [rfReplaceAll];
if (Linux) then
Result.baseloc.local.path := Replace(AppPath + SRLDirectory, '\', '/', opt)
else
Result.baseloc.local.path := Replace(AppPath + SRLDirectory, '/', '\', opt);
Result.filter.exp := '<';
Result.filter.dir := 'dir';
Result.filter.fil := 'file';
Result.filter.local.start := 'name="';
Result.filter.local.finish := '"';
Result.filter.remote.start := 'href="';
Result.filter.remote.finish := '"';
Result.rev.start := 'rev="';
Result.rev.finish := '"';
Result.skip := [];
end;

function GetSVNVersion(svn: TSVN): Integer;
var
input: string;
begin
input := GetPage(svn.baseloc.remote.path);
Result := StrToIntDef(Between(svn.rev.start, svn.rev.finish, input), 0);
end;

procedure WriteSVNVersion(svn: TSVN);
var
rev: Integer;
begin
rev := GetSVNVersion(svn);
if rev = 0 then
begin
Writeln('Collecting rev number failed');
Writeln('You can manually set svn_settings.ini if this results in a problem');
exit;
end;

WriteINI(svn.name, 'REVISION', IntToStr(rev), SCARDirectory + 'svn_settings.ini');
end;

function IsSVNOld(svn: TSVN): Boolean;
var
curRev, locRev: Integer;
begin
locRev := StrToIntDef(ReadINI(svn.name, 'REVISION', AppPath + 'svn_settings.ini'), 0);
curRev := GetSVNVersion(svn);
if curRev = 0 then
begin
Writeln('Collecting current rev number failed');
Writeln('Assuming newer SVN is on local system to avoid problems');
Result := False;
Exit;
end;

Result := locRev < curRev;

if Result then
Writeln(svn.name + ' has the latest rev downloaded')
else
Writeln(svn.name + ' is rev ' + IntToStr(locRev) + ' and latest is ' + IntToStr(curRev));
end;

procedure MovePlugins(svn: TSVN; dest: string);
var
i, f: Integer;
s: string;
o: Boolean;
begin
if (Linux) then
dest := dest + '/'
else
dest := dest + '\';
for i := 0 to High(svn.files) do
if ((Linux) and (Pos('.so', svn.files[i].local.filename) > 0)) or ((not Linux) and (Pos('.dll', svn.files[i].local.filename) > 0)) then
try
Writeln('Found plugin "' + svn.files[i].local.filename);
if (Pos('Simba', svn.files[i].local.path) <= 0) then
begin
Writeln('Not a Simba plugin - ignoring');
Continue;
end;
o := False;
f := OpenFile(svn.baseloc.local.path + svn.files[i].local.path + svn.files[i].local.filename, False);
if (f = -1) then
begin
Writeln('Error opening file ''' + svn.baseloc.local.path + svn.files[i].local.path + svn.files[i].local.filename + '''');
Continue;
end;
ReadFileString(f, s, FileSize(f));
CloseFile(f);
o := True;
f := RewriteFile(dest + svn.files[i].local.filename, False);
if (f = -1) then
begin
Writeln('Error opening file ''' + dest + svn.files[i].local.filename + '''');
Continue;
end;
WriteFileString(f, s);
CloseFile(f);
except
Writeln('Failed to save plugin.');
if o then
Writeln('Problem involved rewriting the file at target folder')
else
Writeln('Problem involved opening the sauce file to read');
end;
end;

var
srl: TSVN;

begin
Writeln('Begin');

srl := ReturnSRLSVN;

if (not CheckVersion) or (CheckVersion and IsSVNOld(srl)) then
begin
CollectSVN(srl);
DownloadSVN(srl);

if MoveSRLPlugins then
MovePlugins(srl, AppPath + 'Plugins');
end;

Writeln('End');
end.

Gu3st...

2010-02-14 07:00:29

Everything worked well except creating the \Simba\ folder inside \place inside plugins folder\
"ReWriteFile: - Exception. Could not create file. Returning -1"
I tried running as Administrator, and it didn't work any better. In fact it didn't download anything at all, just returned me errors..

So I deleted my SIMBA folder and reinstalled everything. Opened in admin mode.. tested again and… same result..

I am running Vista.

mixster

2010-02-14 08:07:00

Did it automatically create all the other folders itself? If so, I don't see why there should be a problem with that specific one. If you created the folder yourself/used my include skeleton, then I am even less sure. Where abouts is Simba installed at? If it's possible permission problems may be arising, then it wouldn't download anything else… Meh, I don't like Vista :(

Gu3st...

2010-02-14 08:10:02

From: mixster
Did it automatically create all the other folders itself? If so, I don't see why there should be a problem with that specific one. If you created the folder yourself/used my include skeleton, then I am even less sure. Where abouts is Simba installed at? If it's possible permission problems may be arising, then it wouldn't download anything else… Meh, I don't like Vista :(
It's installed on a removable flash drive. The name of the flash drive has special characters in it (ΓΈ) so that might be it :p
I didn't create any folders myself

mixster

2010-02-14 08:15:35

lol, but if it managed to create some, then I don't see why it shouldn't be able to produce the Simba folder, or was it that it made the Simba folder, but just didn't put any plugins into it? Well I guess that's hard to test since it would only make the folder if it put something in it. Maybe make the folder yourself and see?

mastaraymond

2010-02-14 10:12:42


const
CheckVersion = False;
MoveSRLPlugins = True;
SRLDirectory = IncludePath + 'SRL/';
{$ifdef Linux}
Linux = True;
{$else}
Linux = false;
{$endif}

var
SCARDirectory: string;

type
TFile = record
path, filename: string;
end;

TSVNFile = record
local, remote: TFile;
end;

TMatch = record
start, finish: string;
end;

TFilter = record
exp, dir, fil: string;
local, remote: TMatch;
end;

TSVN = record
name: string;
skip: TStringArray;
baseloc: TSVNFile;
files: array of TSVNFile;
filter: TFilter;
rev: TMatch;
col: Boolean;
end;

function Explode(str, del: string): TStringArray;
var
i, l, dL: Integer;
begin
i := 0;
l := -1;
SetLength(Result, 0);
if (str = '') then
Exit;
dL := Length(del) - 1;
repeat
Inc(l);
SetLength(Result, l + 1);
i := Pos(del, str);
if i <= 0 then
Break;
Result[l] := Copy(str, 1, i - 1);
Delete(str, 1, i + dL);
until false
Result[l] := Copy(str, 1, Length(str));
end;

function ReturnPage(svn: TSVN; dir: TSVNFile): string;
var
url: string;
begin
url := svn.baseloc.remote.path + dir.remote.path;

try
Result := GetPage(url);
except
Writeln('Downloading url "' + url + '" failed');
Result := '';
end;
end;

procedure RawCollectSVN(var svn: TSVN; cur_dir: TSVNFile);
var
input, tmpLoc, tmpRem: string;
split: TStringArray;
h, i: Integer;
new_dir: TSVNFile;
sk: Boolean;
begin
input := ReturnPage(svn, cur_dir);
split := Explode(input, svn.filter.exp);

for i := 0 to High(split) do
begin
for h := 0 to High(svn.skip) do
begin
sk := Pos(svn.skip[h], split[i]) > 0;
if sk then
Break;
end;

if sk then
Continue;

tmpLoc := Between(svn.filter.local.start, svn.filter.local.finish, split[i]);
tmpRem := Between(svn.filter.remote.start, svn.filter.remote.finish, split[i]);

if (tmpLoc = '') or (tmpRem = '') then
Continue;

if Pos(svn.filter.dir, split[i]) > 0 then // Handle directory
begin
new_dir.local.path := cur_dir.local.path + tmpLoc;
if (Linux) then
new_dir.local.path := new_dir.local.path + '/'
else
new_dir.local.path := new_dir.local.path + '\';
new_dir.remote.path := cur_dir.remote.path + tmpRem;
Writeln('Discovered directory "' + cur_dir.local.path + tmpLoc + '"');
if not DirectoryExists(svn.baseloc.local.path + new_dir.local.path) then
if not CreateDirectory(svn.baseloc.local.path + new_dir.local.path) then
Writeln(format('Could not create the folder: %s',[svn.baseloc.local.path + new_dir.local.path]));
RawCollectSVN(svn, new_dir);
end
else if Pos(svn.filter.fil, split[i]) > 0 then // Handle file
begin;
h := Length(svn.files);
SetLength(svn.files, h + 1);
svn.files[h].local.path := cur_dir.local.path;
svn.files[h].local.filename := tmpLoc;
svn.files[h].remote.path := cur_dir.remote.path;
svn.files[h].remote.filename := tmpRem;
end;
end;
end;

procedure CollectSVN(var svn: TSVN);
var
start: TSVNFile;
t: Integer;
begin
Writeln('Now starting to collect "' + svn.name + '"');
t := GetSystemTime;
RawCollectSVN(svn, start);
svn.col := True;
t := GetSystemTime - t;
Writeln('Finished collecting "' + svn.name + '" in ' + IntToStr(t) + ' ms');
Writeln('A total of ' + IntToStr(Length(svn.files)) + ' files were collected');
end;

procedure DownloadSVN(svn: TSVN);
var
i, f, l, t: Integer;
s: string;
opt: TReplaceFlags;
begin
Writeln('Now starting to download "' + svn.name + '"');
Writeln('');

opt := [rfReplaceAll];

t := GetSystemTime;
l := Length(svn.files);
for i := 0 to l - 1 do
try
s := svn.baseloc.local.path + svn.files[i].local.path + svn.files[i].local.filename;

f := RewriteFile(s, False);
if (f = -1) then
begin
Writeln('Error writing ''' + s + '''' + ' (' + IntToStr(i) + ' of ' + IntToStr(l - 1) + ')');
Continue;
end
else
Writeln(s + ' (' + IntToStr(i) + ' of ' + IntToStr(l - 1) + ')');

WriteFileString(f, GetPage(svn.baseloc.remote.path + svn.files[i].remote.path + svn.files[i].remote.filename));
CloseFile(f);
except
Writeln('Failed to download file.');
end;
t := GetSystemTime - t;
Writeln('Finished downloading "' + svn.name + '" in ' + IntToStr(t) + ' ms');
end;

function ReturnSRLSVN: TSVN;
var
opt: TReplaceFlags;
srlpath : string;
begin
Result.name := 'SRL';
Result.baseloc.remote.path := 'http://www.villavu.com/repositories/srl-opendev/';
opt := [rfReplaceAll];
if (Linux) then
Result.baseloc.local.path := Replace(SRLDirectory, '\', '/', opt)
else
Result.baseloc.local.path := Replace(SRLDirectory, '/', '\', opt);
if not DirectoryExists(Result.baseloc.local.path) then
CreateDirectory(Result.baseloc.local.path);
Result.filter.exp := '<';
Result.filter.dir := 'dir';
Result.filter.fil := 'file';
Result.filter.local.start := 'name="';
Result.filter.local.finish := '"';
Result.filter.remote.start := 'href="';
Result.filter.remote.finish := '"';
Result.rev.start := 'rev="';
Result.rev.finish := '"';
Result.skip := [];
end;

function GetSVNVersion(svn: TSVN): Integer;
var
input: string;
begin
input := GetPage(svn.baseloc.remote.path);
Result := StrToIntDef(Between(svn.rev.start, svn.rev.finish, input), 0);
end;

procedure WriteSVNVersion(svn: TSVN);
var
rev: Integer;
begin
rev := GetSVNVersion(svn);
if rev = 0 then
begin
Writeln('Collecting rev number failed');
Writeln('You can manually set svn_settings.ini if this results in a problem');
exit;
end;

WriteINI(svn.name, 'REVISION', IntToStr(rev), SCARDirectory + 'svn_settings.ini');
end;

function IsSVNOld(svn: TSVN): Boolean;
var
curRev, locRev: Integer;
begin
locRev := StrToIntDef(ReadINI(svn.name, 'REVISION', AppPath + 'svn_settings.ini'), 0);
curRev := GetSVNVersion(svn);
if curRev = 0 then
begin
Writeln('Collecting current rev number failed');
Writeln('Assuming newer SVN is on local system to avoid problems');
Result := False;
Exit;
end;

Result := locRev < curRev;

if Result then
Writeln(svn.name + ' has the latest rev downloaded')
else
Writeln(svn.name + ' is rev ' + IntToStr(locRev) + ' and latest is ' + IntToStr(curRev));
end;

procedure MovePlugins(svn: TSVN; dest: string);
var
i, f: Integer;
s: string;
o: Boolean;
begin
for i := 0 to High(svn.files) do
if ((Linux) and (Pos('.so', svn.files[i].local.filename) > 0)) or ((not Linux) and (Pos('.dll', svn.files[i].local.filename) > 0)) then
try
Writeln('Found plugin "' + svn.files[i].local.filename);
if (Pos('Simba', svn.files[i].local.path) <= 0) then
begin
Writeln('Not a Simba plugin - ignoring');
Continue;
end;
o := False;
f := OpenFile(svn.baseloc.local.path + svn.files[i].local.path + svn.files[i].local.filename, False);
if (f = -1) then
begin
Writeln('Error opening file ''' + svn.baseloc.local.path + svn.files[i].local.path + svn.files[i].local.filename + '''');
Continue;
end;
ReadFileString(f, s, FileSize(f));
CloseFile(f);
o := True;
f := RewriteFile(dest + svn.files[i].local.filename, False);
if (f = -1) then
begin
Writeln('Error opening file ''' + dest + svn.files[i].local.filename + '''');
Continue;
end;
WriteFileString(f, s);
CloseFile(f);
except
Writeln('Failed to save plugin.');
if o then
Writeln('Problem involved rewriting the file at target folder')
else
Writeln('Problem involved opening the sauce file to read');
end;
end;

var
srl: TSVN;

begin
Writeln('Begin');

srl := ReturnSRLSVN;
if (not CheckVersion) or (CheckVersion and IsSVNOld(srl)) then
begin
CollectSVN(srl);
DownloadSVN(srl);

if MoveSRLPlugins then
MovePlugins(srl, Pluginpath);
end;

Writeln('End');
end.

^ Would work with the latest Simba..

Wizzup?

2010-02-18 11:58:55

Mixster, if you can think of a way to uncompress .tar.gz you can use snapshot instead of downloading from the svn.
http://vila.villavu.com/cgi-bin/gitweb/gitweb.cgi?p=srl-opendev.git;a=summary has a snapshot option

mixster

2010-02-18 13:36:35

Or I can add some parsing and make it check if it is the latest version and only update the needed files based on (what I think is) MD5 hashes it uses for 'commit' and 'parent' and so exploring then populate a list of updated files which should be updated.

As far as uncompressing .tar.gz, I don't think it would be a good idea unless there's a component for it in Simba as I would think a scripted Method would take forever to process to the point at which downloading it would be a better choice.

Wizzup?

2010-02-18 13:59:19

From: mixster
As far as uncompressing .tar.gz, I don't think it would be a good idea unless there's a component for it in Simba as I would think a scripted Method would take forever to process to the point at which downloading it would be a better choice.


Probably. ;)