예제 #1
0
 def evaluate_queries(self, queries):
     hashes = []
     for query, digest in queries.items():
         parameters = js.loads(query)
         documents = self._run_query(parameters)
         hashes.append(
             utils.hash_items([document.mtime for document in documents]))
     return hashes
예제 #2
0
파일: build.py 프로젝트: pvinis/incontext
 def render(url):
     path, queries, hashes = website.render(document=document)
     return {
         "files": [path],
         "queries":
         queries,
         "mtime":
         utils.hash_items([template_hash, document.hash] + hashes)
     }
예제 #3
0
 def hash(self):
     return utils.hash_items([self.mtime])
예제 #4
0
 def add(self, parameters, documents):
     mtimes = [document.mtime for document in documents]
     self.queries[js.dumps(parameters)] = utils.hash_items(mtimes)
예제 #5
0
파일: build.py 프로젝트: pvinis/incontext
def process_files(incontext, options, handlers):
    document_store = store.DocumentStore(
        incontext.configuration.site.destination.store_path)
    incontext.environment[DOCUMENT_STORE] = document_store

    logging.info("Generating intermediates...")
    phase1 = Phase(
        os.path.join(incontext.configuration.site.destination.root_directory,
                     "phase-1-generate-intermediates.json"),
        incontext.configuration.site.paths.content, document_store)
    for task in handlers:
        fn = incontext.get_handler(task["then"])
        args = task["args"] if "args" in task else {}
        phase1.add_task(
            task['when'],
            fn(incontext,
               from_directory=incontext.configuration.site.paths.content,
               to_directory=incontext.configuration.site.destination.
               files_directory,
               **args))
    phase1.process()

    # Renders are dependent on the templates, so we hash all the templates and add this into the hash for the page
    # renders to ensure everything is re-rendered whenever a template changes. It should be possible to track the
    # templates used in render in the future if we need to make this faster.
    templates = [
        os.path.join(*paths) for paths in utils.find_files(
            incontext.configuration.site.paths.templates)
    ]
    template_mtimes = [os.path.getmtime(path) for path in templates]
    template_hash = utils.hash_items(template_mtimes)

    logging.info("Render content cache...")
    cache_path = os.path.join(
        incontext.configuration.site.destination.root_directory,
        "phase-6-render-content.json")
    render_change_tracker = tracker.ChangeTracker(cache_path)
    website = Website(incontext=incontext)
    for document in website.documents():

        def render_outer(document):
            def render(url):
                path, queries, hashes = website.render(document=document)
                return {
                    "files": [path],
                    "queries":
                    queries,
                    "mtime":
                    utils.hash_items([template_hash, document.hash] + hashes)
                }

            return render

        queries = {}
        try:
            queries = render_change_tracker.get_info(
                path=document.url)["queries"]
        except KeyError:
            pass
        hash = utils.hash_items([template_hash, document.hash] +
                                document.evaluate_queries(queries))
        render_change_tracker.add(path=document.url,
                                  create=render_outer(document),
                                  mtime=hash)
    render_change_tracker.commit(
        cleanup(root=incontext.configuration.site.destination.root_directory,
                document_store=document_store))

    touch(incontext.configuration.site.destination.store_path)