def module_resolver(section, branch, dir): from lib.apps import local_apps # first part of branch is the module name parts = os.path.normpath(branch.strip('/')).replace( os.path.sep, '/').split('/') locale = i18n.current_lang(True) if not parts: return False module_path = local_apps.getModulePath(parts[0]) if module_path: fn = os.path.join(module_path, *parts[1:]) if fn.endswith('.js') and os.path.exists(fn): return i18n.translate_js( fn ) # returns the path to a cached file containing the original js + json translation map return fn elif parts[0].startswith('modules-') and parts[0].endswith('.js'): hash = parts[0].replace('modules-', '').replace('.min.js', '') return make_absolute( os.path.join( i18n.CACHE_PATH, '%s-%s-%s.cache' % ('modules.min.js', hash, locale))) elif parts[0].startswith('modules-') and parts[0].endswith('.css'): return filechain.MODULE_STATIC_CACHE_PATH + os.sep + 'css' + os.sep + parts[ 0] return False
def module_resolver(section, branch, dir): from lib.apps import local_apps # first part of branch is the module name parts = os.path.normpath(branch.strip('/')).replace(os.path.sep, '/').split('/') locale = i18n.current_lang(True) if not parts: return False module_path = local_apps.getModulePath(parts[0]) if module_path: # this means there is a module named parts[0] # SPL-51365 images should load irrespective of css_minification. if parts[0]==parts[1]: # ignore of repetition of module name # happens for image request when minify_css=False fn = os.path.join(module_path, *parts[2:]) else: fn = os.path.join(module_path, *parts[1:]) #verified while fixing SPL-47422 #pylint: disable=E1103 if fn.endswith('.js') and os.path.exists(fn): return i18n.translate_js(fn) # returns the path to a cached file containing the original js + json translation map return fn elif parts[0].startswith('modules-') and parts[0].endswith('.js'): hash = parts[0].replace('modules-', '').replace('.min.js', '') return make_absolute(os.path.join(i18n.CACHE_PATH, '%s-%s-%s.cache' % ('modules.min.js', hash, locale))) elif parts[0].startswith('modules-') and parts[0].endswith('.css'): return filechain.MODULE_STATIC_CACHE_PATH + os.sep + 'css' + os.sep + parts[0] return False
def static_app_resolver(section, branch, dir): """ Resolver that pulls application specific assets. """ parts = branch.split('/') subbranch, app, asset = parts[0], parts[1], '/'.join(parts[2:] ) appstaticdir = os.path.normpath(os.path.join(dir, app, 'appserver', 'static')) fn = os.path.normpath(os.path.join(appstaticdir, asset)) if fn.startswith(appstaticdir) and fn.startswith(os.path.normpath(dir)) and os.path.exists(fn): sp = os.path.splitext(asset) if sp[1] == '.js' and not asset.startswith('js/contrib') and 'i18noff' not in cherrypy.request.query_string: i18n_cache = i18n.translate_js(fn) if i18n_cache: return i18n_cache return fn return False
def static_resolver(section, branch, dir): """resolver that knows how to add translations to javascript files""" # chain off to another resolver for statics served from application bundles. # overrides the 'dir' param with where applications are stored. if branch.startswith('app/'): return static_app_resolver(section, branch, static_app_dir) sp = os.path.splitext(branch) fn = os.path.join(dir, branch) if branch == 'js/i18n.js': return i18n.dispatch_i18n_js(fn) # send the locale data with the i18n.js system elif branch.endswith('common.min.js'): return filechain.chain_common_js() # returns the path to a cached file containing the finished cache file elif not branch.startswith('js/contrib') and sp[1] == '.js' and os.path.exists(fn) and 'i18noff' not in cherrypy.request.query_string: return i18n.translate_js(fn) # returns the path to a cached file containing the original js + json translation map return False # fallback to the default handler
def static_resolver(section, branch, dir): """resolver that knows how to add translations to javascript files""" # chain off to another resolver for statics served from application bundles. # overrides the 'dir' param with where applications are stored. if branch.startswith('app/'): return static_app_resolver(section, branch, static_app_dir) sp = os.path.splitext(branch) fn = os.path.join(dir, branch) if branch == 'js/i18n.js': return i18n.dispatch_i18n_js(fn) # send the locale data with the i18n.js system elif branch.endswith('common.min.js'): return filechain.chain_common_js() # returns the path to a cached file containing the finished cache file elif branch.startswith('js/splunkjs'): return False elif not branch.startswith('js/contrib') and sp[1] == '.js' and os.path.exists(fn) and 'i18noff' not in cherrypy.request.query_string: return i18n.translate_js(fn) # returns the path to a cached file containing the original js + json translation map return False # fallback to the default handler
def module_resolver(section, branch, dir): from lib.apps import local_apps # first part of branch is the module name parts = os.path.normpath(branch.strip('/')).replace(os.path.sep, '/').split('/') locale = i18n.current_lang(True) if not parts: return False module_path = local_apps.getModulePath(parts[0]) if module_path: fn = os.path.join(module_path, *parts[1:]) if fn.endswith('.js') and os.path.exists(fn): return i18n.translate_js(fn) # returns the path to a cached file containing the original js + json translation map return fn elif parts[0].startswith('modules-') and parts[0].endswith('.js'): hash = parts[0].replace('modules-', '').replace('.min.js', '') return make_absolute(os.path.join(i18n.CACHE_PATH, '%s-%s-%s.cache' % ('modules.min.js', hash, locale))) elif parts[0].startswith('modules-') and parts[0].endswith('.css'): return filechain.MODULE_STATIC_CACHE_PATH + os.sep + 'css' + os.sep + parts[0] return False