jenkins-bot has submitted this change and it was merged. Change subject: Convert icons has option to convert only specified icons ......................................................................
Convert icons has option to convert only specified icons When svg file names are provided as command line arguments then it will only convert the give files. Otherwise it'll convert all files. Note that you should specify only the file name, not the whole path. Bug: T107686 Change-Id: I98ae762004ad2d5de9f07de1ef170d1df206e436 --- M scripts/convert-icons.py 1 file changed, 42 insertions(+), 6 deletions(-) Approvals: Mholloway: Looks good to me, approved Niedzielski: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/scripts/convert-icons.py b/scripts/convert-icons.py index e318d60..abe1f19 100755 --- a/scripts/convert-icons.py +++ b/scripts/convert-icons.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import os import sh +import sys from glob import glob @@ -16,10 +17,35 @@ class ImagesBatch(object): - def __init__(self, path): + def __init__(self, path, filters): self.dp = int(os.path.basename(path)) self.path = path - self.svgs = [os.path.abspath(p) for p in glob(os.path.join(path, "*.svg"))] + self.svgs = [] + all_svgs = self.find_svg_files(path) + filtered_svgs = self.filter_filenames(all_svgs, filters) + self.svgs = self.abspath(filtered_svgs) + + @staticmethod + def find_svg_files(path): + return [p for p in glob(os.path.join(path, "*.svg"))] + + @staticmethod + def filter_filenames(all_svg_files, filters=None): + relative_svg_files = [] + if filters: + for filter in filters: + if os.path.join(source_path, filter) in all_svg_files: + relative_svg_files.append(os.path.join(source_path, filter)) + else: + relative_svg_files = all_svg_files + return relative_svg_files + + @staticmethod + def abspath(filenames): + output = [] + for filename in filenames: + output.append(os.path.abspath(filename)) + return output def _do_export(self, density, input_path, drawable): nonspecific = ".nonspecific." in input_path @@ -33,7 +59,7 @@ sh.rsvg_convert(input_path, "-a", h=px, o=output_precrush_path) sh.pngcrush("-q", "-reduce", output_precrush_path, output_file_path) sh.rm(output_precrush_path) - return (output_file_path, noflip) + return output_file_path, noflip def _do_flop(self, density, (input_path, noflip)): if noflip: @@ -55,8 +81,18 @@ print(u"\u2713 %s" % os.path.basename(svg)) +def validate_filters(filter_set): + for filter in filter_set: + if not filter.endswith(".svg") or "/" in filter: + print >> sys.stderr, 'Only svg file names allowed in arguments.' + sys.exit(-1) + return filter_set + if __name__ == "__main__": - paths = glob(os.path.join(os.path.dirname(__file__), "../icon-svgs/*")) - for path in paths: - ib = ImagesBatch(path) + svg_filters = None + if len(sys.argv) > 1: + svg_filters = validate_filters(set(sys.argv[1:])) + source_density_paths = glob(os.path.join(os.path.dirname(__file__), "../icon-svgs/*")) + for source_path in source_density_paths: + ib = ImagesBatch(source_path, svg_filters) ib.convert() -- To view, visit https://gerrit.wikimedia.org/r/241959 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I98ae762004ad2d5de9f07de1ef170d1df206e436 Gerrit-PatchSet: 2 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: BearND <bsitzm...@wikimedia.org> Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org> Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org> Gerrit-Reviewer: Niedzielski <sniedziel...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits