

def find_pos(lang, project_apps=True, django_apps=False, third_party_apps=False):
    '\n    scans a couple possible repositories of gettext catalogs for the given\n    language code\n\n    '
    paths = []
    parts = settings.SETTINGS_MODULE.split('.')
    project = __import__(parts[0], {
        
    }, {
        
    }, [])
    abs_project_path = os.path.normpath(os.path.abspath(os.path.dirname(project.__file__)))
    if project_apps:
        if os.path.exists(os.path.abspath(os.path.join(os.path.dirname(project.__file__), 'locale'))):
            paths.append(os.path.abspath(os.path.join(os.path.dirname(project.__file__), 'locale')))
        if os.path.exists(os.path.abspath(os.path.join(os.path.dirname(project.__file__), '..', 'locale'))):
            paths.append(os.path.abspath(os.path.join(os.path.dirname(project.__file__), '..', 'locale')))
    if django_apps:
        django_paths = cache.get('rosetta_django_paths')
        if (django_paths is None):
            django_paths = []
            for (root, dirnames, filename) in os.walk(os.path.abspath(os.path.dirname(django.__file__))):
                if ('locale' in dirnames):
                    django_paths.append(os.path.join(root, 'locale'))
                    continue
            cache.set('rosetta_django_paths', django_paths, (60 * 60))
        paths = (paths + django_paths)
    for localepath in settings.LOCALE_PATHS:
        if os.path.isdir(localepath):
            paths.append(localepath)
    has_appconfig = False
    for appname in settings.INSTALLED_APPS:
        if (rosetta_settings.EXCLUDED_APPLICATIONS and (appname in rosetta_settings.EXCLUDED_APPLICATIONS)):
            continue
        p = appname.rfind('.')
        if (p >= 0):
            app = getattr(__import__(appname[:p], {
                
            }, {
                
            }, [str(appname[(p + 1):])]), appname[(p + 1):])
        else:
            app = __import__(appname, {
                
            }, {
                
            }, [])
        if (django.VERSION[0:2] >= (1, 7)):
            if (inspect.isclass(app) and issubclass(app, AppConfig)):
                has_appconfig = True
                continue
        app_path = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(app.__file__), 'locale')))
        if (('contrib' in app_path) and ('django' in app_path) and (not django_apps)):
            continue
        if ((not third_party_apps) and (abs_project_path not in app_path)):
            continue
        if ((not project_apps) and (abs_project_path in app_path)):
            continue
        if os.path.isdir(app_path):
            paths.append(app_path)
    if has_appconfig:
        for app_ in apps.get_app_configs():
            if (rosetta_settings.EXCLUDED_APPLICATIONS and (app_.name in rosetta_settings.EXCLUDED_APPLICATIONS)):
                continue
            app_path = app_.path
            if (('contrib' in app_path) and ('django' in app_path) and (not django_apps)):
                continue
            if ((not third_party_apps) and (abs_project_path not in app_path)):
                continue
            if ((not project_apps) and (abs_project_path in app_path)):
                continue
            if os.path.exists(os.path.abspath(os.path.join(app_path, 'locale'))):
                paths.append(os.path.abspath(os.path.join(app_path, 'locale')))
            if os.path.exists(os.path.abspath(os.path.join(app_path, '..', 'locale'))):
                paths.append(os.path.abspath(os.path.join(app_path, '..', 'locale')))
    ret = set()
    langs = [lang]
    if ('-' in lang):
        (_l, _c) = map((lambda x: x.lower()), lang.split('-', 1))
        langs += [('%s_%s' % (_l, _c)), ('%s_%s' % (_l, _c.upper())), ('%s_%s' % (_l, _c.capitalize()))]
    elif ('_' in lang):
        (_l, _c) = map((lambda x: x.lower()), lang.split('_', 1))
        langs += [('%s-%s' % (_l, _c)), ('%s-%s' % (_l, _c.upper())), ('%s_%s' % (_l, _c.capitalize()))]
    paths = map(os.path.normpath, paths)
    paths = list(set(paths))
    for path in paths:
        if (path not in rosetta_settings.ROSETTA_EXCLUDED_PATHS):
            for lang_ in langs:
                dirname = os.path.join(path, lang_, 'LC_MESSAGES')
                for fn in rosetta_settings.POFILENAMES:
                    filename = os.path.join(dirname, fn)
                    if os.path.isfile(filename):
                        ret.add(os.path.abspath(filename))
    return list(sorted(ret))

dataset/ETHPy150Open mbi/django-rosetta/rosetta/poutil.py find_pos/original