Skip to content

Instantly share code, notes, and snippets.

@rachitmishra
Last active July 4, 2019 07:04
Show Gist options
  • Save rachitmishra/616546a84c8bd04c6eef9d3c73708492 to your computer and use it in GitHub Desktop.
Save rachitmishra/616546a84c8bd04c6eef9d3c73708492 to your computer and use it in GitHub Desktop.
Python script to fix vector errors for android (.1 to 0.1)
from xml.dom.minidom import parse, parseString
from sys import argv
import os
def fix_path(pathdata, token):
# Fix missing 0 after space
points = pathdata.split(token)
for i, b in enumerate(points):
if b.startswith('.'):
points[i] = '0' + b
return token.join(points)
def fix_file(filename):
dom1 = parse(filename)
paths = dom1.getElementsByTagName('path')
for a in paths:
for s in [" ", "-", "c", "m", "l", "h", "s", "a", "v", "M", "L", "C"]:
pathdata = a.attributes['android:pathData'].value
a.setAttribute('android:pathData', fix_path(pathdata, s))
return dom1.toxml()
def update_file(filename, content):
with open(filename, "w") as f:
f.write(content)
def fix_folder(path):
for entry in os.scandir(path):
if entry.is_dir():
if(entry.name == "build"):
continue
fix_folder(entry.path)
if entry.is_file():
if (entry.name.startswith('vc_')):
print("Fixing file " + entry.path)
newcontent = fix_file(entry.path)
print("Updating file ")
update_file(entry.path, newcontent)
def validate_arg(args):
if (len(argv) == 1):
print("""
------------------------------
Usage:
-a : Fix folder
-f : Fix file
------------------------------
""")
return False
if (len(argv) > 3):
print("""
------------------------------
Error:
Only one of following is allowed
-a : Fix folder
-f : Fix file
------------------------------
""")
return False
return True
def process_arg(args):
if (argv[1] == '-a'):
print("Fixing folder " + argv[2])
fix_folder(argv[2])
if (argv[1] == '-f'):
print("Fixing file " + argv[2])
newcontent = fix_file(argv[2])
print("Updating file ")
update_file(argv[2], newcontent)
if __name__ == '__main__':
if validate_arg(argv):
process_arg(argv)
@rachitmishra
Copy link
Author

@Hero9909 well that was the goal helping out someone with a similar problem :)

I will fix the other issue you have mentioned and update the gist.

Thanks for the coffee 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment