| 1 | from django.conf import settings |
|---|
| 2 | from projects.handlers.types import pot |
|---|
| 3 | from txcommon.log import logger |
|---|
| 4 | from notification import models as notification |
|---|
| 5 | |
|---|
| 6 | class IntltoolHandler(pot.POTHandler): |
|---|
| 7 | """ |
|---|
| 8 | POTHandler abstraction layer, hense specific to the projects app. |
|---|
| 9 | |
|---|
| 10 | You can use this higher-level object to interact with a |
|---|
| 11 | component's statistics that use intltool instead of meddling with |
|---|
| 12 | the lower-level POTManager. Each Component object gets one of these |
|---|
| 13 | as ``component.trans``. |
|---|
| 14 | |
|---|
| 15 | """ |
|---|
| 16 | |
|---|
| 17 | def set_stats(self): |
|---|
| 18 | """ |
|---|
| 19 | Calculate stats for all translations of the component after |
|---|
| 20 | these tranlations be merged with a new POT file extracted |
|---|
| 21 | using intltool-update. . |
|---|
| 22 | """ |
|---|
| 23 | |
|---|
| 24 | logger.debug("Setting stats for %s" % self.component) |
|---|
| 25 | |
|---|
| 26 | isIntltooled = self.tm.intltool_update() |
|---|
| 27 | if not isIntltooled: |
|---|
| 28 | logger.debug("intltool-update --pot has failed for %s" % |
|---|
| 29 | self.component) |
|---|
| 30 | |
|---|
| 31 | if settings.ENABLE_NOTICES: |
|---|
| 32 | notification.send(self.component.project.maintainers.all(), |
|---|
| 33 | 'project_component_potfile_error', |
|---|
| 34 | {'component': self.component}) |
|---|
| 35 | is_msgmerged=False |
|---|
| 36 | else: |
|---|
| 37 | is_msgmerged=True |
|---|
| 38 | |
|---|
| 39 | # Set the source file (pot) to the database |
|---|
| 40 | self.tm.set_source_stats(self.component, is_msgmerged) |
|---|
| 41 | |
|---|
| 42 | for lang in self.tm.get_langs(): |
|---|
| 43 | self.set_stats_for_lang(lang, is_msgmerged) |
|---|
| 44 | |
|---|
| 45 | # Cleaning the repository after running intltool-update |
|---|
| 46 | self.component.unit.browser._clean_dir() |
|---|
| 47 | |
|---|
| 48 | self.clear_old_stats() |
|---|