summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-10-17 11:27:49 -0300
committerTomás Touceda <chiiph@leap.se>2013-10-17 11:27:49 -0300
commit9f7506cd11f6b2625f57d1effd988271e898bf05 (patch)
tree1a9ab8c518f1d71cc87ab1800649ffd9a62ac8d6
parent0c2567096393f9a8fa86e0e7d8460ccca15756d7 (diff)
parenta057c79a7954be6b6d78e02e009e2d717010a8b7 (diff)
Merge remote-tracking branch 'ivan/feature/3925_automate-i18n' into develop
-rw-r--r--.gitignore2
-rw-r--r--Makefile1
-rw-r--r--changes/feature-3925_automate-i18n2
-rw-r--r--data/bitmask.pro63
-rw-r--r--data/bitmask.pro.template9
-rwxr-xr-xdata/make_project_file.py74
-rw-r--r--docs/dev/internationalization.rst13
7 files changed, 95 insertions, 69 deletions
diff --git a/.gitignore b/.gitignore
index ecec4091..579d3541 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,3 +29,5 @@ MANIFEST
_trial_temp*
config/*
CHANGELOG~
+
+data/bitmask.pro
diff --git a/Makefile b/Makefile
index 766544f4..1b4eed5d 100644
--- a/Makefile
+++ b/Makefile
@@ -48,6 +48,7 @@ resources : $(COMPILED_RESOURCES)
ui : $(COMPILED_UI)
translations:
+ data/make_project_file.py
$(PYLUP) $(PROJFILE)
$(LRELE) $(TRANSLAT_DIR)/*.ts
diff --git a/changes/feature-3925_automate-i18n b/changes/feature-3925_automate-i18n
new file mode 100644
index 00000000..60f31813
--- /dev/null
+++ b/changes/feature-3925_automate-i18n
@@ -0,0 +1,2 @@
+ o Automate internationalization process, create project file dynamically on
+ make. Closes #3925.
diff --git a/data/bitmask.pro b/data/bitmask.pro
deleted file mode 100644
index b9b5dc84..00000000
--- a/data/bitmask.pro
+++ /dev/null
@@ -1,63 +0,0 @@
-# qmake file
-
-# is not there a f*** way of expanding this? other to template with python I mean...
-
-# to get a list of python files we can use:
-# find . -iname "*.py" | grep -Ev "__init__.py|/build/|/docs/|/gui/ui_[a-z]*.py|/gui/[a-z]*_rc.py|./.venv/|/tests/"
-# and remove by hand the few files that we do not want.
-
-SOURCES += ../src/leap/bitmask/app.py \
- ../src/leap/bitmask/config/leapsettings.py \
- ../src/leap/bitmask/config/providerconfig.py \
- ../src/leap/bitmask/crypto/srpauth.py \
- ../src/leap/bitmask/crypto/srpregister.py \
- ../src/leap/bitmask/gui/loggerwindow.py \
- ../src/leap/bitmask/gui/login.py \
- ../src/leap/bitmask/gui/mainwindow.py \
- ../src/leap/bitmask/gui/twisted_main.py \
- ../src/leap/bitmask/gui/wizardpage.py \
- ../src/leap/bitmask/gui/wizard.py \
- ../src/leap/bitmask/gui/eip_status.py \
- ../src/leap/bitmask/gui/mail_status.py \
- ../src/leap/bitmask/gui/eip_preferenceswindow.py \
- ../src/leap/bitmask/gui/preferenceswindow.py \
- ../src/leap/bitmask/platform_init/initializers.py \
- ../src/leap/bitmask/platform_init/locks.py \
- ../src/leap/bitmask/provider/supportedapis.py \
- ../src/leap/bitmask/services/abstractbootstrapper.py \
- ../src/leap/bitmask/services/eip/eipbootstrapper.py \
- ../src/leap/bitmask/services/eip/eipconfig.py \
- ../src/leap/bitmask/provider/providerbootstrapper.py \
- ../src/leap/bitmask/services/__init__.py \
- ../src/leap/bitmask/services/connections.py \
- ../src/leap/bitmask/services/eip/udstelnet.py \
- ../src/leap/bitmask/services/eip/vpnlauncher.py \
- ../src/leap/bitmask/services/eip/vpnprocess.py \
- ../src/leap/bitmask/services/mail/smtpbootstrapper.py \
- ../src/leap/bitmask/services/mail/smtpconfig.py \
- ../src/leap/bitmask/services/soledad/soledadbootstrapper.py \
- ../src/leap/bitmask/services/soledad/soledadconfig.py \
- ../src/leap/bitmask/services/tx.py \
- ../src/leap/bitmask/util/constants.py \
- ../src/leap/bitmask/util/keyring_helpers.py \
- ../src/leap/bitmask/util/leap_argparse.py \
- ../src/leap/bitmask/util/leap_log_handler.py \
- ../src/leap/bitmask/util/privilege_policies.py \
- ../src/leap/bitmask/util/pyside_tests_helper.py \
- ../src/leap/bitmask/util/request_helpers.py \
- ../src/leap/bitmask/util/requirement_checker.py
-
-FORMS += ../src/leap/bitmask/gui/ui/loggerwindow.ui \
- ../src/leap/bitmask/gui/ui/login.ui \
- ../src/leap/bitmask/gui/ui/mainwindow.ui \
- ../src/leap/bitmask/gui/ui/wizard.ui \
- ../src/leap/bitmask/gui/ui/eip_status.ui \
- ../src/leap/bitmask/gui/ui/mail_status.ui \
- ../src/leap/bitmask/gui/ui/eippreferences.ui \
- ../src/leap/bitmask/gui/ui/preferences.ui \
-
-# where to generate ts files -- tx will pick from here
-
-# original file, english
-
-TRANSLATIONS += ts/en_US.ts
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)
diff --git a/docs/dev/internationalization.rst b/docs/dev/internationalization.rst
index f9f522b9..c0f208de 100644
--- a/docs/dev/internationalization.rst
+++ b/docs/dev/internationalization.rst
@@ -65,19 +65,20 @@ If you do not already have it, install the ``transifex-client`` from the cheese
You can learn more about the transifex-client `here <http://help.transifex.com/features/client/index.html>`_.
-**1.** Add any new source files to the project file, ``data/bitmask.pro``. *We should automate this with some templating, it's tedious.*
-
-**2.** Update the source .ts file ``data/ts/en_US.ts``.::
+**1.** Update the source .ts file ``data/ts/en_US.ts``.::
$ make translations
-**3.** Push source .ts file to transifex::
+It automatically adds any new source files and forms to the project file, ``data/bitmask.pro``.
+If there is a file to be ignored in the translations you need to edit the ``data/make_project_file.py`` to set the excludes.
+
+**2.** Push source .ts file to transifex::
$ tx push -s
-**4.** Let the translation fairies do their work...
+**3.** Let the translation fairies do their work...
-**5.** *Et voila!* Get updated .ts files for each language from ``Transifex``. For instance, to pull updated spanish translations::
+**4.** *Et voila!* Get updated .ts files for each language from ``Transifex``. For instance, to pull updated spanish translations::
$ tx pull -l es
Pulling new translations for resource bitmask.bitmask (source: data/ts/en_US.ts)