#NEWLINE# def get_source_file_for_file( filename , source_files ) : #NEWLINE# #INDENT# "\n    Find the related source file (POT) for a file (PO); useful when it has\n    multiple source files.\n\n    This method gets a filename and the related source_files as parameters\n    and tries to discover the related POT file using two methods:\n\n    1. Trying to find a POT file with the same base path that the PO.\n        Example: /foo/bar.pot and /foo/baz.po match on this method.\n\n    2. Trying to find a POT file with the same domain that the PO in any\n        directory.\n\n        Example: /foo/bar.pot and /foo/baz/bar.po match on this method.\n        The domain in this case is 'bar'.\n\n    If no POT is found the method returns None.\n\n    " #NEWLINE# fb = os . path . basename ( filename ) #NEWLINE# fp = filename . split ( fb ) [ 0 ] #NEWLINE# if ( len ( source_files ) > 1 ) : #NEWLINE# #INDENT# for source in source_files : #NEWLINE# #INDENT# sb = os . path . basename ( source ) #NEWLINE# if sb . endswith ( '.pot' ) : #NEWLINE# #INDENT# sb = sb [ : ( - 1 ) ] #NEWLINE# #UNINDENT# pb = source . split ( sb ) [ 0 ] #NEWLINE# if ( ( pb == fp ) or ( sb == fb ) ) : #NEWLINE# #INDENT# return source #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( source_files ) == 1 ) : #NEWLINE# #INDENT# return source_files [ 0 ]