From 048648c9f71a37bf4e5f1c58d05bfc285eede465 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 16 Oct 2013 12:49:44 -0300 Subject: Add tool to generate project file automatically. --- data/bitmask.pro.template | 9 ++++++ data/make_project_file.py | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 data/bitmask.pro.template create mode 100755 data/make_project_file.py (limited to 'data') diff --git a/data/bitmask.pro.template b/data/bitmask.pro.template new file mode 100644 index 00000000..564103a3 --- /dev/null +++ b/data/bitmask.pro.template @@ -0,0 +1,9 @@ +{header} + +SOURCES += {sources} + +FORMS += {forms} + +# where to generate ts files -- tx will pick from here +# original file, english +TRANSLATIONS += ts/en_US.ts diff --git a/data/make_project_file.py b/data/make_project_file.py new file mode 100755 index 00000000..d1567837 --- /dev/null +++ b/data/make_project_file.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +# encoding: utf-8 + +import fnmatch +import os +import os.path +import re + + +# thanks to http://stackoverflow.com/a/5141829/687989 +def list_files(includes, excludes, start='.'): + """ + Returns a list of files matching the glob expressions of the included + parameter and excluding the files and directories matching the parameter + excludes. + + :param includes: the files to match, using glob's format. + :type includes: list of str + :param excludes: the files and directories to exclude, using glob's format. + :type excludes: list of str + """ + # transform glob patterns to regular expressions + includes = r'|'.join([fnmatch.translate(x) for x in includes]) + excludes = r'|'.join([fnmatch.translate(x) for x in excludes]) or r'$.' + + files_list = [] + + for root, dirs, files in os.walk(start): + # exclude dirs + if excludes: + dirs[:] = [d for d in dirs if not re.match(excludes, d)] + + # exclude/include files + if excludes: + files = [f for f in files if not re.match(excludes, f)] + files = [f for f in files if re.match(includes, f)] + files = [os.path.join(root, f) for f in files] + + for fname in files: + files_list.append(fname) + + return files_list + + +if __name__ == '__main__': + SOURCE_ROOT = 'src' + TEMPLATE = 'data/bitmask.pro.template' + PROJECT = 'data/bitmask.pro' + + HEADER = ("# DO NOT EDIT MANUALLY.\n" + "# qmake file generated by script, any changes will be lost.") + + # Source files + includes = ["*.py"] + excludes = ['__init__.py', '_version.py', 'ui_*.py', '*_rc.py'] + sources = list_files(includes, excludes, SOURCE_ROOT) + sources = " \\\n".join(["../{0}".format(f) for f in sources]) + + # Form files + includes = ["*.ui"] + excludes = [] + forms = list_files(includes, excludes, SOURCE_ROOT) + forms = " \\\n".join(["../{0}".format(f) for f in forms]) + + # Load template and write project + template = file(TEMPLATE).read() + project = template.format(header=HEADER, sources=sources, forms=forms) + + try: + with open(PROJECT, 'w') as output: + output.write(project) + print "Project file generated successfully" + except IOError, e: + print "Error saving project file: {0}".format(e) -- cgit v1.2.3