def manageThemes(theme_name, theme_basepath, theme_type): theme_dir = os.path.join(theme_basepath, "themes", theme_name) athana.addFileStore("/theme/", theme_dir + "/") athana.addFileStorePath("/css/", theme_dir + "/css/") athana.addFileStorePath("/img/", theme_dir + "/img/") athana.addFileStorePath("/js/", theme_dir + "/js/") theme.update(theme_name, theme_dir + "/", theme_type) logg.info("Loading theme '%s' from '%s' (%s)", theme_name, theme_dir, theme_type)
def manageThemes(themepath, type): name = config.get("config.theme", "") if os.path.exists(config.basedir + "/" + themepath + "themes/" + name + "/"): athana.addFileStore("/theme/", themepath + "themes/" + name + "/") athana.addFileStorePath("/css/", themepath + "themes/" + name + "/css/") athana.addFileStorePath("/img/", themepath + "themes/" + name + "/img/") athana.addFileStorePath("/js/", themepath + "themes/" + name + "/js/") theme.update(name, themepath + "themes/" + name + "/", type) print "Loading theme '%s' (%s)" % (name, type)
def activate(self): import core.webconfig # XXX: this is ugly, is there a better way? core.webconfig.theme = self theme_jinja_loader = self.make_jinja_loader() if theme_jinja_loader is not None: logg.info("adding jinja loader for theme") app.add_template_loader(theme_jinja_loader, 0) athana.addFileStore("/theme/", self.path + "/") athana.addFileStorePath("/css/", self.path + "/css/") athana.addFileStorePath("/img/", self.path + "/img/") athana.addFileStorePath("/js/", self.path + "/js/")
def initContexts(): athana.setBase(".") athana.setTempDir(config.get("paths.tempdir", "/tmp/")) from core.config import resolve_filename from core.translation import translate from core.ftp import collection_ftpserver tal.set_base(".") tal.add_macro_resolver(resolve_filename) tal.add_translator(translate) context = athana.addContext("/", ".") # === public area === file = context.addFile("web/frontend/streams.py") file.addHandler("send_image").addPattern("/images/.*") file.addHandler("send_thumbnail").addPattern("/thumbs/.*") file.addHandler("send_thumbnail2").addPattern("/thumb2/.*") file.addHandler("send_doc").addPattern("/doc/.*") file.addHandler("send_file").addPattern("/file/.*") file.addHandler("send_file_as_download").addPattern("/download/.*") file.addHandler("send_attachment").addPattern("/attachment/.*") file.addHandler("send_attfile").addPattern("/attfile/.*") file.addHandler("get_archived").addPattern("/archive/.*") file.addHandler("get_root").addPattern( "/[a-z,0-9,-]*\.[a-z]*" ) # root directory added /web/root (only files with extensions) file = context.addFile("web/frontend/zoom.py") file.addHandler("send_imageproperties_xml").addPattern( "/tile/[0-9]*/ImageProperties.xml") file.addHandler("send_tile").addPattern("/tile/[0-9]*/[^I].*") #file = context.addFile("web/frontend/flippage.py") # file.addHandler("send_bookconfig_xml").addPattern("/[0-9]*/bookconfig.xml") # file.addHandler("send_page").addPattern("/[0-9]*/page/[0-9]*\.jpg") # === workflow === #file = context.addFile("web/publish/main.py") # file.addHandler("publish").addPattern("/publish/.*") main_file = file = context.addFile("web/frontend/main.py") handler = file.addHandler("display") handler.addPattern("/") handler.addPattern("/node") file.addHandler("display_noframe").addPattern("/mask") file.addHandler("xmlsearch").addPattern("/xmlsearch") file.addHandler("jssearch").addPattern("/jssearch") file.addHandler("show_parent_node").addPattern("/pnode") file.addHandler("publish").addPattern("/publish/.*") file = context.addFile("web/frontend/popups.py") file.addHandler("popup_metatype").addPattern("/metatype/.*") file.addHandler("popup_fullsize").addPattern("/fullsize") file.addHandler("popup_thumbbig").addPattern("/thumbbig") # file.addHandler("show_index").addPattern("/popup_index") file.addHandler("show_help").addPattern("/popup_help") file.addHandler("show_attachmentbrowser").addPattern("/attachmentbrowser") file.addHandler("show_printview").addPattern("/print/.*") file = context.addFile("web/frontend/shoppingbag.py") file.addHandler("shoppingbag_action").addPattern("/shoppingbag") file = context.addFile("web/frontend/login.py") file.addHandler("login").addPattern("/login") file.addHandler("logout").addPattern("/logout") file.addHandler("pwdforgotten").addPattern("/pwdforgotten") file.addHandler("pwdchange").addPattern("/pwdchange") file = context.addFile("web/frontend/userdata.py") file.addHandler("show_user_data").addPattern("/user") file = context.addFile("workflow/diagram/__init__.py") file.addHandler("send_workflow_diagram").addPattern("/workflowimage") # === admin area === context = athana.addContext("/admin", ".") file = context.addFile("web/admin/main.py") file.addHandler("show_node").addPattern("/(?!export/).*") file.addHandler("export").addPattern("/export/.*") # === edit area === context = athana.addContext("/edit", ".") file = context.addFile("web/edit/edit.py") handler = file.addHandler("frameset") handler.addPattern("/") handler.addPattern("/edit") #file.addHandler("showtree").addPattern("/edit_tree") file.addHandler("edit_tree").addPattern("/treedata") file.addHandler("error").addPattern("/edit_error") #file.addHandler("buttons").addPattern("/edit_buttons") file.addHandler("content").addPattern("/edit_content") file.addHandler("content").addPattern("/edit_content/.*") file.addHandler("action").addPattern("/edit_action") # === ajax tree === context = athana.addContext("/ftree", ".") handler.addPattern("/ftree") file = context.addFile("web/ftree/ftree.py") file.addHandler("ftree").addPattern("/.*") # === help area === context = athana.addContext("/help", '.') file = context.addFile("core/help.py") file.addHandler("getHelp").addPattern("/(?!img/).*") # === services handling === loadServices() # === OAI === context = athana.addContext("/oai/", ".") file = context.addFile("export/oai.py") file.addHandler("oaiRequest").addPattern(".*") # === Export === context = athana.addContext("/export", ".") file = context.addFile("export/export.py") file.addHandler("export").addPattern("/.*") # === static files === athana.addFileStore("/ckeditor/", "lib/CKeditor/files.zip") athana.addFileStore("/css/", "web/css/") athana.addFileStore("/xml/", "web/xml/") athana.addFileStore("/img/", ["web/img/", "web/admin/img/", "web/edit/img/"]) athana.addFileStore("/js/", ["web/js/", "js", "lib/CKeditor/js/"]) # === last: path aliasing for collections === handler = main_file.addHandler("display_alias") handler.addPattern("/[-.~_/a-zA-Z0-9]+$") # 404 handler = main_file.addHandler("display_404") handler.addPattern("/(.)+$") # === theme handling === loadThemes() # === frontend modules handling === try: context = athana.addContext("/modules", ".") file = context.addFile("web/frontend/modules/modules.py") file.addHandler("getContent").addPattern("/.*") except IOError: print "no frontend modules found" #athana.addContext("/flush", ".").addFile("core/webconfig.py").addHandler("flush").addPattern("/py") # === check for ftp usage === if config.get("ftp.activate", "") == "true": # dummy handler for users athana.addFTPHandler( collection_ftpserver(None, port=int(config.get("ftp.port", 21)), debug=config.get("host.type", "testing"))) for collection in tree.getRoot("collections").getChildren(): if collection.get("ftp.user") and collection.get("ftp.passwd"): athana.addFTPHandler( collection_ftpserver(collection, port=int(config.get("ftp.port", 21)), debug=config.get( "host.type", "testing")))
def initContexts(): athana.setBase(".") athana.setTempDir(config.get("paths.tempdir", "/tmp/")) from core.config import resolve_filename from core.translation import translate from core.ftp import collection_ftpserver tal.set_base(".") tal.add_macro_resolver(resolve_filename) tal.add_translator(translate) context = athana.addContext("/", ".") # === public area === file = context.addFile("web/frontend/streams.py") file.addHandler("send_image").addPattern("/images/.*") file.addHandler("send_thumbnail").addPattern("/thumbs/.*") file.addHandler("send_thumbnail2").addPattern("/thumb2/.*") file.addHandler("send_doc").addPattern("/doc/.*") file.addHandler("send_file").addPattern("/file/.*") file.addHandler("send_file_as_download").addPattern("/download/.*") file.addHandler("send_attachment").addPattern("/attachment/.*") file.addHandler("send_attfile").addPattern("/attfile/.*") file.addHandler("get_archived").addPattern("/archive/.*") file.addHandler("get_root").addPattern("/[a-z,0-9,-]*\.[a-z]*") # root directory added /web/root (only files with extensions) file = context.addFile("web/frontend/zoom.py") file.addHandler("send_imageproperties_xml").addPattern("/tile/[0-9]*/ImageProperties.xml") file.addHandler("send_tile").addPattern("/tile/[0-9]*/[^I].*") #file = context.addFile("web/frontend/flippage.py") # file.addHandler("send_bookconfig_xml").addPattern("/[0-9]*/bookconfig.xml") # file.addHandler("send_page").addPattern("/[0-9]*/page/[0-9]*\.jpg") # === workflow === #file = context.addFile("web/publish/main.py") # file.addHandler("publish").addPattern("/publish/.*") main_file = file = context.addFile("web/frontend/main.py") handler = file.addHandler("display") handler.addPattern("/") handler.addPattern("/node") file.addHandler("display_noframe").addPattern("/mask") file.addHandler("xmlsearch").addPattern("/xmlsearch") file.addHandler("jssearch").addPattern("/jssearch") file.addHandler("show_parent_node").addPattern("/pnode") file.addHandler("publish").addPattern("/publish/.*") file = context.addFile("web/frontend/popups.py") file.addHandler("popup_metatype").addPattern("/metatype/.*") file.addHandler("popup_fullsize").addPattern("/fullsize") file.addHandler("popup_thumbbig").addPattern("/thumbbig") # file.addHandler("show_index").addPattern("/popup_index") file.addHandler("show_help").addPattern("/popup_help") file.addHandler("show_attachmentbrowser").addPattern("/attachmentbrowser") file.addHandler("show_printview").addPattern("/print/.*") file = context.addFile("web/frontend/shoppingbag.py") file.addHandler("shoppingbag_action").addPattern("/shoppingbag") file = context.addFile("web/frontend/login.py") file.addHandler("login").addPattern("/login") file.addHandler("logout").addPattern("/logout") file.addHandler("pwdforgotten").addPattern("/pwdforgotten") file.addHandler("pwdchange").addPattern("/pwdchange") file = context.addFile("web/frontend/userdata.py") file.addHandler("show_user_data").addPattern("/user") file = context.addFile("workflow/diagram/__init__.py") file.addHandler("send_workflow_diagram").addPattern("/workflowimage") # === admin area === context = athana.addContext("/admin", ".") file = context.addFile("web/admin/main.py") file.addHandler("show_node").addPattern("/(?!export/).*") file.addHandler("export").addPattern("/export/.*") # === edit area === context = athana.addContext("/edit", ".") file = context.addFile("web/edit/edit.py") handler = file.addHandler("frameset") handler.addPattern("/") handler.addPattern("/edit") #file.addHandler("showtree").addPattern("/edit_tree") file.addHandler("edit_tree").addPattern("/treedata") file.addHandler("error").addPattern("/edit_error") #file.addHandler("buttons").addPattern("/edit_buttons") file.addHandler("content").addPattern("/edit_content") file.addHandler("content").addPattern("/edit_content/.*") file.addHandler("action").addPattern("/edit_action") # === ajax tree === context = athana.addContext("/ftree", ".") handler.addPattern("/ftree") file = context.addFile("web/ftree/ftree.py") file.addHandler("ftree").addPattern("/.*") # === help area === context = athana.addContext("/help", '.') file = context.addFile("core/help.py") file.addHandler("getHelp").addPattern("/(?!img/).*") # === services handling === loadServices() # === OAI === context = athana.addContext("/oai/", ".") file = context.addFile("export/oai.py") file.addHandler("oaiRequest").addPattern(".*") # === Export === context = athana.addContext("/export", ".") file = context.addFile("export/export.py") file.addHandler("export").addPattern("/.*") # === static files === athana.addFileStore("/ckeditor/", "lib/CKeditor/files.zip") athana.addFileStore("/css/", "web/css/") athana.addFileStore("/xml/", "web/xml/") athana.addFileStore("/img/", ["web/img/", "web/admin/img/", "web/edit/img/"]) athana.addFileStore("/js/", ["web/js/", "js", "lib/CKeditor/js/"]) # === last: path aliasing for collections === handler = main_file.addHandler("display_alias") handler.addPattern("/[-.~_/a-zA-Z0-9]+$") # 404 handler = main_file.addHandler("display_404") handler.addPattern("/(.)+$") # === theme handling === loadThemes() # === frontend modules handling === try: context = athana.addContext("/modules", ".") file = context.addFile("web/frontend/modules/modules.py") file.addHandler("getContent").addPattern("/.*") except IOError: print "no frontend modules found" #athana.addContext("/flush", ".").addFile("core/webconfig.py").addHandler("flush").addPattern("/py") # === check for ftp usage === if config.get("ftp.activate", "") == "true": # dummy handler for users athana.addFTPHandler(collection_ftpserver(None, port=int(config.get("ftp.port", 21)), debug=config.get("host.type", "testing"))) for collection in tree.getRoot("collections").getChildren(): if collection.get("ftp.user") and collection.get("ftp.passwd"): athana.addFTPHandler(collection_ftpserver( collection, port=int(config.get("ftp.port", 21)), debug=config.get("host.type", "testing")))
def initContexts(): athana.setBase(config.basedir) athana.setTempDir(config.get("paths.tempdir", "/tmp/")) from core.config import resolve_filename from core.translation import translate, set_language tal.set_base(config.basedir) tal.add_macro_resolver(resolve_filename) tal.add_translator(translate) add_template_globals() @athana.request_started def set_lang(req, *args): set_language(req) # XXX: init our temporary child count cahche from web.frontend import frame frame.init_child_count_cache() context = athana.addContext("/", ".") workflows_enabled = config.getboolean("workflows.activate", True) admin_enabled = config.getboolean("admin.activate", True) edit_enabled = config.getboolean("edit.activate", True) oai_enabled = config.getboolean("oai.activate", False) # === public area === file = context.addFile("web/frontend/filehandlers.py") file.addHandler("send_thumbnail").addPattern("/thumbs/.*") file.addHandler("send_thumbnail2").addPattern("/thumb2/.*") file.addHandler("send_doc").addPattern("/doc/.*") file.addHandler("send_image").addPattern("/image/.*") file.addHandler("redirect_images").addPattern("/images/.*") handler = file.addHandler("send_file") handler.addPattern("/file/.*") handler.addPattern("/download/.*") file.addHandler("send_attachment").addPattern("/attachment/.*") file.addHandler("send_attfile").addPattern("/attfile/.*") file.addHandler("fetch_archived").addPattern("/archive/.*") file.addHandler("send_from_webroot").addPattern("/[a-z,0-9,-]*\.[a-z]*") # root directory added /web/root (only files with extensions) file = context.addFile("web/frontend/zoom.py") file.addHandler("send_imageproperties_xml").addPattern("/tile/[0-9]*/ImageProperties.xml") file.addHandler("send_tile").addPattern("/tile/[0-9]*/[^I].*") main_file = file = context.addFile("web/frontend/main.py") handler = file.addHandler("display") handler.addPattern("/") handler.addPattern("/node") handler = file.addHandler("display_newstyle") handler.addPattern("/nodes/\d+") # /\d+ could also be a node, the handler must check this handler.addPattern("/\d+") if workflows_enabled: file.addHandler("workflow").addPattern("/mask") file.addHandler("show_parent_node").addPattern("/pnode") file.addHandler("publish").addPattern("/publish/.*") file = context.addFile("web/frontend/popups.py") file.addHandler("popup_metatype").addPattern("/metatype/.*") file.addHandler("popup_fullsize").addPattern("/fullsize") file.addHandler("popup_thumbbig").addPattern("/thumbbig") # file.addHandler("show_index").addPattern("/popup_index") file.addHandler("show_help").addPattern("/popup_help") file.addHandler("show_attachmentbrowser").addPattern("/attachmentbrowser") if config.getboolean("config.enable_printing"): file.addHandler("show_printview").addPattern("/print/\d+\.pdf") file.addHandler("redirect_old_printview").addPattern("/print/.*") file = context.addFile("web/frontend/login.py") file.addHandler("login").addPattern("/login") file.addHandler("logout").addPattern("/logout") file.addHandler("pwdforgotten").addPattern("/pwdforgotten") file.addHandler("pwdchange").addPattern("/pwdchange") if workflows_enabled: file = context.addFile("workflow/diagram/__init__.py") file.addHandler("send_workflow_diagram").addPattern("/workflowimage") if admin_enabled: context = athana.addContext("/admin", ".") file = context.addFile("web/handlers/become.py") file.addHandler("become_user").addPattern("/_become/.*") file = context.addFile("web/admin/main.py") file.addHandler("show_node").addPattern("/(?!export/).*") file.addHandler("export").addPattern("/export/.*") if edit_enabled: # === edit area === context = athana.addContext("/edit", ".") file = context.addFile("web/edit/edit.py") handler = file.addHandler("frameset") handler.addPattern("/") handler.addPattern("/edit") file.addHandler("edit_print").addPattern("/print/\d+_.+\.pdf") # file.addHandler("showtree").addPattern("/edit_tree") file.addHandler("edit_tree").addPattern("/treedata") file.addHandler("error").addPattern("/edit_error") # file.addHandler("buttons").addPattern("/edit_buttons") file.addHandler("content").addPattern("/edit_content") file.addHandler("content").addPattern("/edit_content/.*") file.addHandler("action").addPattern("/edit_action") # === ajax tree === context = athana.addContext("/ftree", ".") handler.addPattern("/ftree") file = context.addFile("web/ftree/ftree.py") file.addHandler("ftree").addPattern("/.*") # === services handling === loadServices() # === OAI === if oai_enabled: context = athana.addContext("/oai/", ".") file = context.addFile("export/oai.py") file.addHandler("oaiRequest").addPattern(".*") # === Export === context = athana.addContext("/export", ".") file = context.addFile("web/frontend/export.py") file.addHandler("export").addPattern("/.*") # === static files === athana.addFileStore("/ckeditor/", "lib/CKeditor/files.zip") athana.addFileStore("/css/", "web/css/") athana.addFileStore("/xml/", "web/xml/") athana.addFileStore("/img/", ["web/img/", "web/admin/img/", "web/edit/img/"]) athana.addFileStore("/js/", ["web/js/", "js", "lib/CKeditor/js/"]) # === last: path aliasing for collections === handler = main_file.addHandler("display_alias") handler.addPattern("/([_a-zA-Z][_/a-zA-Z0-9]+)$") # 404 handler = main_file.addHandler("display_404") handler.addPattern("/(.)+$") init_theme() if admin_enabled: import web.newadmin athana.add_wsgi_context("/f/", web.newadmin.app) # testing global exception handler context = athana.addContext("/_test", ".") file = context.addFile("web/handlers/handlertest.py") file.addHandler("error").addPattern("/error") file.addHandler("error_variable_msg").addPattern("/error_variable_msg") file.addHandler("db_error").addPattern("/db_error")
def initHelp(): print "..init help" def addHelpItem(i, part, dict): for j in range(i): dict = dict[part[j]] if part[i] not in dict: dict[part[i]] = {'lang': part[0]} if athana.GLOBAL_ROOT_DIR == "no-root-dir-set": athana.setBase(".") for helppath in helppaths: for root, dirs, filenames in os.walk(helppath): for filename in [f for f in filenames if f.endswith('zip')]: lang = filename.split(".")[0] parts = filename.split(".") if lang not in paths: paths[lang] = [] paths[lang].append(".".join(parts[1:-1])) if ".".join(parts[1:-1]) not in all_paths: all_paths[".".join(parts[1:-1])] = [] if parts[0] not in all_paths[".".join(parts[1:-1])]: all_paths[".".join(parts[1:-1])].append(parts[0]) if ".".join(parts[1:-1]) not in map: map[".".join(parts[1:-1])] = {} if parts[0] not in map[".".join(parts[1:-1])]: map[".".join(parts[1:-1])][parts[0]] = [] c = None for con in athana.contexts: if con.name == "/help/%s/" + "/".join(parts[:-1]) + "/": c = con break if not c: c = athana.addFileStore("/help/" + "/".join(parts[:-1]) + "/", helppath + filename) # translations try: if c.handlers[0].filesystem.isfile('translation.po'): fi = c.handlers[0].filesystem.open('translation.po', 'rb') id = None for line in fi.read().split("\n"): if line.startswith("msgid") or "msgid " in line: id = re.sub(r'^\"|\"$', '', " ".join(line.split(" ")[1:]).strip()) elif line.startswith("msgstr"): map[".".join(parts[1:-1])][parts[0]].append((id, re.sub(r'^\"|\"$', '', line[6:].strip()))) fi.close() translation.addLabels(map[".".join(parts[1:-1])]) except: pass # index values if lang not in index.keys(): index[lang] = {} if c.handlers[0].filesystem.isfile('index.txt'): fi = c.handlers[0].filesystem.open('index.txt', 'rb') for line in re.sub(r'\r', '', fi.read()).strip().split("\n"): if line not in index[lang]: index[lang][line] = [] if filename.replace("index.txt", "") not in index[lang][line]: index[lang][line].append(filename.replace("index.txt", "")) # help items for i in range(len(parts) - 1): try: addHelpItem(i, parts, items) except: pass