i18n/mki18n.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 15 Sep 2017 19:01:31 +0300
changeset 1807 5562f34f2fc2
parent 1758 845ca626db09
child 1826 91796f408540
permissions -rwxr-xr-x
lazy initialization of highlight pens and brushes for DebugVariableViewer

Constructors wx.Pen() and wx.Brush() require wx.App to exist already.
That causes crash during import of the control,
because import is done before calling main application code.
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
#
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    81
import os
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    82
import sys
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    83
import wx
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    84
import re
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    85
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
# Global variables
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    88
# ----------------
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
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1757
diff changeset
    91
__author__ = "Pierre Rouleau"
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
    92
__version__ = "$Revision: 1.5 $"
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    93
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
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    96
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    97
def getlanguageDict():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    98
    languageDict = {}
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
    99
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   100
    if wx.VERSION >= (3, 0, 0):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   101
        app = wx.App()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   102
    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   103
        app = wx.PySimpleApp()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   104
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   105
    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
   106
        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
   107
        if i:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   108
            languageDict[i.CanonicalName] = i.Description
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   109
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   110
    return languageDict
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   111
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   112
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   113
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
   114
    if verbose:
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   115
        print str
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   116
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   117
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   118
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
   119
    appfil_file = open(filein, 'r')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   120
    messages_file = open(fileout, 'r')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   121
    messages = messages_file.read()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   122
    messages_file.close()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   123
    messages_file = open(fileout, 'a')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   124
    messages_file.write('\n')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   125
    messages_file.write('#: %s\n' % prefix)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   126
    messages_file.write('\n')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   127
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   128
    words_found = {}
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   129
    for filepath in appfil_file.xreadlines():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   130
        code_file = open(filepath.strip(), 'r')
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   131
        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
   132
            word = match.group(1)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   133
            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
   134
                words_found[word] = True
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   135
                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
   136
                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
   137
                messages_file.write("msgstr \"\"\n")
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   138
        code_file.close()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   139
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   140
    messages_file.close()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   141
    appfil_file.close()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   142
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
# 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
   146
# ^^^^^^^^^^^^^^^
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   147
#
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   148
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
   149
    """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
   150
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   151
    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
   152
    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
   153
    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
   154
    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
   155
    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
   156
    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
   157
    'applicationDomain' argument.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   158
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   159
    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
   160
    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
   161
    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
   162
    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
   163
    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
   164
    .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
   165
    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
   166
    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
   167
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   168
    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
   169
    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
   170
    """
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
    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
   173
        applicationName = fileBaseOf(applicationDirectoryPath, withPath=0)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   174
    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   175
        applicationName = applicationDomain
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   176
    currentDir = os.getcwd()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   177
    os.chdir(applicationDirectoryPath)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   178
    filelist = 'app.fil'
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   179
    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
   180
        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
   181
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   182
    fileout = 'messages.pot'
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   183
    # Steps:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   184
    #  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
   185
    #  The following switches are used:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   186
    #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   187
    #   -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
   188
    #   --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
   189
    #   --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
   190
    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
   191
    verbosePrint(verbose, cmd)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   192
    os.system(cmd)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   193
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   194
    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
   195
    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
   196
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   197
    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
   198
    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
   199
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   200
    # generate messages.po
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   201
    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
   202
    verbosePrint(verbose, cmd)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   203
    os.system(cmd)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   204
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   205
    languageDict = getlanguageDict()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   206
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   207
    for langCode in languageDict.keys():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   208
        if langCode == 'en':
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   209
            pass
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   210
        else:
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   211
            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
   212
            if os.path.exists(langPOfileName):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   213
                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
   214
                verbosePrint(verbose, cmd)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   215
                os.system(cmd)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   216
    os.chdir(currentDir)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   217
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   218
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   219
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
   220
    """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
   221
    """
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
    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
   224
        applicationName = fileBaseOf(applicationDirectoryPath, withPath=0)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   225
    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   226
        applicationName = applicationDomain
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   227
    currentDir = os.getcwd()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   228
    os.chdir(applicationDirectoryPath)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   229
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   230
    languageDict = getlanguageDict()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   231
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   232
    for langCode in languageDict.keys():
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   233
        if langCode == 'en':
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   234
            pass
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   235
        else:
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   236
            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
   237
            if os.path.exists(langPOfileName):
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   238
                fileList = ''
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   239
                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
   240
                    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
   241
                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
   242
                verbosePrint(verbose, cmd)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   243
                os.system(cmd)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   244
                if targetDir is None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   245
                    pass
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   246
                else:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   247
                    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
   248
                    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
   249
                    verbosePrint(verbose, cmd)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   250
                    os.system(cmd)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   251
    os.chdir(currentDir)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   252
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   253
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   254
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
   255
    """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
   256
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   257
    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
   258
    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
   259
    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
   260
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   261
    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
   262
    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
   263
    '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
   264
    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
   265
    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
   266
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   267
    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
   268
    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
   269
    code.
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   270
    """
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   271
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   272
    if targetDir is None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   273
        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
   274
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   275
    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
   276
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   277
    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
   278
        applicationName = fileBaseOf(applicationDirectoryPath, withPath=0)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   279
    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   280
        applicationName = applicationDomain
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   281
    currentDir = os.getcwd()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   282
    os.chdir(applicationDirectoryPath)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   283
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   284
    languageDict = getlanguageDict()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   285
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   286
    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
   287
        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
   288
            pass
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   289
        else:
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   290
            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
   291
            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
   292
                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
   293
                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
   294
                    mkdir(mo_targetDir)
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   295
                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
   296
                verbosePrint(verbose, cmd)
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   297
                os.system(cmd)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   298
    os.chdir(currentDir)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   299
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   300
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   301
def printUsage(errorMsg=None):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   302
    """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
   303
    print """
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   304
    ##################################################################################
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   305
    #   mki18n :   Make internationalization files.                                  #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   306
    #              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
   307
    #              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
   308
    #              Supports C,C++,Python source files.                               #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   309
    #                                                                                #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   310
    #   Usage: mki18n {OPTION} [appDirPath]                                          #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   311
    #                                                                                #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   312
    #   Options:                                                                     #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   313
    #     -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
   314
    #     -h               : prints this help                                        #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   315
    #     -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
   316
    #     -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
   317
    #                        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
   318
    #                        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
   319
    #                        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
   320
    #                        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
   321
    #                        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
   322
    #                        source code to parse.                                   #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   323
    #     -v               : verbose (prints comments while running)                 #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   324
    #     --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
   325
    #                        the directory name is used.                             #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   326
    #     --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
   327
    #                      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
   328
    #                                                                                #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   329
    #   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
   330
    #   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
   331
    #   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
   332
    #                                                                                #
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   333
    ##################################################################################"""
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   334
    if errorMsg:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   335
        print "\n   ERROR: %s" % errorMsg
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   336
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   337
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   338
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
   339
    """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
   340
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   341
    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
   342
    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
   343
    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
   344
    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
   345
    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
   346
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   347
    [Example]
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   348
    >>> 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
   349
    >>> 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
   350
    'test'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   351
    >>> 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
   352
    'test'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   353
    >>> 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
   354
    '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
   355
    >>> 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
   356
    'test'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   357
    >>> 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
   358
    >>> 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
   359
    'abcdef'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   360
    >>> 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
   361
    'abcdef'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   362
    >>> 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
   363
    >>> 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
   364
    'abcdef'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   365
    >>> 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
   366
    'abcdef'
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   367
    """
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   368
    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
   369
    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
   370
        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
   371
    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
   372
        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
   373
    else:
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   374
        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
   375
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   376
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   377
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
   378
    """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
   379
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   380
    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
   381
    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
   382
    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
   383
    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
   384
    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
   385
    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
   386
    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
   387
    """
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
    # 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
   390
    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
   391
    # 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
   392
    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
   393
    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
   394
    # 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
   395
    # 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
   396
    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
   397
        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
   398
            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
   399
            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
   400
            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
   401
    # 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
   402
    # 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
   403
    # 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
   404
    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
   405
        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
   406
    # 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
   407
    # 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
   408
    theDir = ''
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   409
    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
   410
        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
   411
        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
   412
            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
   413
        theDir += '/'
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   414
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
   415
1739
ec153828ded2 clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1738
diff changeset
   416
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
   417
    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
   418
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   419
    [Example]
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   420
    >>> 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
   421
    '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
    >>> 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
   423
    '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
    >>>
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
    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
   427
    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
   428
        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
   429
    else:
0de89da92ee0 clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   430
        return thePath.replace(os.sep, '/')
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   431
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
   432
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   433
# -----------------------------------------------------------------------------
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
# 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
   436
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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
if __name__ == "__main__":
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   439
    import getopt     # command line parsing
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   440
    argc = len(sys.argv)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   441
    if argc == 1:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   442
        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
   443
        sys.exit(1)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   444
    # 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
   445
    validOptions = "ehmpv"
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   446
    validLongOptions = ['domain=', 'moTarget=']
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   447
    option = {}
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   448
    option['forceEnglish'] = 0
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   449
    option['mo'] = 0
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   450
    option['po'] = 0
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   451
    option['verbose'] = 0
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   452
    option['domain'] = None
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   453
    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
   454
    optionKey = {
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   455
        '-e':         'forceEnglish',
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   456
        '-m':         'mo',
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   457
        '-p':         'po',
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   458
        '-v':         'verbose',
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   459
        '--domain':   'domain',
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   460
        '--moTarget': 'moTarget',
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   461
    }
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1754
diff changeset
   462
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   463
    try:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   464
        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
   465
    except getopt.GetoptError, e:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   466
        printUsage(e[0])
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   467
        sys.exit(1)
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   468
    for (opt, val) in optionList:
1738
d2e979738700 clean-up: fix PEP8 E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
   469
        if (opt == '-h'):
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   470
            printUsage()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   471
            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
   472
        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
   473
    if len(pargs) == 0:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   474
        appDirPath = os.getcwd()
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   475
        if option['verbose']:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   476
            print "No project directory given. Using current one:  %s" % appDirPath
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   477
    elif len(pargs) == 1:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   478
        appDirPath = pargs[0]
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   479
    else:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   480
        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
   481
        sys.exit(1)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   482
    if option['domain'] is None:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   483
        # 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
   484
        option['domain'] = fileBaseOf(appDirPath)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   485
    if option['verbose']:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   486
        print "Application domain used is: '%s'" % option['domain']
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   487
    if option['po']:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   488
        try:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   489
            makePO(appDirPath, option['domain'], option['verbose'])
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   490
        except IOError, e:
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   491
            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
   492
    if option['mo']:
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   493
        makeMO(appDirPath, option['moTarget'], option['domain'], option['verbose'], option['forceEnglish'])
1731
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   494
    sys.exit(1)
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   495
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   496
6ebd9c40b2be convert some files from CRLF to LF
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   497
# -----------------------------------------------------------------------------