OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.5 KiB

  1. -- --- T2-COPYRIGHT-NOTE-BEGIN ---
  2. -- This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. --
  4. -- T2 SDE: misc/lua/parse-db.lua
  5. -- Copyright (C) 2005 - 2006 The T2 SDE Project
  6. --
  7. -- More information can be found in the files COPYING and README.
  8. --
  9. -- This program is free software; you can redistribute it and/or modify
  10. -- it under the terms of the GNU General Public License as published by
  11. -- the Free Software Foundation; version 2 of the License. A copy of the
  12. -- GNU General Public License can be found in the file COPYING.
  13. -- --- T2-COPYRIGHT-NOTE-END ---
  14. -- parse all packages.db information into tables
  15. -- filelist saving commented out (eats another 30M)
  16. require "lzlib"
  17. require "t2_desc"
  18. function block_lines()
  19. local line = lines();
  20. if (line == nil) or (line=="\023") then
  21. return nil;
  22. end
  23. return line;
  24. end
  25. function read_deps()
  26. local deps={}
  27. for line in block_lines do
  28. _,_,dependency = string.find(line, "[^ ]* (.*)");
  29. table.insert (deps, dependency);
  30. end
  31. return deps;
  32. end
  33. function read_flist()
  34. local files={};
  35. local cksums={};
  36. local sizes={};
  37. local usage=0;
  38. for line in block_lines do
  39. _,_,cksum,size,file = string.find(line, "^([0-9]+) ([0-9]+) (.*)");
  40. -- uncomment theese lines if you want to save complete file list
  41. -- table.insert (files, file);
  42. -- table.insert (cksums, 1 * cksum);
  43. -- table.insert (sizes, 1 * size);
  44. usage = usage + size;
  45. end
  46. return usage,files,cksums,sizes;
  47. end
  48. zf,error = lzlib.open("./packages.db", "r");
  49. if not zf then -- failed to open file, print error
  50. print(error);
  51. else
  52. lines = zf:lines(); -- obtain line iterator
  53. packages = {};
  54. repeat -- parse packages
  55. pkgname = lines();
  56. if pkgname then
  57. print(pkgname);
  58. local pkg_data = {};
  59. if lines() ~= "\023" then -- separator line
  60. print ("terminating line missing\n");
  61. end
  62. pkg_data.desc=t2_desc.parse (block_lines);
  63. pkg_data.deps=read_deps ();
  64. pkg_data.usage = read_flist ();
  65. if lines() ~= "\004" then -- separator line
  66. print ("terminating line missing\n");
  67. end
  68. packages[pkgname] = pkg_data;
  69. end
  70. until pkgname == nil;
  71. _,normal_eof,error = zf:eof ();
  72. if not normal_eof then -- check if stream ended because of error
  73. print ("-- abnormal end of stream: ", error);
  74. end
  75. ok,error = zf:close();
  76. if not ok then
  77. print ("could not close stream: ", error);
  78. end
  79. x = gcinfo ();
  80. print(x, "kb dynamic memory used.");
  81. end