txtmerge-all.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. # usage: txtmerge-all.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 glob
  9. import shutil
  10. assert len(sys.argv) == 3, "usage:\ntxtmerge-all.py <input_dir> <output_file_name>"
  11. idir = str(sys.argv[1])
  12. oname = str(sys.argv[2])
  13. startLocationPath = os.path.join(idir, 'start.qsrc')
  14. with io.open(oname, 'w', encoding='utf-16', newline='\r\n') as ofile:
  15. with io.open(startLocationPath, 'rt', encoding='utf-8') as ifile:
  16. shutil.copyfileobj(ifile, ofile)
  17. for location in glob.glob(os.path.join(idir, '*.qsrc')):
  18. if location != startLocationPath:
  19. with io.open(location, 'rt', encoding='utf-8') as ifile:
  20. shutil.copyfileobj(ifile, ofile)
  21. from datetime import date
  22. from sys import version_info
  23. ofile.write(u"#addbuilddate" + '\n')
  24. today = date.today()
  25. if version_info.major == 2:
  26. du = unicode(today.strftime("$builddate = '%B %d, %Y'"), 'utf8') + '\n'
  27. elif version_info.major == 3:
  28. du = str(today.strftime("$builddate = '%B %d, %Y'")) + '\n'
  29. ofile.write(du)
  30. ofile.write(u"--- addbuilddate ---------------------------------" + '\n')