Changeset 528:25c1783c0111

Show
Ignore:
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:
3 modified

Legend:

Unmodified
Added
Removed
  • projects/handlers/types/intltool.py

    r482 r528  
    4545        # Cleaning the repository after running intltool-update 
    4646        self.component.unit.browser._clean_dir() 
     47 
     48        self.clear_old_stats() 
  • projects/handlers/types/pot.py

    r514 r528  
    11from translations.lib.types.pot import POTManager 
     2from translations.models import POFile 
    23from txcommon.log import logger 
    34 
     
    5758            self.set_stats_for_lang(lang) 
    5859 
     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 
    5979    def clear_stats(self): 
    6080        """Clear stats for all translations of the component.""" 
  • translations/lib/types/pot.py

    r514 r528  
    202202        POFile.objects.filter(object_id=object.id, content_type=ctype).delete() 
    203203 
     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 
    204211    def set_source_stats(self, object, is_msgmerged): 
    205212        """Set the source file (pot) in the database""" 
     
    312319        shutil.copyfile(os.path.join(self.path, filename), dest) 
    313320 
     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 
    314329    def msgmerge(self, pofile, potfile): 
    315330        """