pakhandler.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. import piksemel
  3. def updateIndex():
  4. import os
  5. import subprocess
  6. join = os.path.join
  7. fontsPath = "/usr/share/fonts"
  8. encodingsPath = join(fontsPath, "encodings")
  9. fontsScale = "fonts.scale"
  10. fontsDir = "fonts.dir"
  11. for root, dirs, files in os.walk(fontsPath):
  12. if root.startswith(encodingsPath):
  13. continue
  14. fonts = files[:]
  15. if fontsScale in fonts:
  16. fonts.remove(fontsScale)
  17. os.unlink(join(root, fontsScale))
  18. if fontsDir in fonts:
  19. fonts.remove(fontsDir)
  20. os.unlink(join(root, fontsDir))
  21. if not fonts:
  22. continue
  23. print "Creating %s ..." % join(root, fontsScale)
  24. subprocess.call(["/usr/bin/mkfontscale", "-u", root])
  25. print "Creating %s ..." % join(root, fontsDir)
  26. subprocess.call(["/usr/bin/mkfontdir", root])
  27. def checkPaths(filepath):
  28. doc = piksemel.parse(filepath)
  29. for item in doc.tags("File"):
  30. path = item.getTagData("Path")
  31. if path.startswith("usr/share/fonts/"):
  32. updateIndex()
  33. break
  34. def setupPackage(metapath, filepath):
  35. checkPaths(filepath)
  36. def cleanupPackage(metapath, filepath):
  37. pass
  38. def postCleanupPackage(metapath, filepath):
  39. checkPaths(filepath)