Last active
February 2, 2022 21:29
-
-
Save Kethen/9330128586210276813b9ea03861bf71 to your computer and use it in GitHub Desktop.
python script for merging themes.xml and colors.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xml.etree.ElementTree import parse, indent | |
import re | |
import sys | |
colors = parse("material-theme/values/colors.xml") | |
day = parse("material-theme/values/themes.xml") | |
night = parse("material-theme/values-night/themes.xml") | |
def get_color(tree, colorString): | |
colorName = re.compile("@color/(.+)").match(colorString).group(1) | |
for color in tree.getroot().findall("color"): | |
if color.get("name") == colorName: | |
return color.text | |
def apply_patch(theme, colors): | |
style = theme.getroot().find("style") | |
style.set("name", sys.argv[1]) | |
del style.attrib["parent"] | |
for item in style: | |
item.text = get_color(colors, item.text) | |
apply_patch(day, colors) | |
apply_patch(night, colors) | |
indent(day) | |
day.write("day.xml") | |
indent(night) | |
night.write("night.xml") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python3 convert.py <patch name>
, with material-theme in the current directorygenerates day.xml and night.xml into current directory