[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Lost] [Patch] lpt: Repositories aus pkgsrc verwenden



+ lpt: Bei lpt get die Repository-URLs aus der pkgsrc statt hartkodierter URL 
verwenden
! lpt: Page Fault in lpt list korrigiert
Index: src/modules/pas/lpt/lpt.pas
===================================================================
--- src/modules/pas/lpt/lpt.pas	(Revision 722)
+++ src/modules/pas/lpt/lpt.pas	(Arbeitskopie)
@@ -1,7 +1,7 @@
 program pashello;
 {$MODE ObjFPC}
 
-uses dos, sysutils, classes, tar, tcpip, http, packages;
+uses dos, sysutils, classes, tar, tcpip, http, packages, repositories;
 
 const
     configRoot: String = 'file:/config/lpt/';
@@ -132,18 +132,26 @@
     srec: SearchRec;
     pkgset: TPackageSet;
     section: String;
+    repo: TRepository;
 
     version: TPackageVersion;
     filename: String;
     url: String;
 begin
+    ReadPkgsrc(configRoot + 'pkgsrc');
     pkgset := TPackageSet.create;
 
     dos.FindFirst(configRoot + 'pkglist.*', 0, srec);
     while DosError = 0 do begin
         WriteLn('Lese Paketliste ein: ' + srec.name);
-        // TODO Aus dem Namen die URL bestimmen
-        pkgset.ScanFile(configRoot + srec.name, 'http://192.168.1.3:8080/lpt/');
+        
+        repo := GetRepository(Copy(srec.name, length('pkglist.*'), length(srec.name)));
+        if repo = nil then begin
+            WriteLn('Fehler: Nicht in pkgsrc gefunden. Ueberspringe Quelle.');
+            continue;
+        end;
+
+        pkgset.ScanFile(configRoot + srec.name, repo.url);
         dos.FindNext(srec);
     end;
 
@@ -173,16 +181,24 @@
     sect: TPackageSection;
     ver: TPackageVersion;
 
+    repo: TRepository;
 
     i, j, k: integer;
 begin
+    ReadPkgsrc(configRoot + 'pkgsrc');
     pkgset := TPackageSet.create;
 
     dos.FindFirst(configRoot + 'pkglist.*', 0, srec);
     while DosError = 0 do begin
         WriteLn('Lese Paketliste ein: ' + srec.name);
-        // TODO Aus dem Namen die URL bestimmen
-        pkgset.ScanFile(configRoot + srec.name, 'http://192.168.1.3:8080/lpt/');
+
+        repo := GetRepository(Copy(srec.name, length('pkglist.*'), length(srec.name)));
+        if repo = nil then begin
+            WriteLn('Fehler: Nicht in pkgsrc gefunden. Ueberspringe Quelle.');
+            continue;
+        end;
+
+        pkgset.ScanFile(configRoot + srec.name, repo.url);
         dos.FindNext(srec);
     end;
 
@@ -190,10 +206,10 @@
         pkg := TPackage(pkgset.packages.items[i]);
         WriteLn('+ ' + pkg.name);
         for j := 0 to pkg.sections.count - 1 do begin
-            sect := TPackageSection(pkg.sections.items[i]);
+            sect := TPackageSection(pkg.sections.items[j]);
             WriteLn('| + ' + sect.section);
             for k := 0 to sect.versions.count - 1 do begin
-                ver := TPackageVersion(sect.versions.items[i]);
+                ver := TPackageVersion(sect.versions.items[k]);
                 WriteLn('| | + ' + ver.version);
             end;
         end;
Index: src/modules/pas/lpt/repositories.pas
===================================================================
--- src/modules/pas/lpt/repositories.pas	(Revision 0)
+++ src/modules/pas/lpt/repositories.pas	(Revision 0)
@@ -0,0 +1,77 @@
+unit repositories;
+{$MODE ObjFPC}
+
+interface
+uses sysutils, classes;
+
+type
+    TRepository = class(TCollectionItem)
+        public
+            name:   String;
+            url:    String;
+    end;
+
+
+procedure ReadPkgsrc(filename: String);
+function GetRepository(name: String): TRepository;
+
+
+implementation
+
+var
+    repos: TCollection;
+
+procedure ReadPkgsrc(filename: String);
+var
+    repo: TRepository;
+    f: Text;
+    name: String;
+    url: String;
+    space: integer;
+begin
+    Assign(f, filename);
+    Reset(f);
+    while not eof(f) do begin
+        ReadLn(f, url);
+
+        // Leerzeilen ignorieren
+        if url = '' then begin
+            continue;
+        end;
+
+        // Name und URL am ersten Leerzeichen auftrennen
+        space := Pos(' ', url);
+        if  space > 0 then begin
+            name := Copy(url, 1, space - 1);
+            url := Copy(url, space + 1, length(url));
+        end else begin
+            WriteLn('Ungueltige Paketquelle: ' + url);
+            continue;
+        end;
+
+        // Neues Repository in die Liste aufnehmen
+        repo := TRepository(repos.add());
+        repo.name := name;
+        repo.url := url;
+    end;
+    Close(f);
+end;
+
+function GetRepository(name: String): TRepository;
+var
+    i:      integer;
+    repo:   TRepository;
+begin
+    for i := 0 to repos.count - 1 do begin
+        repo := TRepository(repos.items[i]);
+        if repo.name = name then begin
+            exit(repo);
+        end;
+    end;
+
+    exit(nil);
+end;
+
+begin
+    repos := TCollection.create(TRepository);
+end.