Ejemplo n.º 1
0
    def get_cached_data():
        """Get current data and update cache."""
        cache_read = False
        typesetting_data = {}

        try:
            with open(cache_filename, "rb") as storage:
                typesetting_data = load(storage)
                cache_read = True

            cache_data_outdated = getmtime(file_path) < getmtime(cache_filename) > getmtime(filepath)

            # Write new cache data if the current data does not contain
            # the necessary up to date information - This might be the case if
            # only `texparser` has written to the cache file
            if "engine" not in typesetting_data or cache_data_outdated:
                raise Exception()

        except:
            # Get data and save it in the cache
            packages = find_tex_packages(filename, ignore_warnings)
            engine = construct_engine_command(typesetting_directives, tm_engine, packages)
            synctex = not (bool(call("{} --help | grep -q synctex".format(engine), shell=True)))
            typesetting_data.update({"engine": engine, "packages": packages, "synctex": synctex})
            if not cache_read:
                typesetting_data["files_with_guttermarks"] = {filename}

        try:
            with open(cache_filename, "wb") as storage:
                dump(typesetting_data, storage)
        except:
            print('<p class="warning"> Could not write cache file!</p>')

        return typesetting_data
Ejemplo n.º 2
0
    def get_cached_data():
        """Get current data and update cache."""
        cache_read = False
        typesetting_data = {}

        try:
            with open(cache_filename, 'rb') as storage:
                typesetting_data = load(storage)
                cache_read = True

            cache_data_outdated = (getmtime(file_path) <
                                   getmtime(cache_filename) >
                                   getmtime(filepath))

            # Write new cache data if the current data does not contain
            # the necessary up to date information - This might be the case if
            # only `texparser` has written to the cache file
            if 'engine' not in typesetting_data or cache_data_outdated:
                raise Exception()

        except:
            # Get data and save it in the cache
            packages = find_tex_packages(filename, ignore_warnings)
            engine = construct_engine_command(typesetting_directives,
                                              tm_engine, packages)
            synctex = not (bool(
                call("{} --help | grep -q synctex".format(engine),
                     shell=True)))
            typesetting_data.update({
                'engine': engine,
                'packages': packages,
                'synctex': synctex
            })
            if not cache_read:
                typesetting_data['files_with_guttermarks'] = {filename}

        try:
            with open(cache_filename, 'wb') as storage:
                dump(typesetting_data, storage)
        except:
            print('<p class="warning"> Could not write cache file!</p>')

        return typesetting_data
Ejemplo n.º 3
0
    # If the caret is right next to or between a word, then we show the
    # documentation for that word using the the shell command `texdoc`
    tm_current_word = getenv('TM_CURRENT_WORD')
    if tm_current_word:
        output = check_output("texdoc {}".format(shellquote(tm_current_word)),
                              shell=True).strip()
        # Close the html output window on success
        if not output:
            exit(200)

    # Find all the packages included in the file or its inputs
    master_file, master_dir = find_file_to_typeset(
        find_tex_directives(getenv("TM_FILEPATH")))
    chdir(master_dir)
    packages = find_tex_packages(master_file)

    texmf_directory = check_output("kpsewhich --expand-path '$TEXMFMAIN'",
                                   shell=True,
                                   universal_newlines=True).strip()
    docdbpath = "{}/Library/Caches/TextMate".format(expanduser('~'))
    docdbfile = "{}/latexdocindex".format(docdbpath)

    if exists(docdbfile) and getmtime(docdbfile) > getmtime(texmf_directory):
        # Read from cache
        with open(docdbfile, 'rb') as cache:
            paths, descriptions, headings = load(cache)
    else:
        # Parse the texdoctk database
        docfiles = get_documentation_files(texmf_directory)
        paths, descriptions, headings = parse_texdoctk_data(
Ejemplo n.º 4
0
if __name__ == "__main__":

    # If the caret is right next to or between a word, then we show the
    # documentation for that word using the the shell command `texdoc`
    tm_current_word = getenv("TM_CURRENT_WORD")
    if tm_current_word:
        output = check_output("texdoc {}".format(shellquote(tm_current_word)), shell=True).strip()
        # Close the html output window on success
        if not output:
            exit(200)

    # Find all the packages included in the file or its inputs
    master_file, master_dir = find_file_to_typeset(find_tex_directives(getenv("TM_FILEPATH")))
    chdir(master_dir)
    packages = find_tex_packages(master_file)

    texmf_directory = check_output("kpsewhich --expand-path '$TEXMFMAIN'", shell=True, universal_newlines=True).strip()
    docdbpath = "{}/Library/Caches/TextMate".format(expanduser("~"))
    docdbfile = "{}/latexdocindex".format(docdbpath)

    if exists(docdbfile) and getmtime(docdbfile) > getmtime(texmf_directory):
        # Read from cache
        with open(docdbfile, "rb") as cache:
            paths, descriptions, headings = load(cache)
    else:
        # Parse the texdoctk database
        docfiles = get_documentation_files(texmf_directory)
        paths, descriptions, headings = parse_texdoctk_data(docfiles, texmf_directory)

        # Supplement with searched for files