Changeset 528:25c1783c0111
- Timestamp:
- 04/27/09 22:10:31 (11 months ago)
- Author:
- Diego Búrigo Zacarão <diegobz@…>
- Branch:
- default
- Message:
-
Delete cache and POFiles entries when a file is deleted from upstream
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r482
|
r528
|
|
| 45 | 45 | # Cleaning the repository after running intltool-update |
| 46 | 46 | self.component.unit.browser._clean_dir() |
| | 47 | |
| | 48 | self.clear_old_stats() |
-
|
r514
|
r528
|
|
| 1 | 1 | from translations.lib.types.pot import POTManager |
| | 2 | from translations.models import POFile |
| 2 | 3 | from txcommon.log import logger |
| 3 | 4 | |
| … |
… |
|
| 57 | 58 | self.set_stats_for_lang(lang) |
| 58 | 59 | |
| | 60 | self.clear_old_stats() |
| | 61 | |
| | 62 | def clear_old_stats(self): |
| | 63 | """ |
| | 64 | Clear stats present on the database and msgmerge dir, that are not |
| | 65 | anymore in the upstream repository |
| | 66 | """ |
| | 67 | pofiles = POFile.objects.select_related().filter( |
| | 68 | component=self.component) |
| | 69 | pots = self.tm.get_source_files() |
| | 70 | files = self.tm.get_po_files() |
| | 71 | for pot in pots: |
| | 72 | files.append(pot) |
| | 73 | logger.info(files) |
| | 74 | for stat in pofiles: |
| | 75 | if stat.filename not in files: |
| | 76 | self.tm.delete_file_from_static_dir(stat.filename) |
| | 77 | stat.delete() |
| | 78 | |
| 59 | 79 | def clear_stats(self): |
| 60 | 80 | """Clear stats for all translations of the component.""" |
-
|
r514
|
r528
|
|
| 202 | 202 | POFile.objects.filter(object_id=object.id, content_type=ctype).delete() |
| 203 | 203 | |
| | 204 | def delete_stats_for_file_object(self, filename, object): |
| | 205 | """Delete a specific pofile of an object""" |
| | 206 | ctype = ContentType.objects.get_for_model(object) |
| | 207 | POFile.objects.filter(filename=filename, object_id=object.id, |
| | 208 | content_type=ctype).delete() |
| | 209 | self.delete_file_from_static_dir(filename) |
| | 210 | |
| 204 | 211 | def set_source_stats(self, object, is_msgmerged): |
| 205 | 212 | """Set the source file (pot) in the database""" |
| … |
… |
|
| 312 | 319 | shutil.copyfile(os.path.join(self.path, filename), dest) |
| 313 | 320 | |
| | 321 | def delete_file_from_static_dir(self, filename): |
| | 322 | """Delete a file from the static cache dir""" |
| | 323 | dest = os.path.join(self.msgmerge_path, filename) |
| | 324 | try: |
| | 325 | os.remove(dest) |
| | 326 | except OSError: |
| | 327 | pass |
| | 328 | |
| 314 | 329 | def msgmerge(self, pofile, potfile): |
| 315 | 330 | """ |