txtmerge.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. from datetime import date
  33. from sys import version_info
  34. ofile.write(u"#addbuilddate" + '\n')
  35. today = date.today()
  36. if version_info.major == 2:
  37. du = unicode(today.strftime("$builddate = '%B %d, %Y'"), 'utf8') + '\n'
  38. elif version_info.major == 3:
  39. du = str(today.strftime("$builddate = '%B %d, %Y'")) + '\n'
  40. ofile.write(du)
  41. ofile.write(u"--- addbuilddate ---------------------------------" + '\n')
  42. ofile.close()