mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 08:48:13 +00:00
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import logging
|
|
import os
|
|
import subprocess
|
|
|
|
logger = logging.getLogger()
|
|
SUBPROCESS_TIMEOUT = 5
|
|
|
|
|
|
class BaseRenderEngine(object):
|
|
|
|
install_paths = []
|
|
supported_extensions = []
|
|
|
|
@classmethod
|
|
def name(cls):
|
|
return cls.__name__.lower()
|
|
|
|
@classmethod
|
|
def renderer_path(cls):
|
|
path = None
|
|
try:
|
|
path = subprocess.check_output(['which', cls.name()], timeout=SUBPROCESS_TIMEOUT).decode('utf-8').strip()
|
|
except subprocess.CalledProcessError:
|
|
for p in cls.install_paths:
|
|
if os.path.exists(p):
|
|
path = p
|
|
except Exception as e:
|
|
logger.exception(e)
|
|
return path
|
|
|
|
@classmethod
|
|
def version(cls):
|
|
raise NotImplementedError("version not implemented")
|
|
|
|
@classmethod
|
|
def get_help(cls):
|
|
path = cls.renderer_path()
|
|
if not path:
|
|
raise FileNotFoundError("renderer path not found")
|
|
help_doc = subprocess.check_output([path, '-h'], stderr=subprocess.STDOUT,
|
|
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
|
|
return help_doc
|
|
|
|
@classmethod
|
|
def get_output_formats(cls):
|
|
raise NotImplementedError(f"get_output_formats not implemented for {cls.__name__}") |