generate-flist.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import sys
  5. # Generate the list of files needed in initramfs for plymouth
  6. exclude_list = (
  7. "/usr/sbin/plymouth-set-default-theme",
  8. "/usr/lib/plymouth/renderers/x11.so",
  9. "/usr/lib/plymouth/label.so",
  10. )
  11. paths = (
  12. "/usr/share/plymouth",
  13. "/usr/share/pixmaps",
  14. "/etc/plymouth",
  15. )
  16. FILE_LIST = "lib/initramfs/plymouth.list"
  17. def usage():
  18. print "%s <directory>" % sys.argv[0]
  19. return 1
  20. def generate_needed_binary_list():
  21. binaries = set()
  22. executables = os.popen("find -type f -executable | cut -c2-").read().strip().split()
  23. executables = set(executables).difference(exclude_list)
  24. for exe in executables:
  25. if exe.endswith(".la"):
  26. continue
  27. if ".so." in exe:
  28. # Add the libfoo.so.X symlink instead of libfoo.so.X.y.z
  29. symlink = exe.rsplit(".", 2)[0]
  30. if os.path.exists(symlink[1:]):
  31. binaries.add(symlink)
  32. continue
  33. binaries.add(exe)
  34. for exe in executables:
  35. for line in os.popen("ldd %s" % exe[1:]):
  36. if "=> /" in line:
  37. binaries.add(line.split()[2])
  38. elif line.strip().startswith("/"):
  39. binaries.add(line.strip().split()[0])
  40. return binaries
  41. def get_other_file_list():
  42. files = ["usr/share/pixmaps/plymouth-pisilinux.png", "usr/share/themes/charge/charge.plymouth"]
  43. for path in paths:
  44. files.extend(os.popen("find %s -type f" % path[1:]).read().strip().split())
  45. return ["/%s" % f for f in files]
  46. if __name__ == "__main__":
  47. try:
  48. directory = sys.argv[1]
  49. except:
  50. sys.exit(usage())
  51. os.chdir(directory)
  52. files = generate_needed_binary_list()
  53. files = files.union(get_other_file_list())
  54. if not os.path.exists(os.path.dirname(FILE_LIST)):
  55. os.makedirs(os.path.dirname(FILE_LIST))
  56. open(FILE_LIST, "w").write("\n".join(sorted(files)))