def _load_static_data(filename): """Load a static file from the 'static' directory""" is_frozen = (hasattr(sys, 'frozen') # new py2exe or imp.is_frozen('__main__')) # tools/freeze if is_frozen: if sys.platform.startswith("darwin"): path = os.path.join(os.path.dirname(sys.executable), "../Resources", STATIC_REL_PATH, filename) else: path = os.path.join(os.path.dirname(sys.executable), STATIC_REL_PATH, filename) with open(path, 'rb') as f: data = f.read() else: try: from pkgutil import get_data as _get except ImportError: from pkg_resources import resource_string as _get data = _get(basepkgname, os.path.join(STATIC_REL_PATH, filename)) if filename.endswith('.css'): s = data.decode('utf-8') s = fontfallback.css_replace_fontfamily(s) data = s.encode('utf-8') elif filename.endswith('.html'): s = data.decode('utf-8') s = s.replace('{% current_version %}', __version__) data = s.encode('utf-8') return data
def _load_static_data(filename): """Load a static file from the 'static' directory""" is_frozen = ( hasattr(sys, 'frozen') # new py2exe or imp.is_frozen('__main__')) # tools/freeze if is_frozen: if sys.platform.startswith("darwin"): path = os.path.join(os.path.dirname(sys.executable), "../Resources", STATIC_REL_PATH, filename) else: path = os.path.join(os.path.dirname(sys.executable), STATIC_REL_PATH, filename) with open(path, 'rb') as f: data = f.read() else: try: from pkgutil import get_data as _get except ImportError: from pkg_resources import resource_string as _get data = _get(basepkgname, os.path.join(STATIC_REL_PATH, filename)) if filename.endswith('.css'): s = data.decode('utf-8') s = fontfallback.css_replace_fontfamily(s) data = s.encode('utf-8') elif filename.endswith('.html'): s = data.decode('utf-8') s = s.replace('{% current_version %}', __version__) data = s.encode('utf-8') return data
def _load_static_data(filename): """Load a static file from the 'static' directory""" if filename in _static_cache: return _static_cache[filename] is_frozen = hasattr(sys, "frozen") or imp.is_frozen( # new py2exe "__main__") # tools/freeze if is_frozen: if sys.platform.startswith("darwin"): path = os.path.join( os.path.dirname(sys.executable), "../Resources", STATIC_REL_PATH, filename, ) else: path = os.path.join(os.path.dirname(sys.executable), STATIC_REL_PATH, filename) with open(path, "rb") as f: data = f.read() else: try: from pkgutil import get_data as _get except ImportError: from pkg_resources import resource_string as _get data = _get(basepkgname, os.path.join(STATIC_REL_PATH, filename)) if filename.endswith(".css"): s = data.decode("utf-8") # s = fontfallback.css_replace_fontfamily(s) data = s.encode("utf-8") elif filename.endswith(".html"): s = data.decode("utf-8") s = s.replace("{% current_version %}", __version__) data = s.encode("utf-8") _static_cache[filename] = data return data