コード例 #1
0
ファイル: action.py プロジェクト: apg/stationary
def build(config):
    """Rebuilds the site.
    """
    sanity_check(config)

    src_dir = osp.abspath(config.src_directory)
    build_dir = osp.abspath(config.build_directory)
    build_data_dir = osp.abspath(config.build_data_directory)

    for root, dirs, files in os.walk(config.src_directory):
        for f in files:
            root = osp.abspath(root)
            src_file = osp.join(root, f)
            dest_file = reroot(src_file, srcdir=src_dir, destdir=build_dir)
            build_file(config, src_file, dest_file)

            if f.endswith('.html'):
                dest_data_file = reroot(src_file,
                                        srcdir=src_dir,
                                        destdir=build_data_dir)
                build_data(config, src_file, dest_data_file)

    # build global data
    global_file = osp.join(config.data_directory, config.base_context_filename)
    global_dest = reroot(global_file,
                         srcdir=config.data_directory,
                         destdir=build_data_dir)
    build_data(config, global_file, global_dest)
コード例 #2
0
ファイル: action.py プロジェクト: apg/stationary
        def do_GET(self):
            """Build/cache and serve a page"""
            src_dir = osp.abspath(config.src_directory)
            build_dir = osp.abspath(config.build_directory)

            try:
                if self.path == '/':
                    self.path = '/index.html'

                base_ctx = config.base_context() or {}
                src_file = osp.join(src_dir, self.path[1:])

                dest_file = reroot(src_file, srcdir=src_dir, destdir=build_dir)

                # don't even check if file exists, raise an error if it doesn't
                try:
                    dest_file = build_file(config, src_file, dest_file)
                    self.send_response(200)
                    self.send_header('Content-Type', mimeof(dest_file))
                    self.end_headers()

                    with open(dest_file) as f:
                        self.wfile.write(f.read())
                except IOError:
                    self.send_response(404)
                    self.send_header('Content-Type', 'text/plain')
                    self.wfile.write("404 Not found")
            except:
                self.send_response(500)
                self.send_header('Content-Type', 'text/plain')
                self.end_headers()
                traceback.print_exc(file=self.wfile)