def wiki(request, tmp_path): config = hatta.WikiConfig( pages_path=os.path.join(tmp_path, 'pages'), cache_path=os.path.join(tmp_path, 'cache'), ) request.addfinalizer(lambda: clear_directory(tmp_path)) return hatta.Wiki(config)
def pytest_funcarg__wiki(request): basedir = str(request.config.ensuretemp('repo')) config = hatta.WikiConfig( pages_path=os.path.join(basedir, 'pages'), cache_path=os.path.join(basedir, 'cache'), ) request.addfinalizer(lambda: clear_directory(basedir)) return hatta.Wiki(config)
def main(args): hatta_config = hatta.WikiConfig() hatta_config.parse_files(files=[args.input_config]) hatta_config.set('read_only', True) wiki = hatta.Wiki(hatta_config) # list of all page names page_names = list(wiki.storage.all_pages()) mkdir_p(args.output_dir) print('Converting %d wiki entries' % len(page_names)) for page_name in page_names: convert_page(page_name, wiki=wiki, out_dir=args.output_dir, file_prefix=args.file_prefix, files_in_one_dir=args.files_in_one_dir, add_link_ext=args.add_link_ext) print('Done!')
def req(request, tmp_path): request.addfinalizer(lambda: clear_directory(tmp_path)) config = hatta.WikiConfig( pages_path=os.path.join(tmp_path, 'pages'), cache_path=os.path.join(tmp_path, 'cache'), default_style="...", ) wiki = hatta.Wiki(config) environ = { 'SERVER_NAME': 'hatta', 'wsgi.url_scheme': 'http', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/', 'SCRIPT_NAME': '', } adapter = wiki.url_map.bind_to_environ(environ) return wiki, hatta.WikiRequest(wiki, adapter, environ)
def load_from_config(self, conf_file): config = hatta.WikiConfig() config.parse_files([conf_file]) config.sanitize() wiki = hatta.Wiki(config, site_id=conf_file) # file name is the domain name _path # if the path is set, use the dispatcher middleware splitname = os.path.basename(os.path.splitext(conf_file)[0]).split( '_', 1) domain_name = splitname[0] if len(splitname) == 2: self.apps.setdefault( domain_name, DispatcherMiddleware(self.default_application, None)).mounts[ '/' + splitname[1].replace('_', '/')] = wiki.application else: self.apps[domain_name] = wiki.application
def pytest_funcarg__req(request): basedir = str(request.config.ensuretemp('repo')) request.addfinalizer(lambda: clear_directory(basedir)) config = hatta.WikiConfig( pages_path=os.path.join(basedir, 'pages'), cache_path=os.path.join(basedir, 'cache'), default_style="...", ) wiki = hatta.Wiki(config) environ = { 'SERVER_NAME': 'hatta', 'wsgi.url_scheme': 'http', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/', 'SCRIPT_NAME': '', } adapter = wiki.url_map.bind_to_environ(environ) return wiki, hatta.WikiRequest(wiki, adapter, environ)
""" An example of how you can extend Hatta's parser without touching the original code. """ import hatta class MyWikiParser(hatta.WikiParser): """Alternative WikiParser that uses smilies with noses.""" smilies = { r':-)': "smile.png", r':-(': "frown.png", r':-P': "tongue.png", r':-D': "grin.png", r';-)': "wink.png", } class MyWikiPageWiki(hatta.WikiPageWiki): def __init__(self, *args, **kw): super(MyWikiPageWiki, self).__init__(*args, **kw) self.parser = MyWikiParser if __name__=='__main__': config = hatta.read_config() wiki = hatta.Wiki(config) wiki.mime_map['text/x-wiki'] = MyWikiPageWiki hatta.main(wiki=wiki)
#! /usr/bin/env python # -*- coding: utf-8 -*- """ An auto-reloading standalone wiki server, useful for development. """ import hatta import werkzeug if __name__=="__main__": config = hatta.WikiConfig() config.parse_args() # config.parse_files() application = hatta.Wiki(config).application host = config.get('interface', 'localhost') port = int(config.get('port', 8080)) werkzeug.run_simple(host, port, application, use_reloader=True)