generate-flist1.py 2.1 KB

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