def update_all_pages_list_cache(folder_pages_full_path): buf = shell.get_page_file_list_by_req_path( folder_pages_full_path=folder_pages_full_path, req_path="~all") path = os.path.join(folder_pages_full_path, ".zw_all_pages_list_cache") with open(path, "w") as f: f.write(buf)
def update_recent_change_cache(folder_pages_full_path): path = os.path.join(folder_pages_full_path, ".zw_recent_changes_cache") buf = shell.get_page_file_list_by_req_path(folder_pages_full_path = folder_pages_full_path, req_path = "~recent", sort_by_modified_ts = True) with open(path, "w") as f: f.write(buf)
def code_repl(match_obj): code = match_obj.group('code') code = code.split("\n")[1] if code.startswith("ls("): p = 'ls\("(?P<path>.+?)",\s*maxdepth\s*=\s*(?P<maxdepth>\d+)\s*\)' m = re.match(p, code, re.UNICODE | re.MULTILINE) req_path = m.group("path") full_path = os.path.join(folder_pages_full_path, req_path) max_depth = int(m.group("maxdepth")) if os.path.exists(full_path): buf = shell.get_page_file_list_by_req_path(req_path = req_path, max_depth = max_depth, folder_pages_full_path = folder_pages_full_path) buf = sequence_to_unorder_list(buf.split("\n"), **view_settings) else: buf = "" return buf buf_fixed = "{{{#!zw\n%s\n}}}" % code return buf_fixed
def wp_read(config_agent, tpl_render, req_path): view_settings = get_view_settings(config_agent) folder_pages_full_path = config_agent.get_full_path("paths", "pages_path") local_full_path = mdutils.req_path_to_local_full_path(req_path, folder_pages_full_path) static_file_prefix = static_file.get_static_file_prefix_by_local_full_path(config_agent = config_agent, local_full_path = local_full_path, req_path = req_path) path_info = web.ctx.environ["PATH_INFO"] HOME_PAGE = "" if req_path != HOME_PAGE and view_settings["button_mode_path"]: buf = mdutils.text_path_to_button_path("/%s" % req_path) button_path = mdutils.md2html(config_agent = config_agent, req_path = req_path, text = buf, static_file_prefix = static_file_prefix, **view_settings) else: button_path = None view_settings["show_quick_links"] = False if os.path.isfile(local_full_path): # os.path.exists(local_full_path) buf = commons.shutils.cat(local_full_path) buf = commons.strutils.strip_bom(buf) elif os.path.isdir(local_full_path): # os.path.exists(local_full_path) if req_path == HOME_PAGE: a = os.path.join(local_full_path, "index.md") b = os.path.join(local_full_path, "index.markdown") if os.path.exists(a) or os.path.exists(b): fixed_req_path = os.path.join(path_info, "index") return web.seeother(fixed_req_path) else: fixed_req_path = os.path.join(path_info, "~all") return web.seeother(fixed_req_path) else: # listdir /path/to/folder/* buf = shell.get_page_file_list_by_req_path(folder_pages_full_path = folder_pages_full_path, req_path = req_path) if buf: buf = mdutils.sequence_to_unorder_list(buf.split("\n"), **view_settings) else: buf = "folder `%s` exists, but there is no files" % path_info else: # not os.path.exists(local_full_path) if path_info.endswith("/"): fixed_req_path = path_info + "index?action=update" else: fixed_req_path = path_info + "?action=update" return web.seeother(fixed_req_path) title = mdutils.get_title_from_md(local_full_path = local_full_path) content = mdutils.md2html(config_agent = config_agent, req_path = req_path, text = buf, static_file_prefix = static_file_prefix, **view_settings) static_files = get_the_same_folders_cssjs_files(req_path = req_path, local_full_path = local_full_path, folder_pages_full_path = folder_pages_full_path) if not static_files: static_files = static_file.get_global_static_files(**view_settings) + "\n" buf = tpl_render.canvas(config = config_agent.config, static_files = static_files, button_path = button_path, req_path = req_path, title = title, content = content, **view_settings) return buf
def update_all_pages_list_cache(folder_pages_full_path): buf = shell.get_page_file_list_by_req_path(folder_pages_full_path=folder_pages_full_path, req_path="~all") path = os.path.join(folder_pages_full_path, ".zw_all_pages_list_cache") with open(path, "w") as f: f.write(buf)
def wp_read(config_agent, tpl_render, req_path): view_settings = get_view_settings(config_agent) folder_pages_full_path = config_agent.get_full_path("paths", "pages_path") local_full_path = mdutils.req_path_to_local_full_path( req_path, folder_pages_full_path) static_file_prefix = static_file.get_static_file_prefix_by_local_full_path( config_agent=config_agent, local_full_path=local_full_path, req_path=req_path) path_info = web.ctx.environ["PATH_INFO"] HOME_PAGE = "" if req_path != HOME_PAGE and view_settings["button_mode_path"]: buf = mdutils.text_path_to_button_path("/%s" % req_path) button_path = mdutils.md2html(config_agent=config_agent, req_path=req_path, text=buf, static_file_prefix=static_file_prefix, **view_settings) else: button_path = None view_settings["show_quick_links"] = False title = "" if os.path.isfile(local_full_path): # os.path.exists(local_full_path) buf = commons.shutils.cat(local_full_path) buf = commons.strutils.strip_bom(buf) title = mdutils.get_title_by_file_path_in_md( folder_pages_full_path=folder_pages_full_path, file_path_suffix=local_full_path) elif os.path.isdir(local_full_path): # os.path.exists(local_full_path) if req_path == HOME_PAGE: a = os.path.join(local_full_path, "index.md") b = os.path.join(local_full_path, "index.markdown") if os.path.exists(a) or os.path.exists(b): fixed_req_path = os.path.join(path_info, "index") return web.seeother(fixed_req_path) else: fixed_req_path = os.path.join(path_info, "~all") return web.seeother(fixed_req_path) else: # listdir /path/to/folder/* buf = shell.get_page_file_list_by_req_path( folder_pages_full_path=folder_pages_full_path, req_path=req_path) if buf: buf = mdutils.sequence_to_unorder_list( folder_pages_full_path=folder_pages_full_path, seq=buf.split("\n"), **view_settings) title = req_path else: buf = "folder `%s` exists, but there is no files" % path_info else: # not os.path.exists(local_full_path) readonly = config_agent.config.get("main", "readonly") if readonly: raise web.Forbidden() else: if path_info.endswith("/"): fixed_req_path = path_info + "index?action=update" else: fixed_req_path = path_info + "?action=update" return web.seeother(fixed_req_path) content = mdutils.md2html(config_agent=config_agent, req_path=req_path, text=buf, static_file_prefix=static_file_prefix, **view_settings) static_files = get_the_same_folders_cssjs_files( req_path=req_path, local_full_path=local_full_path, folder_pages_full_path=folder_pages_full_path) if not static_files: static_files = static_file.get_global_static_files( **view_settings) + "\n" buf = tpl_render.canvas(config=config_agent.config, static_files=static_files, button_path=button_path, req_path=req_path, title=title, content=content, **view_settings) return buf