concat_dbus_conf_files.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. # Copyright 2019 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """Concatenates D-Bus busconfig files."""
  6. import sys
  7. import xml.etree.ElementTree
  8. _BUSCONFIG_FILE_HEADER = b"""<!DOCTYPE busconfig
  9. PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
  10. "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
  11. """
  12. def main():
  13. if len(sys.argv) < 3:
  14. sys.stderr.write('Usage: %s OUTFILE INFILES\n' % (sys.argv[0]))
  15. sys.exit(1)
  16. out_path = sys.argv[1]
  17. in_paths = sys.argv[2:]
  18. # Parse the first input file.
  19. tree = xml.etree.ElementTree.parse(in_paths[0])
  20. assert(tree.getroot().tag == 'busconfig')
  21. # Append the remaining input files to the first file.
  22. for path in in_paths[1:]:
  23. current_tree = xml.etree.ElementTree.parse(path)
  24. assert(current_tree.getroot().tag == 'busconfig')
  25. for child in current_tree.getroot():
  26. tree.getroot().append(child)
  27. # Output the result.
  28. with open(out_path, "wb") as f:
  29. f.write(_BUSCONFIG_FILE_HEADER)
  30. tree.write(f)
  31. if __name__ == '__main__':
  32. main()