util/TranslationCatalogs.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 28 Apr 2016 12:58:58 +0300
changeset 1506 b9b8978dbc9d
parent 817 1a3cc2065216
child 1511 91538d0c242c
permissions -rw-r--r--
Fix error about missing attribute 'timeout' that happens sometimes during compilation

The fix [1476:49f1763a5613] of the problem with following trace was wrong.
Traceback (most recent call last):
File "./Beremiz.py", line 1229, in run_with_except_hook
run_old(*args, **kw)
File
"/home/developer/WorkData/PLC/beremiz/beremiz/util/ProcessLogger.py",
line 68, in run
self.endcallback(self.Proc.pid, err)
File
"/home/developer/WorkData/PLC/beremiz/beremiz/util/ProcessLogger.py",
line 169, in finish
if self.timeout: self.timeout.cancel()
AttributeError: ProcessLogger instance has no attribute 'timeout'
The problem was that compilation process was finished before the timeout attribute is set.
Now timeout is set before launcing of compilation process.
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os 

import wx

# Get the default language
langid = wx.LANGUAGE_DEFAULT

# Define locale for wx
locale = wx.Locale(langid)

def GetDomain(path):
    for name in os.listdir(path):
        filepath = os.path.join(path, name)
        basename, fileext = os.path.splitext(name)
        if os.path.isdir(filepath):
            result = GetDomain(filepath)
            if result is not None:
                return result
        elif fileext == ".mo":
            return basename
    return None

def AddCatalog(locale_dir):
    if os.path.exists(locale_dir) and os.path.isdir(locale_dir):
        domain = GetDomain(locale_dir)
        if domain is not None:
            locale.AddCatalogLookupPathPrefix(locale_dir)
            locale.AddCatalog(domain)