[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [tyndur-devel] [PATCH] lpt: Filter beim Auflisten
On Mon, Jan 24, 2011 at 06:39:22PM +0100, Arne Hasselbring wrote:
> + Durch Eingabe von lpt list --filter [installed|notinstalled] werden nur
> installierte bzw. nicht installierte Pakete angezeigt
> ---
> src/modules/pas/lpt/lpt.pas | 119 ++++++++++++++++++++++++++++++++++++++++++-
> 1 files changed, 118 insertions(+), 1 deletions(-)
Hm, kann man natürlich so machen, aber irgendwie tendierst du dazu, Code
zu kopieren statt ihn wiederzuverwenden.
Meine erste Idee wäre gewesen, ein TPackageSet.Filter einzubauen, das
einen Funktionspointer function (pkgset: PPackageSet): boolean; nimmt
und zurückgibt, ob ein Eintrag in der Menge bleiben soll oder nicht.
Dann braucht du nämlich von dem ganzen Ausgabecode keine Kopien, sondern
kannst ihn einfach mit dem jeweils richtigen TPackageSet füttern.
> diff --git a/src/modules/pas/lpt/lpt.pas b/src/modules/pas/lpt/lpt.pas
> index 5705d97..1ab91f8 100644
> --- a/src/modules/pas/lpt/lpt.pas
> +++ b/src/modules/pas/lpt/lpt.pas
> @@ -295,6 +295,111 @@ begin
> end;
> end;
>
> +
> +procedure ListInstalled;
> +var
> + srec: SearchRec;
srec sieht unbenutzt aus.
> + pkgset: TPackageSet;
> + pkg: TPackage;
> + sect: TPackageSection;
> + ver: TPackageVersion;
> + dep: TDependency;
> +
> + repo: TRepository;
> +
> + i, j, k, l: integer;
> + filename: String;
> +begin
> + ReadPkgsrc(getConfigRoot + 'pkgsrc');
> + pkgset := TPackageSet.create;
> + ReadPkglists(pkgset);
> +
> + for i := 0 to pkgset.packages.count - 1 do begin
> + pkg := TPackage(pkgset.packages.items[i]);
> + for j := 0 to pkg.sections.count - 1 do begin
> + sect := TPackageSection(pkg.sections.items[j]);
> + for k := 0 to sect.versions.count - 1 do begin
> + ver := TPackageVersion(sect.versions.items[k]);
> + filename := 'file:/packages/' + ver.pkg.name + '/' +
> + ver.version + '/' + ver.section.section + '/';
> +
> + if FileExists(filename) then begin
> + Write(pkg.name, StringOfChar(' ', 12 - Length(pkg.name)));
> + Write(' | ', sect.section, StringOfChar(' ', 5 - Length(sect.section)));
> + Write(' | ', ver.version : 10);
> + if Length(pkg.desc) > 43 then begin
> + WriteLn(' | ' + Copy(pkg.desc, 1, 40), '...');
> + end else begin
> + WriteLn(' | ' + pkg.desc);
> + end;
> +
> + for l := 0 to ver.preinstDependencies.count - 1 do begin
> + dep := TDependency(ver.preinstDependencies.items[l]);
> + WriteLn('' : 36, rsListInstallDependency, dep.pkgname + ' (' + dep.section + ')');
> + end;
> +
> + for l := 0 to ver.runDependencies.count - 1 do begin
> + dep := TDependency(ver.runDependencies.items[l]);
> + WriteLn('' : 36, rsListRunDependency, dep.pkgname + ' (' + dep.section + ')');
> + end;
> + end;
> + end;
> + end;
> + end;
> +end;
> +
> +
> +procedure ListNotInstalled;
> +var
> + srec: SearchRec;
Hier auch.
> + pkgset: TPackageSet;
> + pkg: TPackage;
> + sect: TPackageSection;
> + ver: TPackageVersion;
> + dep: TDependency;
> +
> + repo: TRepository;
> +
> + i, j, k, l: integer;
> + filename: String;
> +begin
> + ReadPkgsrc(getConfigRoot + 'pkgsrc');
> + pkgset := TPackageSet.create;
> + ReadPkglists(pkgset);
> +
> + for i := 0 to pkgset.packages.count - 1 do begin
> + pkg := TPackage(pkgset.packages.items[i]);
> + for j := 0 to pkg.sections.count - 1 do begin
> + sect := TPackageSection(pkg.sections.items[j]);
> + for k := 0 to sect.versions.count - 1 do begin
> + ver := TPackageVersion(sect.versions.items[k]);
> + filename := 'file:/packages/' + ver.pkg.name + '/' +
> + ver.version + '/' + ver.section.section + '/';
> + if not FileExists(filename) then begin
> + Write(pkg.name, StringOfChar(' ', 12 - Length(pkg.name)));
> + Write(' | ', sect.section, StringOfChar(' ', 5 - Length(sect.section)));
> + Write(' | ', ver.version : 10);
> + if Length(pkg.desc) > 43 then begin
> + WriteLn(' | ' + Copy(pkg.desc, 1, 40), '...');
> + end else begin
> + WriteLn(' | ' + pkg.desc);
> + end;
> +
> + for l := 0 to ver.preinstDependencies.count - 1 do begin
> + dep := TDependency(ver.preinstDependencies.items[l]);
> + WriteLn('' : 36, rsListInstallDependency, dep.pkgname + ' (' + dep.section + ')');
> + end;
> +
> + for l := 0 to ver.runDependencies.count - 1 do begin
> + dep := TDependency(ver.runDependencies.items[l]);
> + WriteLn('' : 36, rsListRunDependency, dep.pkgname + ' (' + dep.section + ')');
> + end;
> + end;
> + end;
> + end;
> + end;
> +end;
> +
> function c_lostio_create_link(target, link: PChar; hard: boolean): integer; cdecl; external name 'io_create_link';
>
> procedure CfgAddbin(path, pubname: String);
> @@ -358,7 +463,19 @@ begin
> if system.ParamStr(1) = 'scan' then begin
> Scan;
> end else if system.ParamStr(1) = 'list' then begin
> - List;
> + if system.ParamCount = 1 then begin
> + List;
> + end else if system.ParamCount = 3 then begin
> + if system.ParamStr(2) = '--filter' then begin
> + if system.ParamStr(3) = 'installed' then begin
> + ListInstalled;
> + end else if system.ParamStr(3) = 'notinstalled' then begin
Vielleicht 'new' statt 'notinstalled'?
> + ListNotInstalled;
> + end;
> + end;
Da fehlen ein paar else-Zweige, die mich anmeckern, wenn ich 'lpt list
--filter kaputt' oder 'lpt list foo bar' eingebe.
> + end else begin
> + WriteLn(rsWrongParamCount);
> + end;
> end else if system.ParamStr(1) = 'get' then begin
> if system.ParamCount = 2 then begin
> Get(system.ParamStr(2), false);
> --
> 1.7.1
>
> _______________________________________________
> tyndur-devel mailing list
> tyndur-devel@xxxxxxxxxx
> http://list.tyndur.org/mailman/listinfo/tyndur-devel