@staticmethod
    def _generate_syntax_file_map():
        """
        Generate a map of all file types to their syntax files.
        """
        syntax_file_map = {}
        packages_path = sublime.packages_path()
        packages = [f for f in os.listdir(packages_path) if os.path.isdir(os.path.join(packages_path, f))]
        for package in packages:
            package_dir = os.path.join(packages_path, package)
            syntax_files = [os.path.join(package_dir, f) for f in os.listdir(package_dir) if f.endswith(".tmLanguage")]
            for syntax_file in syntax_files:
                try:
                    plist = plistlib.readPlist(syntax_file)
                    if plist:
                        for file_type in plist['fileTypes']:
                            syntax_file_map[file_type.lower()] = syntax_file
                except expat.ExpatError:  # can't parse
                    logger.warn("could not parse '%s'" % syntax_file)
                except KeyError:  # no file types
                    pass

        # load ST3 syntax files
        if hasattr(sublime, "find_resources"):
            syntax_files = sublime.find_resources("*.tmLanguage")
            for syntax_file in syntax_files:
                try:
                    plist = plistlib.readPlistFromBytes(bytearray(sublime.load_resource(syntax_file), "utf-8"))
                    if plist:
                        for file_type in plist['fileTypes']:
                            syntax_file_map[file_type.lower()] = syntax_file
                except expat.ExpatError:  # can't parse
                    logger.warn("could not parse '%s'" % syntax_file)
                except KeyError:  # no file types
                    pass

        return syntax_file_map
dataset/ETHPy150Open bgreenlee/sublime-github/sublime_github.py/OpenGistCommand._generate_syntax_file_map/original