mission_merger.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #This was written for the 501st Starsim unit in Arma3
  2. #For faster mission integration with mission scripts
  3. #Written by CC Klein copyright 2018
  4. #Authors email: ethan.leas@gmail.com
  5. import os
  6. import subprocess
  7. from distutils.dir_util import *
  8. from distutils.file_util import *
  9. def isDir(dir):
  10. return os.path.isdir(dir)
  11. def pathName(dir, rPath):
  12. return os.path.join(dir, rPath)
  13. def listDir(dir):
  14. return os.listdir(dir)
  15. #Creating String values for Directory Structure
  16. dir = os.path.dirname(__file__)
  17. root_dir = pathName(dir, '../../')
  18. filename = pathName(dir, '../../Missions/')
  19. tmp_file = filename+"Temp/"
  20. script_files = pathName(dir, '../../Scripts/')
  21. mission_files = listDir(filename)
  22. pbo_tool_files = pathName(dir, '../../Util/Tools/')
  23. pbo_tool = pbo_tool_files+"MakePbo.exe"
  24. #For each mission folder in mission_files copy them to
  25. #tmp dir then copy scripts into mission tmp dir
  26. for name in mission_files:
  27. if name.endswith('.txt') == False and name != 'Temp' and name.endswith('.pbo') == False:
  28. print(name)
  29. src_dir = filename+name
  30. tmp_dir = tmp_file+name
  31. mkpath(tmp_dir)
  32. copy_tree(src_dir, tmp_dir)
  33. copy_tree(script_files, tmp_dir)
  34. subprocess.call([pbo_tool, "-PN",tmp_dir])
  35. #Get list of tmp dir after being populated
  36. pbo_files = listDir(tmp_file)
  37. pbo_dir = root_dir+"Pbo Files/"
  38. #If pbo dir does not exist create it
  39. #else delete it then create it
  40. if isDir(pbo_dir) == False:
  41. mkpath(pbo_dir)
  42. else:
  43. remove_tree(pbo_dir)
  44. mkpath(pbo_dir)
  45. #For each listing in tmp dir filter out .pbo files for copy
  46. for name in pbo_files:
  47. if name.endswith('.pbo') == True:
  48. src_file = tmp_file+name
  49. move_file(src_file, pbo_dir)
  50. #Cleanup
  51. #If temp dir exists delete
  52. if isDir(tmp_file) == True:
  53. remove_tree(tmp_file)