def _check_use_local_daemon(self, request): use_local = get_bender_or_static3_setting('BENDER_LOCAL_MODE', None) if use_local != None: return use_local if get_setting('ENV') in ('local',): return True return False
def get_bender_asset_url(self, full_asset_path): ''' Builds a URL to the particulr CSS, JS, IMG, or other file that is part of project_name. The URL includes the proper domain and build information. ''' project_name = _extract_project_name_from_path(full_asset_path) if not project_name: raise Exception('Your path must be of the form: "<project_name>/static/js/whatever.js"') # Break the full path down to just the asset path (everything under static/) asset_path = full_asset_path.replace("%s/static/" % project_name, '') # Make sure the path doesn't refer to a precompiled extension (since that won't actually exist on s3) extension = _find_extension(full_asset_path, also_search_folder_name=False) if extension in PRECOMPILED_EXTENSIONS: message = "You cannot use the '%s' extension in this static path: %s.\n You must use 'js' or 'css' (It will work locally, but it won't work on QA/prod)." % (extension, full_asset_path) if get_setting('ENV') == 'prod': logger.error(message) else: raise Exception(message) # Dispatch to the correct fetcher if self.use_local_daemon: return self.local_daemon_fetcher.get_asset_url(project_name, asset_path) else: return self.s3_fetcher.get_asset_url(project_name, asset_path)
def make_url_to_pointer(self, pointer, project_name): # if the version is just an integer, that represents a major version, and so we create # the major version pointer if str(pointer).isdigit(): pointer = 'latest-version-%s' % str(pointer) url = 'http://%s/%s/%s' % (self._get_non_cdn_domain(), project_name, pointer) if get_setting('ENV') not in ('prod',): url += '-qa' return url
def __init__(self, host_project_name='', is_debug=False, forced_build_version_by_project=None): ''' @host_project_name - the project name of the application that we are runing from ''' self.host_project_name = host_project_name self.is_debug = is_debug self.project_directory = get_setting('PROJ_DIR') # We store the build versions locally in this object so we don't have to # hit memcached dozens of times per request every time we call get_asset_url. self.per_request_project_build_version_cache = {} self._add_forced_versions_to_per_request_cache(forced_build_version_by_project)
def _check_is_debug_mode(self, http_get_params): ''' Debug mode will include the expanded, unbundled, non-minifised assets returns a Boolean ''' hs_debug = http_get_params.get('hsDebug') if hs_debug: return hs_debug != 'false' local_mode = get_bender_or_static3_setting('BENDER_LOCAL_MODE', None) if local_mode != None: return local_mode debug_mode = get_bender_or_static3_setting('BENDER_DEBUG_MODE', None) if debug_mode != None: return debug_mode return get_setting('ENV') in ('local',)
def load_cache(): ''' If the RAW_CACHE_NAME is defined in settings, load the cache of that name. Otherwise, load the cache that has the exact same settings as the default cache, except with no 'KEY_PREFIX' set ''' # If no django installed, we use the local memory cache if not get_cache: return simple_memory_cache cache_name = get_setting_default('RAW_CACHE_NAME', None) if cache_name: return get_cache(cache_name) conf = get_setting('CACHES').get('default') backend = conf['BACKEND'] raw_conf_dict = {} for key in ('LOCATION', 'TIMEOUT'): val = conf.get(key) if val != None: raw_conf_dict[key] = val raw_conf_dict['KEY_FUNCTION'] = lambda key, key_prefix, version: key the_cache = get_cache(backend, **raw_conf_dict) return the_cache
def _is_only_on_qa(): return get_setting('ENV') == 'qa'