Esempio n. 1
0
def trace(filename: str,
          blackAndWhite: bool = False,
          mode: str = "default") -> str:
    """Do a trace of an image on the filesystem using the pyppeteer library.

	Args:
		filename (str): The location of the file on the filesystem, use an
		absolute filepath for this
		blackAndWhite (bool, optional): Trace a black and white SVG. Defaults to False.
		mode (str, optional): Set the mode. See https://github.com/jankovicsandras/imagetracerjs
		for more information. Defaults to "default".

	Returns:
		str: SVG string
	"""
    if mode.find("black") >= 0 or blackAndWhite:
        mode = "posterized1"
    try:
        return asyncio.get_event_loop().run_until_complete(
            doTrace(filename.replace("\\", "/"), mode))
    except ConnectionResetError:
        Logger(FHFormatter()).logPrint(
            "ConnectionResetError - probably just a hiccup " + "retrying",
            LogType.WARNING)
        return asyncio.get_event_loop().run_until_complete(
            doTrace(filename.replace("\\", "/"), mode))
Esempio n. 2
0
def openColourSwatch(file: str) -> ColourSwatch:
    """Open a colour swatch file into a layer image object
	Args:
		file (str): path/ filename
	Returns:
		ColourSwatch: a colour swatch object
	"""
    functionMap = {
        "gpl": openSwatch_GPL,
        "yaml": openSwatch_YAML,
        "colors": openSwatch_COLOR,
        "spl": openSwatch_SPL,
        "skp": openSwatch_SKP,
        "soc": openSwatch_SOC,
        "txt": openSwatch_TXT,
        "acbl": openSwatch_ACBL,
        "xml": openSwatch_XML,
        "pal": openSwatch_CDPAL,
        "hpl": openSwatch_HPL,
        "toml": openSwatch_TOML,
        "json": openSwatch_JSON,
        "png": openSwatch_PNG,
        "jpg": openSwatch_IMAGE,
        "webp": openSwatch_IMAGE,
        "ase": openSwatch_ASE,
        "svg": openSwatch_SVG
    }
    if not exists(file):
        Logger(FHFormatter()).logPrint(file + " does not exist", LogType.ERROR)
        raise FileExistsError
    fileExt = file.split(".")[-1].lower()
    if fileExt not in functionMap:
        extNotRecognised(file)
        raise ValueError
    return functionMap[fileExt](file)
Esempio n. 3
0
def extNotRecognised(fileName: str):
    """ Output the file extension not recognised error """
    exts = [
        "gpl", "yaml", "colors", "spl", "skp", "soc", "txt", "acbl", "xml",
        "pal", "hpl", "toml", "json", "ase", "png", "jpg", "webp", "svg"
    ]
    Logger(FHFormatter()).logPrint(
        "File extension is not recognised for file: " + fileName +
        "! Must be " + "one of \"" + ", \"".join(exts) + "\"", LogType.ERROR)
Esempio n. 4
0
metLogger.logPrint("none", LogType.NONE)
metLogger.logPrint("bold indent", LogType.BOLD, True)
metLogger.logPrint("italic indent", LogType.ITALIC, True)
metLogger.logPrint("header", LogType.HEADER)
metLogger.logPrint("debug", LogType.DEBUG)
metLogger.logPrint("info", LogType.INFO)
metLogger.logPrint("success", LogType.SUCCESS)
metLogger.logPrint("warning", LogType.WARNING)
metLogger.logPrint("error", LogType.ERROR)
metLogger.logPrint("critical", LogType.CRITICAL)


print("#########################")
print("#          FH           #")
print("#########################")
fhLogger = Logger(FHFormatter())
fhLogger.logPrint("none", LogType.NONE)
fhLogger.logPrint("bold indent", LogType.BOLD, True)
fhLogger.logPrint("italic indent", LogType.ITALIC, True)
fhLogger.logPrint("header", LogType.HEADER)
fhLogger.logPrint("debug", LogType.DEBUG)
fhLogger.logPrint("info", LogType.INFO)
fhLogger.logPrint("success", LogType.SUCCESS)
fhLogger.logPrint("warning", LogType.WARNING)
fhLogger.logPrint("error", LogType.ERROR)
fhLogger.logPrint("critical", LogType.CRITICAL)

print("#########################")
print("#         FHNF          #")
print("#########################")
fhnfLogger = Logger(FHNFFormatter())
Esempio n. 5
0
def extNotLossless(fileName):
    """ Output the file extension not lossless error """
    Logger(FHFormatter()).logPrint(
        "File extension is not lossless: " + fileName + "! Must be " +
        "one of \"" + ", \"".join(exts) + "\"", LogType.ERROR)
Esempio n. 6
0
def extNotSupported(fileName):
    """ Output the file extension not supported error """
    exts = ["jpg", "png", "gif"]
    Logger(FHFormatter()).logPrint(
        "File extension is not supported for file: " + fileName +
        "! Must be " + "one of \"" + ", \"".join(exts) + "\"", LogType.ERROR)
Esempio n. 7
0
"""Shared utils used by the other builder components
"""
import os
import sys
import asyncio
from contextlib import contextmanager
import yaml
from metprint import LogType, Logger, FHFormatter

printf = Logger(FHFormatter())


class JobOptions:
    """Container for options related to job processing"""
    def __init__(self, **kwargs):
        for k, v in kwargs.items():
            setattr(self, k, v)


CWD = os.path.realpath(os.getcwd())


@contextmanager
def compat_event_loop():
    """OS agnostic context manager for an event loop."""
    if sys.platform.startswith("win"):
        asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())

    event_loop = asyncio.get_event_loop()

    if event_loop.is_closed():