Пример #1
0
def compile_sketch(sketch_name,
                   generate_index=False,
                   index_template=None,
                   force_local=False):
    """
    Transcrypt the sketch python code to javascript.

    :param sketch_name: name for new sketch
    :param generate_index: boolean to flag if the index.html file should be updated
    :param force_local: boolean to flag to force local run (used by web editor only)
    :type sketch_name: string
    :return: file names
    :rtype: list of strings
    """

    sketch = Sketch(sketch_name)
    sketch.validate_name()

    if not sketch.sketch_exists:
        raise PythonSketchDoesNotExist(sketch)

    compile_sketch_js(sketch, force_local=force_local)
    if generate_index:
        # to be able to overwrite default index template file
        # useful for generating the docs or debugging
        sketch.config.index_template = index_template
        index_contet = get_sketch_index_content(sketch)
        with open(sketch.index_html, "w", encoding="utf-8") as fd:
            fd.write(index_contet)
        cprint.info(f"{sketch.index_html.resolve()} updated")

    return sketch
Пример #2
0
def transcrypt_sketch(sketch_name):
    """
    Transcrypt the sketch python code to javascript.

    :param sketch_name: name for new sketch
    :type sketch_name: string
    :return: file names
    :rtype: list of strings
    """

    sketch_files = SketchFiles(sketch_name)
    if not sketch_files.sketch_exists:
        raise PythonSketchDoesNotExist(sketch_files.sketch_py.resolve())

    compile_sketch_js(sketch_files)
    return sketch_files
Пример #3
0
def compile_sketch(sketch_name):
    """
    Transcrypt the sketch python code to javascript.

    :param sketch_name: name for new sketch
    :type sketch_name: string
    :return: file names
    :rtype: list of strings
    """

    sketch = Sketch(sketch_name)
    sketch.validate_name()

    if not sketch.sketch_exists:
        raise PythonSketchDoesNotExist(sketch)

    compile_sketch_js(sketch)
    return sketch
Пример #4
0
def monitor_sketch(sketch_name):
    """
    Monitor for any change in any .py inside the sketch dir.
    For every new change, runs the transcrypt to update the js files.

    :param sketch_name: name for new sketch
    :type sketch_name: string
    :return: file names
    :rtype: list of strings
    """

    sketch_files = SketchFiles(sketch_name)
    if not sketch_files.sketch_exists:
        raise PythonSketchDoesNotExist(sketch_files.sketch_py.resolve())

    cprint(f"Monitoring for changes in {sketch_files.sketch_dir.resolve()}...")

    try:
        monitor_sketch_service(sketch_files)
    except KeyboardInterrupt:
        cprint.info("Exiting monitor...")