summaryrefslogtreecommitdiff
path: root/data/make_project_file.py
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-10-18 09:34:47 -0300
committerTomás Touceda <chiiph@leap.se>2013-10-18 09:34:47 -0300
commita06b5719f028e619a4b3800fb346ed3c984e4d25 (patch)
treeb177a28201d647731797efb25c19fd9b3a311c9a /data/make_project_file.py
parent932dcf596177b93c0b0f9e876be74be314fb6037 (diff)
parentf673b84a9a9b0fea3f6bbfefbb38cbd3d311cf3c (diff)
Merge branch 'release-0.3.5'
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)