<commit_before>'''
Created on Mar 9, 2012

@package: internationalization
@copyright: 2012 Sourcefabric o.p.s.
@license: http://www.gnu.org/licenses/gpl-3.0.txt
@author: <NAME>

Implementation for the PO file management.
'''

from internationalization.api.po_file import IPOFileService
from ally.container.ioc import injected

# --------------------------------------------------------------------

@injected
class POFileServiceAlchemy(IPOFileService):
    '''
    Implementation for @see: IPOService
    '''

    def __init__(self):
        '''
        '''

    def getGlobalPOFile(self, language):
        '''
        @see: IPOService.getGlobalPOFile
        '''

    def getComponentPOFile(self, component, locale):
        '''
        @see: IPOService.getComponentPOFile
        '''

    def getPluginPOFile(self, plugin, locale):
        '''
        @see: IPOService.getPluginPOFile
        '''

    def updateGlobalPOFile(self, poFile, locale:str):
        '''
        @see: IPOService.updateGlobalPOFile
        '''

    def updateComponentPOFile(self, poFile, component, locale):
        '''
        @see: IPOService.updateComponentPOFile
        '''

    def updatePluginPOFile(self, poFile, plugin, locale):
        '''
        @see: IPOService.updatePluginPOFile
        '''
<commit_msg>NR-21 : Translation management plugin implementation<commit_after>'''
Created on Mar 9, 2012

@package: internationalization
@copyright: 2012 Sourcefabric o.p.s.
@license: http://www.gnu.org/licenses/gpl-3.0.txt
@author: <NAME>

Implementation for the PO file management.
'''

from internationalization.api.po_file import IPOFileService
from ally.container.ioc import injected
from internationalization.core.spec import IPOFileManager
from ally.container import wire
from cdm.spec import ICDM, PathNotFound

# --------------------------------------------------------------------

@injected
class POFileServiceAlchemy(IPOFileService):
    '''
    Implementation for @see: IPOService
    '''

    po_file_manager = IPOFileManager; wire.entity('po_file_manager')

    po_cdm = ICDM; wire.entity('po_cdm')

    def __init__(self):
        '''
        '''

    def getGlobalPOFile(self, locale):
        '''
        @see: IPOService.getGlobalPOFile
        '''
        path = self._cdmPath(locale)
        try:
            cdmFileTimestamp = self.po_cdm.getTimestamp(path)
        except PathNotFound:
            return self.po_file_manager.getGlobalPOFile(locale)
        mngFileTimestamp = self.po_file_manager.poFileTimestamp(locale)
        if cdmFileTimestamp < mngFileTimestamp:
            return self.po_file_manager.getGlobalPOFile(locale)

    def getComponentPOFile(self, component, locale):
        '''
        @see: IPOService.getComponentPOFile
        '''
        path = self._cdmPath(locale, component)
        try:
            cdmFileTimestamp = self.po_cdm.getTimestamp(path)
        except PathNotFound:
            return self.po_file_manager.getComponentPOFile(component, locale)
        mngFileTimestamp = self.po_file_manager.poFileTimestamp(locale)
        if cdmFileTimestamp < mngFileTimestamp:
            return self.po_file_manager.getComponentPOFile(component, locale)

    def getPluginPOFile(self, plugin, locale):
        '''
        @see: IPOService.getPluginPOFile
        '''
        path = self._cdmPath(locale, plugin=plugin)
        try:
            cdmFileTimestamp = self.po_cdm.getTimestamp(path)
        except PathNotFound:
            return self.po_file_manager.getPluginPOFile(plugin, locale)
        mngFileTimestamp = self.po_file_manager.poFileTimestamp(locale)
        if cdmFileTimestamp < mngFileTimestamp:
            return self.po_file_manager.getPluginPOFile(plugin, locale)

    def updateGlobalPOFile(self, poFile, locale:str):
        '''
        @see: IPOService.updateGlobalPOFile
        '''
        self.po_file_manager.updateGlobalPOFile(poFile, locale)

    def updateComponentPOFile(self, poFile, component, locale):
        '''
        @see: IPOService.updateComponentPOFile
        '''
        self.po_file_manager.updateComponentPOFile(poFile, component, locale)

    def updatePluginPOFile(self, poFile, plugin, locale):
        '''
        @see: IPOService.updatePluginPOFile
        '''
        self.po_file_manager.updatePluginPOFile(poFile, plugin, locale)

    def _cdmPath(self, locale=None, component=None, plugin=None):
        if component:
            path = component
        elif plugin:
            path = plugin
        else:
            path = 'global'
        if locale:
            path = path + '-' + locale
        path = path + '.po'
        return path

{'fraction_non_alphanumeric': 0.12502694546238413, 'fraction_numerical': 0.005173528777753826, 'mean_word_length': 2.470456245325355, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6614490', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1297, 'n_words': 263}