summaryrefslogtreecommitdiff
path: root/data/make_project_file.py
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2013-10-16 12:49:44 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2013-10-17 11:25:58 -0300
commit048648c9f71a37bf4e5f1c58d05bfc285eede465 (patch)
tree32cfb7b1a626b417fd5871fbb2e425b498c54e36 /data/make_project_file.py
parent36c36bc9dc9fed643245c9c96a9840f06c515ec1 (diff)
Add tool to generate project file automatically.
Diffstat (limited to 'data/make_project_file.py')
-rwxr-xr-xdata/make_project_file.py74
1 files changed, 74 insertions, 0 deletions
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)