lsinary 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Main fork Pisi: Copyright (C) 2005 - 2011, Tubitak/UEKAE
  5. #
  6. # Copyright (C) 2018, Suleyman POYRAZ (Zaryob)
  7. #
  8. # This program is free software; you can redistribute it and/or modify it under
  9. # the terms of the GNU General Public License as published by the Free
  10. # Software Foundation; either version 2 of the License, or (at your option)
  11. # any later version.
  12. #
  13. # Please read the COPYING file.
  14. import os
  15. import sys
  16. import inary.api
  17. def show_info(filename):
  18. metadata, files = inary.api.info_file(filename)
  19. paths = [fileinfo.path for fileinfo in files.list]
  20. paths.sort()
  21. return paths
  22. def uniq(alist):
  23. set = {}
  24. return [set.setdefault(e, e) for e in alist if e not in set]
  25. def usage(errmsg):
  26. print(("""
  27. Error: %s
  28. Usage:
  29. lsinary INARY_package.INARY (lists the content of package)
  30. lsinary dirs INARY_package.INARY (lists directories in the package for the package developer)
  31. """ % (errmsg)))
  32. sys.exit(1)
  33. def main():
  34. if len(sys.argv) < 2 or ("dirs" in sys.argv and len(sys.argv) < 3):
  35. usage("INARY package required...")
  36. if sys.argv[1] == "dirs":
  37. dirlist = []
  38. for file in show_info(sys.argv[2]):
  39. dirlist.append(os.path.dirname(file))
  40. for dir in uniq(dirlist):
  41. print(("<Path fileType=\"\">/%s</Path>" % dir))
  42. elif not os.path.exists(sys.argv[1]):
  43. print("File %s not found" % sys.argv[1])
  44. else:
  45. for file in show_info(sys.argv[1]):
  46. print(("/%s" % file))
  47. if __name__ == "__main__":
  48. sys.exit(main())