lsar_example.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import sys, os
  2. sys.path.append(os.path.abspath('..')) # For accesing the module
  3. from lsar import Lsar, JsonResultItemZip, JsonResultItemTar, JsonResultItemRar
  4. lsar = Lsar()
  5. lsar.file = 'example.zip'
  6. result = None
  7. try:
  8. # This is needed to fetch usefull data fron lsar.
  9. result = lsar.fetch()
  10. except UnknownOption as err:
  11. print("Version mismatch? Error: {0}".format(err))
  12. except ArchiveNotFound as err:
  13. print("ArchiveNotFound Error: {0}".format(err))
  14. except UnknownOption as err:
  15. print("PasswordRequired Error: {0}".format(err))
  16. except UnknownOption as err:
  17. print("ParseError Error: {0}".format(err))
  18. except UnknownOption as err:
  19. print("UnarchiveError Error: {0}".format(err))
  20. except UnknownFormatError as err:
  21. print("UnarchiveError Error: {0}".format(err))
  22. if result:
  23. print("Format: {0}".format(result.formatName()))
  24. print("formatVersion: {0}".format(result.formatVersion()))
  25. print("contents: {0}".format(result.contents()))
  26. print("encoding: {0}".format(result.encoding()))
  27. print("confidence: {0}".format(result.confidence()))
  28. print("properties: {0}".format(result.properties()))
  29. print("isEncrypted: {0}".format(result.isEncrypted()))
  30. print("archiveName: {0}".format(result.archiveName()))
  31. print("volumes: {0}".format(result.volumes()))
  32. print("isMultiArchive: {0}".format(result.isMultiArchive()))
  33. print("\n----\nContent:")
  34. for fileObject in result.contentsObjects():
  35. print("\tType: {0}".format(type(fileObject)))
  36. print("\tName: {0}".format(fileObject.name()))
  37. print("\tIndex: {0}".format(fileObject.index()))
  38. if type(fileObject) == JsonResultItemZip:
  39. print("\t\tlocalDate: {0}".format(fileObject.localDate()))
  40. print("\t\tcompressionMethod: {0}".format(fileObject.compressionMethod()))
  41. print("\t\textractVersion: {0}".format(fileObject.extractVersion()))
  42. print("\t\tOS: {0}".format(fileObject.OS()))
  43. print("\t\tCRC32: {0}".format(fileObject.CRC32()))
  44. print("\t\tfileAttributes: {0}".format(fileObject.fileAttributes()))
  45. print("\t\tflags: {0}".format(fileObject.flags()))
  46. print("\t\tOSName: {0}".format(fileObject.OSName()))
  47. elif type(fileObject) == JsonResultItemTar:
  48. print("\t\tisSparseFile: {0}".format(fileObject.isSparseFile()))
  49. elif type(fileObject) == JsonResultItemRar:
  50. print("\t\tattributes: {0}".format(fileObject.attributes()))
  51. print("\t\tsolidIndex: {0}".format(fileObject.solidIndex()))
  52. print("\t\tcompressionVersion: {0}".format(fileObject.compressionVersion()))
  53. print("\t\tcompressionMethod: {0}".format(fileObject.compressionMethod()))
  54. print("\t\tOS: {0}".format(fileObject.OS()))
  55. print("\t\tCRC32: {0}".format(fileObject.CRC32()))
  56. print("\t\tflags: {0}".format(fileObject.flags()))
  57. print("\t\tOSName: {0}".format(fileObject.OSName()))
  58. print()