def static_app_factory(global_config, **local_conf): """Create an application instance to serve static contents.""" config = global_config.copy() config.update(local_conf) #initialize mappings to be able to get enabled applications urls.init_application_urls(config['url.file']) application_list = [] enabled_application_list = get_enabled_app_list() for app_name in enabled_application_list: static_app_dir = get_resource_dir(app_name) if not static_app_dir: #when resource dir does not exist continue with next app continue static_app_dir = os.sep.join([static_app_dir, 'static']) static_app = StaticContentMiddleware(static_app_dir, cache_max_age=None) application_list.append(static_app) #cascade all applications in order, so first static URL #are processed and then the other middlewares application = Cascade(application_list) return application
def _init_application_domains(self): self.domains = {} for app_name in get_enabled_app_list(): resource_dir = get_resource_dir(app_name) if not resource_dir: continue locale_dir = os.sep.join([resource_dir, 'locale']) if not os.path.isdir(locale_dir): continue #map a domain to a locale directory. #template location will be resolvedi using something #like "app_name/path_to/template.xxx" for renderers self.domains[app_name] = { 'locale_dir': locale_dir, 'translation': None, }
def export_static(app_name, out_dir): """Copy static files from application dir to an external dir.""" #get resource directory from app res_dir = get_resource_dir(app_name) if not res_dir: print '[WAR] Application %s dont have a resources dir, skipping ..' \ % app_name return #get app static files directory static_dir = os.sep.join([res_dir, 'static', app_name.replace('.', '_')]) if not os.path.isdir(static_dir): print '[WAR] Application %s dont have a static dir, skipping ..' \ % app_name return #append app name to destination directory out_dir = os.sep.join([out_dir, app_name]) if os.path.isdir(out_dir): msg = 'Destination dir already exist. Delete it ? [y/N]' if raw_input(msg).upper() == 'Y': #delete existing destination directory shutil.rmtree(out_dir) else: #any other value different than Y stops the script print '[OK] Script ended by user' sys.exit(0) try: #recursive copy app static files to destination dir shutil.copytree(static_dir, out_dir) print '[OK] Static files from %s copied sucessfully' % app_name except IOError, err: print '[ERR] Unable to copy static files from %s :' % app_name print '[ERR] %s' % str(err) sys.exit(1)