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 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 From 967862447961ad8e39f6d4a37649a549c61032a0 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 16 Oct 2013 12:52:40 -0300 Subject: Ignore dynamically generated file. --- .gitignore | 2 ++ data/bitmask.pro | 63 -------------------------------------------------------- 2 files changed, 2 insertions(+), 63 deletions(-) delete mode 100644 data/bitmask.pro 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/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 -- cgit v1.2.3 From ae030cbe4dbb861f67e321255a61790d05526b31 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 16 Oct 2013 13:40:24 -0300 Subject: Add project file generation to `make translations` --- Makefile | 1 + 1 file changed, 1 insertion(+) 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 -- cgit v1.2.3 From b2ba0758fe98de3ae5e8a47b9ef36dcbe321d2dc Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 16 Oct 2013 13:49:22 -0300 Subject: Update docs for internationalization. --- docs/dev/internationalization.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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 `_. -**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) -- cgit v1.2.3 From a057c79a7954be6b6d78e02e009e2d717010a8b7 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 16 Oct 2013 13:56:06 -0300 Subject: Add changes file for #3925. --- changes/feature-3925_automate-i18n | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changes/feature-3925_automate-i18n 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. -- cgit v1.2.3