pakhandler.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # -*- coding: utf-8 -*-
  2. import piksemel
  3. import sys
  4. import os
  5. pythonPath="/usr/lib/python%d.%d" % sys.version_info[:2]
  6. def byteCompile(filepath):
  7. doc = piksemel.parse(filepath)
  8. paths = []
  9. for item in doc.tags("File"):
  10. path = item.getTagData("Path")
  11. if path.endswith(".py") and not path.startswith("usr/share/doc/"):
  12. paths.append("/"+path)
  13. if paths:
  14. os.system("/usr/bin/python %s/py_compile.py %s" % (pythonPath, " ".join(paths)))
  15. def removeByteCompiled(filepath):
  16. doc = piksemel.parse(filepath)
  17. for item in doc.tags("File"):
  18. path = item.getTagData("Path")
  19. if path.endswith(".py"):
  20. try:
  21. # Remove .pyc and .pyo
  22. os.unlink("/%sc" % path)
  23. os.unlink("/%so" % path)
  24. except OSError:
  25. pass
  26. def setupPackage(metapath, filepath):
  27. byteCompile(filepath)
  28. def cleanupPackage(metapath, filepath):
  29. pass
  30. def postCleanupPackage(metapath, filepath):
  31. removeByteCompiled(filepath)