<s> import os <EOL> from pontoon . base . models import Resource <EOL> from pontoon . base . utils import extension_in , first <EOL> def is_in_hidden_directory ( path ) : <EOL> """<STR_LIT>""" <EOL> for p in path . split ( os . sep ) : <EOL> if p . startswith ( '<STR_LIT:.>' ) : <EOL> return True <EOL> return False <EOL> def is_resource ( filename ) : <EOL> """<STR_LIT>""" <EOL> return extension_in ( filename , Resource . ALLOWED_EXTENSIONS ) <EOL> def is_source_resource ( filename ) : <EOL> """<STR_LIT>""" <EOL> return extension_in ( filename , Resource . SOURCE_EXTENSIONS ) <EOL> def directory_contains_resources ( directory_path , source_only = False ) : <EOL> """<STR_LIT>""" <EOL> resource_check = is_source_resource if source_only else is_resource <EOL> for root , dirnames , filenames in os . walk ( directory_path ) : <EOL> if first ( filenames , resource_check ) is not None : <EOL> return True <EOL> return False <EOL> def locale_directory_path ( checkout_path , locale_code ) : <EOL> """<STR_LIT>""" <EOL> possible_paths = [ ] <EOL> for root , dirnames , filenames in os . walk ( checkout_path ) : <EOL> if locale_code in dirnames : <EOL> possible_paths . append ( os . path . join ( root , locale_code ) ) <EOL> locale_variant = locale_code . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> if locale_variant in dirnames : <EOL> possible_paths . append ( os . path . join ( root , locale_variant ) ) <EOL> for possible_path in possible_paths : <EOL> if directory_contains_resources ( possible_path ) : <EOL> return possible_path <EOL> if possible_paths : <EOL> return possible_paths [ <NUM_LIT:0> ] <EOL> raise IOError ( '<STR_LIT>' . format ( <EOL> locale_code or '<STR_LIT:source>' ) ) <EOL> def relative_source_path ( path ) : <EOL> """<STR_LIT>""" <EOL> if path . endswith ( '<STR_LIT>' ) : <EOL> path += '<STR_LIT:t>' <EOL> return path </s>
