Example #1
0
def serve():
    config = Config()
    config = config.load_config()
    if not os.path.isdir(config['output_dir']):
        print('Output files not found...building...')
        build()

    port = 8000
    host = '0.0.0.0'
    try:
        from tornado import ioloop
        from tornado import web
        application = web.Application([
            (r"/(.*)", web.StaticFileHandler, {
                "path": config['output_dir'],
                "default_filename": "index.html"
            })
        ])
        application.listen(port=port, address=host)
        print('Running at: http://{0}:{1}/'.format(host, port))
        try:
            ioloop.IOLoop.instance().start()
        except KeyboardInterrupt:
            print('Stopping server...')
    except:
        import SimpleHTTPServer
        import SocketServer
        os.chdir(config['output_dir'])
        Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
        httpd = SocketServer.TCPServer((host, port), Handler)
        httpd.allow_reuse_address = True
        print('Running at: http://{0}:{1}/'.format(host, port))
        httpd.serve_forever()
Example #2
0
def build():
    config = Config()
    config, env = config.load_all()
    context = Context()
    context.update(config)
    tags = {}
    categories = {}
    # env = template_init()
    mds = md_files_generator(config['source_dir'])
    notes = []
    print('Building notes...')
    before = time.time()
    count = 0
    for md in mds:
        note = Note(md, config, tags, categories)
        note.render(env, context.note)
        notes.append(note)
        count += 1
        print( ' ' * 10 + note.title)
    now = time.time()
    print("Generate {0} entries in {1:.3f}s".format(count, now-before))
    before = time.time()
    print('Building index...')
    for tag in tags:
        tags[tag].render(env, context.tag)
    for cate in categories:
        categories[cate].render(env, context.category)
    index = Index(config)
    index.render(env, context.index, notes, categories=categories.values(),
                 tags=tags.values())
    now = time.time()
    print("Generate index in {0:.3f}s".format(now-before))
Example #3
0
def serve():
    config = Config()
    config = config.load_config()
    if not os.path.isdir(config['output_dir']):
        print('Output files not found...building...')
        build()

    port = 8000
    host = '0.0.0.0'
    try:
        from tornado import ioloop
        from tornado import web
        application = web.Application([(r"/(.*)", web.StaticFileHandler, {
            "path": config['output_dir'],
            "default_filename": "index.html"
        })])
        application.listen(port=port, address=host)
        print('Running at: http://{0}:{1}/'.format(host, port))
        try:
            ioloop.IOLoop.instance().start()
        except KeyboardInterrupt:
            print('Stopping server...')
    except:
        import SimpleHTTPServer
        import SocketServer
        os.chdir(config['output_dir'])
        Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
        httpd = SocketServer.TCPServer((host, port), Handler)
        httpd.allow_reuse_address = True
        print('Running at: http://{0}:{1}/'.format(host, port))
        httpd.serve_forever()
Example #4
0
def build():
    config = Config()
    config, env = config.load_all()
    context = Context()
    context.update(config)
    tags = {}
    categories = {}
    # env = template_init()
    mds = md_files_generator(config['source_dir'])
    notes = []
    print('Building notes...')
    before = time.time()
    count = 0
    for md in mds:
        note = Note(md, config, tags, categories)
        note.render(env, context.note)
        notes.append(note)
        count += 1
        print(' ' * 10 + note.title)
    now = time.time()
    print("Generate {0} entries in {1:.3f}s".format(count, now - before))
    before = time.time()
    print('Building index...')
    for tag in tags:
        tags[tag].render(env, context.tag)
    for cate in categories:
        categories[cate].render(env, context.category)
    index = Index(config)
    index.render(env,
                 context.index,
                 notes,
                 categories=categories.values(),
                 tags=tags.values())
    now = time.time()
    print("Generate index in {0:.3f}s".format(now - before))
Example #5
0
def cleanup():
    config = Config()
    config = config.load_config()
    try:
        shutil.rmtree(config['output_dir'])
    except:
        prt_exit('Can not cleanup directory {0}\n'
                 'Maybe it does not exist or '
                 'we have permission issue'.format(config['output_dir']))
Example #6
0
def cleanup():
    config = Config()
    config = config.load_config()
    try:
        shutil.rmtree(config['output_dir'])
    except:
        prt_exit('Can not cleanup directory {0}\n'
                 'Maybe it does not exist or '
                 'we have permission issue'.format(config['output_dir']))