Advertisement
Kitomas

minifyShaders.py as of 2024-01-19

Jan 19th, 2024 (edited)
759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. if __name__ != "__main__": exit(0)
  3. from time import time
  4. from os import walk as folderIterate, system as cmd
  5. from os.path import isdir, exists, join as pathJoin
  6. from sys import argv
  7.  
  8. #1st argument is one of these build modes
  9. #2nd argument is the output file name
  10. #the rest are input file names
  11. build_modes = {
  12.     "-release" : "",
  13.     "-debug"   : "--no-renaming"
  14. }
  15.  
  16.  
  17. def getFilesInFolderRecursively(rootIn):
  18.     paths = ''
  19.     if not exists(rootIn): return None
  20.     if not isdir(rootIn): return False
  21.     for root, dirs, files in folderIterate(rootIn,topdown=True):
  22.         for fi in files:
  23.             paths += pathJoin(root,fi)+' '
  24.     return paths
  25.  
  26.  
  27. if len(argv) < 4: exit()
  28.  
  29. if not argv[1].lower() in build_modes:
  30.     print("Error: \"{}\" is not a valid build mode!".format(argv[1]))
  31.     exit(1)
  32.  
  33. flags, paths  =  build_modes[argv[1]], ''
  34.  
  35. #(starting at 3 because argv[2] is the OUTPUT file, not input)
  36. for i in range(3,len(argv)):
  37.     paths += getFilesInFolderRecursively(argv[i])
  38.    
  39.     if type(paths) == bool:
  40.         print("Error: \"{}\" is a file, not a folder!".format(argv[i]))
  41.         exit(1)
  42.     elif paths == None:
  43.         print("Error: \"{}\" does not exist!".format(argv[i]))
  44.         exit(1)
  45.     elif type(paths) != str:
  46.         print("Error: paths returned unknown type")
  47.         exit(1)
  48.    
  49. if paths != '':
  50.     cmd("shader_minifier.exe {} -o {} {}".format(flags, argv[2], paths))
  51.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement