Guest User

Rescaler

a guest
Nov 10th, 2017
156
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """Fixes blur and distance issues for Kurst SWF Renderer in all XML files exported by JPEXS in the current directory, or specific XML files."""
  2. # Usage: python rescale.py [-s scale] [files...]
  3.  
  4. __author__ = "nagi123"
  5. __version__ = "1.0"
  6. __date__ = "November 10, 2017"
  7.  
  8. import os
  9. import re
  10. import sys
  11. from glob import glob
  12.  
  13. def rescale(filename, scale):
  14.     if not os.path.exists(filename):
  15.         return False
  16.     with open(filename) as file:
  17.         lines = file.readlines()
  18.     affected = False
  19.     with open(filename, "w") as file:
  20.         for line in lines:
  21.             blur = 'blurX="(\d+\.\d+)" blurY="(\d+\.\d+)"'
  22.             distance = 'distance="(\d+\.\d+)"'
  23.             if re.search(blur, line) or re.search(distance, line):
  24.                 affected = True
  25.             line = re.sub(blur, lambda m: 'blurX="' + str(float(m.group(1)) * scale) + '" blurY="' + str(float(m.group(2)) * scale) + '"', line)
  26.             line = re.sub(distance, lambda m: 'distance="' + str(float(m.group(1)) * scale) + '"', line)
  27.             file.write(line)
  28.     return affected
  29.  
  30. if __name__ == "__main__":
  31.     i = 1
  32.     if len(sys.argv) > 1:
  33.         if sys.argv[1] == "-s":
  34.             if len(sys.argv) > 2:
  35.                 try:
  36.                     scale = float(sys.argv[2])
  37.                 except ValueError:
  38.                     print "Invalid scale argument - must be floating-point number."
  39.                     sys.exit(1)
  40.                 i = 3
  41.             else:
  42.                 print "Invalid usage."
  43.                 print "Usage: python rescale.py [-s scale] [files...]"
  44.                 sys.exit(1)
  45.     else:
  46.         scale = raw_input("Enter scale value: ")
  47.         try:
  48.             scale = float(scale)
  49.         except ValueError:
  50.             print "Invalid scale value - must be floating-point number."
  51.             sys.exit(1)
  52.     filenames = sys.argv[i:] or glob("*.xml")
  53.     affected = []
  54.     for filename in filenames:
  55.         if rescale(filename, scale):
  56.             affected.append(filename)
  57.     if affected:
  58.         if len(affected) == 1:
  59.             print "1 file affected."
  60.         else:
  61.             print str(len(affected)) + " files affected."
  62.     else:
  63.         print "No files affected."
  64.     sys.exit(0)
RAW Paste Data