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.

96 lines
2.5 KiB

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