From 65c1affbdcf293a8445c378cc4fdb2ea0e07fbd5 Mon Sep 17 00:00:00 2001 From: Stefan Hacker Date: Sun, 21 Jun 2015 18:57:20 +0200 Subject: [PATCH] Add generate-qrc.py script as a rcc -project replacement One can use rcc -project to emit .qrc files for the contents of a directory. However this functionality seems to be woefully incomplete to the point of being broken. This small python script offers the same functionality with more options to customize and configure behaviour. This includes custom prefixes, better handling of qrc file path vs. alias and exclusions. --- scripts/generate-qrc.py | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 scripts/generate-qrc.py diff --git a/scripts/generate-qrc.py b/scripts/generate-qrc.py new file mode 100755 index 000000000..93373e611 --- /dev/null +++ b/scripts/generate-qrc.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python + +# +# Improved version of rcc --project +# +import sys +import os +import re +import argparse + +parser = argparse.ArgumentParser(description='Improved version of rcc --project') +parser.add_argument('theme') +parser.add_argument('--cwd', default='.') +parser.add_argument('--prefix', default='') +parser.add_argument('--output', '-o') +parser.add_argument('--include', '-i', default='.*', help='Default inclusion regex') +parser.add_argument('--exclude', '-e', default='a^', help='Default exclusion regex') + +args = parser.parse_args() + +out = sys.stdout +if args.output: + out = open(args.output, 'w') + +print>>out, '' +print>>out, '' +print>>out, '' % args.prefix + +include = re.compile(args.include) +exclude = re.compile(args.exclude) + +os.chdir(args.cwd) +for (dirpath, dirnames, filenames) in os.walk(args.theme): + for f in filenames: + path = os.path.join(dirpath, f) + relpath = os.path.relpath(path, args.theme) + + if not include.search(relpath): + continue + + if exclude.search(relpath): + continue + + print>>out, ' %s' % (relpath, path) +print>>out, '' +print>>out, ''