From 38fc6d8a4271365d07877a686bf63b3df556e50a Mon Sep 17 00:00:00 2001 From: Wojciech Nagrodzki <278594+wnagrodzki@users.noreply.github.com> Date: Thu, 4 Mar 2021 17:36:46 +0100 Subject: [PATCH] Add script for listing missing colors in xib and storyboard files --- Colorsets/ls_missing_colors.py | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 Colorsets/ls_missing_colors.py diff --git a/Colorsets/ls_missing_colors.py b/Colorsets/ls_missing_colors.py new file mode 100755 index 0000000..26067e0 --- /dev/null +++ b/Colorsets/ls_missing_colors.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 + +""" Searches xib and storyboard files for missing colors. + +If a named color is used in user interface file, and it is not present in +asset catalog it is considered missing. +""" + +import os +import pathlib +import xml.etree.ElementTree + +# Find colors + +known_colors = [] + +for dirpath, dirnames, filenames in os.walk('.'): + pure_path = pathlib.PurePath(dirpath) + directory_name = pure_path.name + if '.colorset' in directory_name: + known_colors.append(pure_path.stem) + +# Find user interface files + +filepaths = [] + +for dirpath, dirnames, filenames in os.walk('.'): + for filename in filenames: + name_path = pathlib.PurePath(filename) + if name_path.suffix in [".xib", ".storyboard"]: + filepath = os.path.join(dirpath, name_path) + filepaths.append(filepath) + +# Check if user interface files contain unknown colors + +for filepath in filepaths: + tree = xml.etree.ElementTree.parse(filepath) + root = tree.getroot() + resources = root.find("resources") + if resources is None: + continue + for named_color in resources.findall("namedColor"): + color_name = named_color.get("name") + if color_name not in known_colors: + message = "warning: missing color: " + color_name + " used in: " + pathlib.PurePath(filepath).name + print(message)