1
0

txtmerge.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python
  2. # usage: txtmerge.py <input_dir> <output_file_name>
  3. # does the exact opposite of txtsplit.py
  4. import os
  5. import sys
  6. import re
  7. import io
  8. import xml.etree.ElementTree as ET
  9. assert len(sys.argv) == 3, "usage:\ntxtmerge.py <input_dir> <output_file_name>"
  10. idir = str(sys.argv[1])
  11. oname = str(sys.argv[2])
  12. # read the project xml file first
  13. # let's do this later in order to implement directory structure
  14. tree = ET.parse('glife.qproj')
  15. root = tree.getroot()
  16. ofile = io.open(oname, 'w', encoding='utf-16', newline='\r\n')
  17. for location in root.iter('Location'):
  18. iname = location.attrib['name']
  19. iname = iname.replace("$","_")
  20. try:
  21. ifile = io.open(os.path.join(idir,iname + '.qsrc'), 'rt', encoding='utf-8')
  22. text = ifile.read()
  23. # make sure there's a line at the end of file
  24. # (why wouldn't there be one? WINDOWS!
  25. if text[-1] != u'\n':
  26. text += u'\n\n'
  27. ofile.write(text)
  28. ifile.close()
  29. except IOError:
  30. print("WARNING: missing location %s" % iname)
  31. pass
  32. ofile.close()