i18n/mki18n.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Wed, 11 Oct 2017 10:34:45 +0300
changeset 1864 9e64afb38963
parent 1847 6198190bc121
child 1881 091005ec69c4
permissions -rwxr-xr-x
fix problems with unconnected input of InOut function variables and
enfoce InOut variables to be connected for functions and function blocks
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     1
#! /usr/bin/env python
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     2
# -*- coding: iso-8859-1 -*-
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     3
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     4
#   PYTHON MODULE:     MKI18N.PY
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     5
#                      =========
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     6
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     7
#   Abstract:         Make Internationalization (i18n) files for an application.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     8
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
     9
#   Copyright Pierre Rouleau. 2003. Released to public domain.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    10
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    11
#   Last update: Saturday, November 8, 2003. @ 15:55:18.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    12
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    13
#   File: ROUP2003N01::C:/dev/python/mki18n.py
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    14
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    15
#   RCS $Header: //software/official/MKS/MKS_SI/TV_NT/dev/Python/rcs/mki18n.py 1.5 2003/11/05 19:40:04 PRouleau Exp $
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    16
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    17
#   Update history:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    18
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    19
#   - File created: Saturday, June 7, 2003. by Pierre Rouleau
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    20
#   - 10/06/03 rcs : RCS Revision 1.1  2003/06/10 10:06:12  PRouleau
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    21
#   - 10/06/03 rcs : RCS Initial revision
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    22
#   - 23/08/03 rcs : RCS Revision 1.2  2003/06/10 10:54:27  PRouleau
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    23
#   - 23/08/03 P.R.: [code:fix] : The strings encoded in this file are encode in iso-8859-1 format.  Added the encoding
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    24
#                    notification to Python to comply with Python's 2.3 PEP 263.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    25
#   - 23/08/03 P.R.: [feature:new] : Added the '-e' switch which is used to force the creation of the empty English .mo file.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    26
#   - 22/10/03 P.R.: [code] : incorporated utility functions in here to make script self sufficient.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    27
#   - 05/11/03 rcs : RCS Revision 1.4  2003/10/22 06:39:31  PRouleau
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    28
#   - 05/11/03 P.R.: [code:fix] : included the unixpath() in this file.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    29
#   - 08/11/03 rcs : RCS Revision 1.5  2003/11/05 19:40:04  PRouleau
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    30
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    31
#   RCS $Log: $
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    32
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    33
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    34
# -----------------------------------------------------------------------------
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    35
"""
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    36
mki18n allows you to internationalize your software.  You can use it to
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    37
create the GNU .po files (Portable Object) and the compiled .mo files
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    38
(Machine Object).
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    39
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    40
mki18n module can be used from the command line or from within a script (see
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    41
the Usage at the end of this page).
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    42
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    43
    Table of Contents
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    44
    -----------------
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    45
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    46
    makePO()             -- Build the Portable Object file for the application --
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    47
    catPO()              -- Concatenate one or several PO files with the application domain files. --
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    48
    makeMO()             -- Compile the Portable Object files into the Machine Object stored in the right location. --
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    49
    printUsage           -- Displays how to use this script from the command line --
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    50
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    51
    Scriptexecution      -- Runs when invoked from the command line --
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    52
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    53
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    54
NOTE:  this module uses GNU gettext utilities.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    55
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    56
You can get the gettext tools from the following sites:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    57
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    58
   - `GNU FTP site for gettetx`_ where several versions (0.10.40, 0.11.2, 0.11.5 and 0.12.1) are available.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    59
     Note  that you need to use `GNU libiconv`_ to use this. Get it from the `GNU
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    60
     libiconv  ftp site`_ and get version 1.9.1 or later. Get the Windows .ZIP
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    61
     files and install the packages inside c:/gnu. All binaries will be stored
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    62
     inside  c:/gnu/bin.  Just  put c:/gnu/bin inside your PATH. You will need
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    63
     the following files:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    64
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    65
      - `gettext-runtime-0.12.1.bin.woe32.zip`_
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    66
      - `gettext-tools-0.12.1.bin.woe32.zip`_
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    67
      - `libiconv-1.9.1.bin.woe32.zip`_
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    68
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    69
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    70
.. _GNU libiconv:                            http://www.gnu.org/software/libiconv/
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    71
.. _GNU libiconv ftp site:                   http://www.ibiblio.org/pub/gnu/libiconv/
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    72
.. _gettext-runtime-0.12.1.bin.woe32.zip:    ftp://ftp.gnu.org/gnu/gettext/gettext-runtime-0.12.1.bin.woe32.zip
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    73
.. _gettext-tools-0.12.1.bin.woe32.zip:      ftp://ftp.gnu.org/gnu/gettext/gettext-tools-0.12.1.bin.woe32.zip
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    74
.. _libiconv-1.9.1.bin.woe32.zip:            http://www.ibiblio.org/pub/gnu/libiconv/libiconv-1.9.1.bin.woe32.zip
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    75
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    76
"""
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    77
# -----------------------------------------------------------------------------
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    78
# Module Import
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    79
# -------------
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    80
#
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
    81
from __future__ import print_function
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    82
import os
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    83
import sys
1832
0f1081928d65 fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1828
diff changeset
    84
import re
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    85
import wx
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    86
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    87
# -----------------------------------------------------------------------------
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    88
# Global variables
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    89
# ----------------
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    90
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    91
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1757
diff changeset
    92
__author__ = "Pierre Rouleau"
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
    93
__version__ = "$Revision: 1.5 $"
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    94
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    95
# -----------------------------------------------------------------------------
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    96
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    97
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    98
def getlanguageDict():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    99
    languageDict = {}
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   100
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   101
    if wx.VERSION >= (3, 0, 0):
1847
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1844
diff changeset
   102
        _app = wx.App()
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1844
diff changeset
   103
    else:
6198190bc121 explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1844
diff changeset
   104
        _app = wx.PySimpleApp()
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   105
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   106
    for lang in [x for x in dir(wx) if x.startswith("LANGUAGE")]:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   107
        i = wx.Locale(wx.LANGUAGE_DEFAULT).GetLanguageInfo(getattr(wx, lang))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   108
        if i:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   109
            languageDict[i.CanonicalName] = i.Description
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   110
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   111
    return languageDict
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   112
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   113
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   114
def verbosePrint(verbose, str):
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   115
    if verbose:
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   116
        print(str)
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   117
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   118
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   119
def processCustomFiles(filein, fileout, regexp, prefix=''):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   120
    appfil_file = open(filein, 'r')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   121
    messages_file = open(fileout, 'r')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   122
    messages = messages_file.read()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   123
    messages_file.close()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   124
    messages_file = open(fileout, 'a')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   125
    messages_file.write('\n')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   126
    messages_file.write('#: %s\n' % prefix)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   127
    messages_file.write('\n')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   128
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   129
    words_found = {}
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   130
    for filepath in appfil_file.xreadlines():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   131
        code_file = open(filepath.strip(), 'r')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   132
        for match in regexp.finditer(code_file.read()):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   133
            word = match.group(1)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   134
            if not words_found.get(word, False) and messages.find("msgid \"%s\"\nmsgstr \"\"" % word) == -1:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   135
                words_found[word] = True
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   136
                messages_file.write('\n')
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1731
diff changeset
   137
                messages_file.write("msgid \"%s\"\n" % word)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   138
                messages_file.write("msgstr \"\"\n")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   139
        code_file.close()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   140
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   141
    messages_file.close()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   142
    appfil_file.close()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   143
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   144
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   145
# -----------------------------------------------------------------------------
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   146
# m a k e P O ( )         -- Build the Portable Object file for the application --
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   147
# ^^^^^^^^^^^^^^^
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   148
#
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   149
def makePO(applicationDirectoryPath,  applicationDomain=None, verbose=0):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   150
    """Build the Portable Object Template file for the application.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   151
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   152
    makePO builds the .pot file for the application stored inside
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   153
    a specified directory by running xgettext for all application source
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   154
    files.  It finds the name of all files by looking for a file called 'app.fil'.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   155
    If this file does not exists, makePo raises an IOError exception.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   156
    By default the application domain (the application
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   157
    name) is the same as the directory name but it can be overridden by the
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   158
    'applicationDomain' argument.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   159
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   160
    makePO always creates a new file called messages.pot.  If it finds files
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   161
    of the form app_xx.po where 'app' is the application name and 'xx' is one
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   162
    of the ISO 639 two-letter language codes, makePO resynchronizes those
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   163
    files with the latest extracted strings (now contained in messages.pot).
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   164
    This process updates all line location number in the language-specific
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   165
    .po files and may also create new entries for translation (or comment out
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   166
    some).  The .po file is not changed, instead a new file is created with
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   167
    the .new extension appended to the name of the .po file.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   168
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   169
    By default the function does not display what it is doing.  Set the
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   170
    verbose argument to 1 to force it to print its commands.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   171
    """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   172
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   173
    if applicationDomain is None:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   174
        applicationName = fileBaseOf(applicationDirectoryPath, withPath=0)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   175
    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   176
        applicationName = applicationDomain
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   177
    currentDir = os.getcwd()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   178
    os.chdir(applicationDirectoryPath)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   179
    filelist = 'app.fil'
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   180
    if not os.path.exists(filelist):
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   181
        raise IOError(2, 'No module file: ' % filelist)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   182
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   183
    fileout = 'messages.pot'
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   184
    # Steps:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   185
    #  Use xgettext to parse all application modules
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   186
    #  The following switches are used:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   187
    #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   188
    #   -s                          : sort output by string content (easier to use when we need to merge several .po files)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   189
    #   --files-from=app.fil        : The list of files is taken from the file: app.fil
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   190
    #   --output=                   : specifies the name of the output file (using a .pot extension)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   191
    cmd = 'xgettext -s --no-wrap --language=Python --files-from=' + filelist + ' --output=' + fileout + ' --package-name ' + applicationName
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   192
    verbosePrint(verbose, cmd)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   193
    os.system(cmd)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   194
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   195
    XSD_STRING_MODEL = re.compile("<xsd\:(?:element|attribute) name=\"([^\"]*)\"[^\>]*\>")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   196
    processCustomFiles(filelist, fileout, XSD_STRING_MODEL, 'Extra XSD strings')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   197
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   198
    XML_TC6_STRING_MODEL = re.compile("<documentation>\s*<xhtml\:p><!\[CDATA\[([^\]]*)\]\]></xhtml\:p>\s*</documentation>", re.MULTILINE | re.DOTALL)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   199
    processCustomFiles(filelist, fileout, XML_TC6_STRING_MODEL, 'Extra TC6 documentation strings')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   200
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   201
    # generate messages.po
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   202
    cmd = 'msginit --no-wrap --no-translator -i %s -l en_US.UTF-8 -o messages.po' % (fileout)
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   203
    verbosePrint(verbose, cmd)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   204
    os.system(cmd)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   205
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   206
    languageDict = getlanguageDict()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   207
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   208
    for langCode in languageDict.keys():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   209
        if langCode == 'en':
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   210
            pass
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   211
        else:
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   212
            langPOfileName = "%s_%s.po" % (applicationName, langCode)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   213
            if os.path.exists(langPOfileName):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   214
                cmd = 'msgmerge -s --no-wrap "%s" %s > "%s.new"' % (langPOfileName, fileout, langPOfileName)
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   215
                verbosePrint(verbose, cmd)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   216
                os.system(cmd)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   217
    os.chdir(currentDir)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   218
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   219
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   220
def catPO(applicationDirectoryPath, listOf_extraPo, applicationDomain=None, targetDir=None, verbose=0):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   221
    """Concatenate one or several PO files with the application domain files.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   222
    """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   223
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   224
    if applicationDomain is None:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   225
        applicationName = fileBaseOf(applicationDirectoryPath, withPath=0)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   226
    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   227
        applicationName = applicationDomain
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   228
    currentDir = os.getcwd()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   229
    os.chdir(applicationDirectoryPath)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   230
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   231
    languageDict = getlanguageDict()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   232
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   233
    for langCode in languageDict.keys():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   234
        if langCode == 'en':
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   235
            pass
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   236
        else:
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   237
            langPOfileName = "%s_%s.po" % (applicationName, langCode)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   238
            if os.path.exists(langPOfileName):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   239
                fileList = ''
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   240
                for fileName in listOf_extraPo:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   241
                    fileList += ("%s_%s.po " % (fileName, langCode))
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   242
                cmd = "msgcat -s --no-wrap %s %s > %s.cat" % (langPOfileName, fileList, langPOfileName)
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   243
                verbosePrint(verbose, cmd)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   244
                os.system(cmd)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   245
                if targetDir is None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   246
                    pass
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   247
                else:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   248
                    mo_targetDir = "%s/%s/LC_MESSAGES" % (targetDir, langCode)
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   249
                    cmd = "msgfmt --output-file=%s/%s.mo %s_%s.po.cat" % (mo_targetDir, applicationName, applicationName, langCode)
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   250
                    verbosePrint(verbose, cmd)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   251
                    os.system(cmd)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   252
    os.chdir(currentDir)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   253
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   254
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   255
def makeMO(applicationDirectoryPath, targetDir='./locale', applicationDomain=None, verbose=0, forceEnglish=0):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   256
    """Compile the Portable Object files into the Machine Object stored in the right location.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   257
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   258
    makeMO converts all translated language-specific PO files located inside
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   259
    the  application directory into the binary .MO files stored inside the
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   260
    LC_MESSAGES sub-directory for the found locale files.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   261
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   262
    makeMO searches for all files that have a name of the form 'app_xx.po'
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   263
    inside the application directory specified by the first argument.  The
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   264
    'app' is the application domain name (that can be specified by the
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   265
    applicationDomain argument or is taken from the directory name). The 'xx'
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   266
    corresponds to one of the ISO 639 two-letter language codes.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   267
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   268
    makeMo stores the resulting files inside a sub-directory of `targetDir`
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   269
    called xx/LC_MESSAGES where 'xx' corresponds to the 2-letter language
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   270
    code.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   271
    """
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   272
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   273
    if targetDir is None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   274
        targetDir = './locale'
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   275
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   276
    verbosePrint(verbose, "Target directory for .mo files is: %s" % targetDir)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   277
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   278
    if applicationDomain is None:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   279
        applicationName = fileBaseOf(applicationDirectoryPath, withPath=0)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   280
    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   281
        applicationName = applicationDomain
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   282
    currentDir = os.getcwd()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   283
    os.chdir(applicationDirectoryPath)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   284
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   285
    languageDict = getlanguageDict()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   286
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   287
    for langCode in languageDict.keys():
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   288
        if (langCode == 'en') and (forceEnglish == 0):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   289
            pass
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   290
        else:
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   291
            langPOfileName = "%s_%s.po" % (applicationName, langCode)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   292
            if os.path.exists(langPOfileName):
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   293
                mo_targetDir = "%s/%s/LC_MESSAGES" % (targetDir, langCode)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   294
                if not os.path.exists(mo_targetDir):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   295
                    mkdir(mo_targetDir)
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   296
                cmd = 'msgfmt --output-file="%s/%s.mo" "%s_%s.po"' % (mo_targetDir, applicationName, applicationName, langCode)
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   297
                verbosePrint(verbose, cmd)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   298
                os.system(cmd)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   299
    os.chdir(currentDir)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   300
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   301
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   302
def printUsage(errorMsg=None):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   303
    """Displays how to use this script from the command line."""
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   304
    print("""
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   305
    ##################################################################################
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   306
    #   mki18n :   Make internationalization files.                                  #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   307
    #              Uses the GNU gettext system to create PO (Portable Object) files  #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   308
    #              from source code, coimpile PO into MO (Machine Object) files.     #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   309
    #              Supports C,C++,Python source files.                               #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   310
    #                                                                                #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   311
    #   Usage: mki18n {OPTION} [appDirPath]                                          #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   312
    #                                                                                #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   313
    #   Options:                                                                     #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   314
    #     -e               : When -m is used, forces English .mo file creation       #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   315
    #     -h               : prints this help                                        #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   316
    #     -m               : make MO from existing PO files                          #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   317
    #     -p               : make PO, update PO files: Creates a new messages.pot    #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   318
    #                        file. Creates a dom_xx.po.new for every existing        #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   319
    #                        language specific .po file. ('xx' stands for the ISO639 #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   320
    #                        two-letter language code and 'dom' stands for the       #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   321
    #                        application domain name).  mki18n requires that you     #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   322
    #                        write a 'app.fil' file  which contains the list of all  #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   323
    #                        source code to parse.                                   #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   324
    #     -v               : verbose (prints comments while running)                 #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   325
    #     --domain=appName : specifies the application domain name.  By default      #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   326
    #                        the directory name is used.                             #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   327
    #     --moTarget=dir : specifies the directory where .mo files are stored.       #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   328
    #                      If not specified, the target is './locale'                #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   329
    #                                                                                #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   330
    #   You must specify one of the -p or -m option to perform the work.  You can    #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   331
    #   specify the path of the target application.  If you leave it out mki18n      #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   332
    #   will use the current directory as the application main directory.            #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   333
    #                                                                                #
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   334
    ##################################################################################""")
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   335
    if errorMsg:
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   336
        print("\n   ERROR: %s" % errorMsg)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   337
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   338
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   339
def fileBaseOf(filename, withPath=0):
1757
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   340
    """fileBaseOf(filename,withPath) ---> string
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   341
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   342
    Return base name of filename.  The returned string never includes the extension.
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   343
    Use os.path.basename() to return the basename with the extension.  The
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   344
    second argument is optional.  If specified and if set to 'true' (non zero)
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   345
    the string returned contains the full path of the file name.  Otherwise the
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   346
    path is excluded.
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   347
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   348
    [Example]
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   349
    >>> fn = 'd:/dev/telepath/tvapp/code/test.html'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   350
    >>> fileBaseOf(fn)
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   351
    'test'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   352
    >>> fileBaseOf(fn)
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   353
    'test'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   354
    >>> fileBaseOf(fn,1)
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   355
    'd:/dev/telepath/tvapp/code/test'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   356
    >>> fileBaseOf(fn,0)
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   357
    'test'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   358
    >>> fn = 'abcdef'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   359
    >>> fileBaseOf(fn)
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   360
    'abcdef'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   361
    >>> fileBaseOf(fn,1)
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   362
    'abcdef'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   363
    >>> fn = "abcdef."
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   364
    >>> fileBaseOf(fn)
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   365
    'abcdef'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   366
    >>> fileBaseOf(fn,1)
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   367
    'abcdef'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   368
    """
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   369
    pos = filename.rfind('.')
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   370
    if pos > 0:
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   371
        filename = filename[:pos]
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   372
    if withPath:
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   373
        return filename
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   374
    else:
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   375
        return os.path.basename(filename)
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   376
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   377
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   378
def mkdir(directory):
1757
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   379
    """Create a directory (and possibly the entire tree).
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   380
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   381
    The os.mkdir() will fail to create a directory if one of the
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   382
    directory in the specified path does not exist.  mkdir()
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   383
    solves this problem.  It creates every intermediate directory
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   384
    required to create the final path. Under Unix, the function
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   385
    only supports forward slash separator, but under Windows and MacOS
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   386
    the function supports the forward slash and the OS separator (backslash
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   387
    under windows).
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   388
    """
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   389
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   390
    # translate the path separators
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   391
    directory = unixpath(directory)
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   392
    # build a list of all directory elements
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   393
    aList = filter(lambda x: len(x) > 0, directory.split('/'))
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   394
    theLen = len(aList)
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   395
    # if the first element is a Windows-style disk drive
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   396
    # concatenate it with the first directory
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   397
    if aList[0].endswith(':'):
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   398
        if theLen > 1:
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   399
            aList[1] = aList[0] + '/' + aList[1]
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   400
            del aList[0]
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   401
            theLen -= 1
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   402
    # if the original directory starts at root,
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   403
    # make sure the first element of the list
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   404
    # starts at root too
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   405
    if directory[0] == '/':
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   406
        aList[0] = '/' + aList[0]
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   407
    # Now iterate through the list, check if the
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   408
    # directory exists and if not create it
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   409
    theDir = ''
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   410
    for i in range(theLen):
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   411
        theDir += aList[i]
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   412
        if not os.path.exists(theDir):
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   413
            os.mkdir(theDir)
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   414
        theDir += '/'
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   415
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   416
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   417
def unixpath(thePath):
1757
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   418
    r"""Return a path name that contains Unix separator.
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   419
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   420
    [Example]
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   421
    >>> unixpath(r"d:\test")
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   422
    'd:/test'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   423
    >>> unixpath("d:/test/file.txt")
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   424
    'd:/test/file.txt'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   425
    >>>
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   426
    """
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   427
    thePath = os.path.normpath(thePath)
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   428
    if os.sep == '/':
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   429
        return thePath
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   430
    else:
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   431
        return thePath.replace(os.sep, '/')
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   432
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   433
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   434
# -----------------------------------------------------------------------------
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   435
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   436
# S c r i p t   e x e c u t i o n               -- Runs when invoked from the command line --
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   437
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   438
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   439
if __name__ == "__main__":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   440
    import getopt     # command line parsing
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   441
    argc = len(sys.argv)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   442
    if argc == 1:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   443
        printUsage('Missing argument: specify at least one of -m or -p (or both).')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   444
        sys.exit(1)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   445
    # If there is some arguments, parse the command line
1754
63f4af6bf6d9 clean-up: fix most PEP8 E221 multiple spaces before operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   446
    validOptions = "ehmpv"
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   447
    validLongOptions = ['domain=', 'moTarget=']
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   448
    option = {}
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   449
    option['forceEnglish'] = 0
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   450
    option['mo'] = 0
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   451
    option['po'] = 0
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   452
    option['verbose'] = 0
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   453
    option['domain'] = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   454
    option['moTarget'] = None
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   455
    optionKey = {
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   456
        '-e':         'forceEnglish',
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   457
        '-m':         'mo',
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   458
        '-p':         'po',
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   459
        '-v':         'verbose',
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   460
        '--domain':   'domain',
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   461
        '--moTarget': 'moTarget',
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   462
    }
1844
b126c2f61bb6 make mki18n return 0 on success
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
   463
    exit_code = 1
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   464
    try:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   465
        optionList, pargs = getopt.getopt(sys.argv[1:], validOptions, validLongOptions)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   466
    except getopt.GetoptError, e:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   467
        printUsage(e[0])
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   468
        sys.exit(1)
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   469
    for (opt, val) in optionList:
1828
396da88d7b5c fix unnecessary parens after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1826
diff changeset
   470
        if opt == '-h':
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   471
            printUsage()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   472
            sys.exit(0)
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   473
        option[optionKey[opt]] = 1 if val == '' else val
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   474
    if len(pargs) == 0:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   475
        appDirPath = os.getcwd()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   476
        if option['verbose']:
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   477
            print("No project directory given. Using current one:  %s" % appDirPath)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   478
    elif len(pargs) == 1:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   479
        appDirPath = pargs[0]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   480
    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   481
        printUsage('Too many arguments (%u).  Use double quotes if you have space in directory name' % len(pargs))
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   482
        sys.exit(1)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   483
    if option['domain'] is None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   484
        # If no domain specified, use the name of the target directory
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   485
        option['domain'] = fileBaseOf(appDirPath)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   486
    if option['verbose']:
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   487
        print("Application domain used is: '%s'" % option['domain'])
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   488
    if option['po']:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   489
        try:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   490
            makePO(appDirPath, option['domain'], option['verbose'])
1844
b126c2f61bb6 make mki18n return 0 on success
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
   491
            exit_code = 0
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   492
        except IOError, e:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   493
            printUsage(e[1] + '\n   You must write a file app.fil that contains the list of all files to parse.')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   494
    if option['mo']:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   495
        makeMO(appDirPath, option['moTarget'], option['domain'], option['verbose'], option['forceEnglish'])
1844
b126c2f61bb6 make mki18n return 0 on success
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
   496
        exit_code = 0
b126c2f61bb6 make mki18n return 0 on success
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
   497
    sys.exit(exit_code)
b126c2f61bb6 make mki18n return 0 on success
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
   498
b126c2f61bb6 make mki18n return 0 on success
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
   499
b126c2f61bb6 make mki18n return 0 on success
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1832
diff changeset
   500
# -----------------------------------------------------------------------------