def getDatepickerPath (): """ returns the path of the datepicker js file with the correct locale """ import i18n staticdir = cherrypy.config.get('staticdir') lang = i18n.current_lang_url_component() locale = None locale1 = lang locale2 = lang[:2] for testlocale in (locale1, locale2): if os.path.exists(os.path.join(staticdir, 'js', 'contrib', 'jquery.ui.datepicker', 'jquery.ui.datepicker-%s.js' % testlocale)): locale = ('contrib', 'jquery.ui.datepicker', 'jquery.ui.datepicker-%s.js' % testlocale) break return locale
def serve_static_css(fn): """ Translate urls defined in static css files into local urls taking locale and root prefix into account This is called above, broken out because CSS uses a simpler in-memory cache that's computationally cheaper, whereas JS uses an expensive i18n cache that we store on disk so it will persist between splunkweb restarts """ # make sure we keep cached copies for each locale/version tuple lang = i18n.current_lang_url_component() cache = serve_static_css.cache.setdefault(lang, {}) # ensure file hasn't been modified since we cached it if fn in cache and cache[fn][0]==os.path.getmtime(fn): css = cache[fn][1] else: f = file(fn) css = re.sub(r'([\s:]+url\([\'"]?)([^\)\'"]+)', lambda m: m.group(1)+make_url(m.group(2)), f.read(250000)) cache[fn] = (os.path.getmtime(fn), css) f.close() cherrypy.response.headers['Content-Type'] = 'text/css' cherrypy.response.headers['Last-Modified'] = datetime.datetime.fromtimestamp(cache[fn][0]).strftime('%a, %d %b %Y %H:%M:%S %Z') serve_static_content(css)
def generateSelfHelpLink(context=None): ''' Generates the contexual URI to the splunk.com help system ''' import i18n, urllib locale = i18n.current_lang_url_component() if not context: # generate standard help link by passing a keyword that is composed # of a cleansed URI (remove locale and namespace) context = cherrypy.request.path_info.strip('/').split('/') appContext = '' if context[0].startswith(locale): context.pop(0) if context[0] in ('manager'): context.pop(1) if context[0] in ('app'): appName = context[1] entity = en.getEntity('apps/local', appName) if filter((lambda x: x[0] == 'disable'), entity.links): # make sure it's not an internal Splunk app appVersion = entity.get('version') appContext = '[%s:%s]' % (appName, appVersion) context = appContext + '.'.join(context) uri = make_url('/help') params = { 'license': 'free' if cherrypy.config.get('is_free_license') else 'pro', 'installType': 'trial' if cherrypy.config.get('is_trial_license') else 'prod', 'versionNumber': cherrypy.config.get('version_label'), 'location': context, 'skin': 'default', 'locale': locale } return uri + '?' + urllib.urlencode(params)