#NEWLINE# def run( self ) : #NEWLINE# #INDENT# po_files = [ ] #NEWLINE# if ( not self . output_file ) : #NEWLINE# #INDENT# if self . locale : #NEWLINE# #INDENT# po_files . append ( ( self . locale , os . path . join ( self . output_dir , self . locale , 'LC_MESSAGES' , ( self . domain + '.po' ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for locale in os . listdir ( self . output_dir ) : #NEWLINE# #INDENT# po_file = os . path . join ( self . output_dir , locale , 'LC_MESSAGES' , ( self . domain + '.po' ) ) #NEWLINE# if os . path . exists ( po_file ) : #NEWLINE# #INDENT# po_files . append ( ( locale , po_file ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# po_files . append ( ( self . locale , self . output_file ) ) #NEWLINE# #UNINDENT# domain = self . domain #NEWLINE# if ( not domain ) : #NEWLINE# #INDENT# domain = os . path . splitext ( os . path . basename ( catalog . input_file ) ) [ 0 ] #NEWLINE# #UNINDENT# infile = open ( self . input_file , 'rb' ) #NEWLINE# try : #NEWLINE# #INDENT# template = read_po ( infile ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# infile . close ( ) #NEWLINE# #UNINDENT# if ( not po_files ) : #NEWLINE# #INDENT# raise DistutilsOptionError ( 'no message catalogs found' ) #NEWLINE# #UNINDENT# for ( locale , filename ) in po_files : #NEWLINE# #INDENT# self . log . info ( 'updating catalog %s based on %s' , filename , self . input_file ) #NEWLINE# infile = open ( filename , 'rb' ) #NEWLINE# try : #NEWLINE# #INDENT# catalog = read_po ( infile , locale = locale , domain = domain ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# infile . close ( ) #NEWLINE# #UNINDENT# catalog . update ( template , self . no_fuzzy_matching , update_header_comment = self . update_header_comment ) #NEWLINE# tmpname = os . path . join ( os . path . dirname ( filename ) , ( tempfile . gettempprefix ( ) + os . path . basename ( filename ) ) ) #NEWLINE# tmpfile = open ( tmpname , 'wb' ) #NEWLINE# try : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# write_po ( tmpfile , catalog , ignore_obsolete = self . ignore_obsolete , include_previous = self . previous , width = self . width ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# tmpfile . close ( ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# os . remove ( tmpname ) #NEWLINE# raise #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# os . rename ( tmpname , filename ) #NEWLINE# #UNINDENT# except OSError : #NEWLINE# #INDENT# os . remove ( filename ) #NEWLINE# shutil . copy ( tmpname , filename ) #NEWLINE# os . remove ( tmpname )