Exemple #1
0
def init_paths(prj_name=None, env_path=None):
    if env_path:
        get_environ(env_path)

    cfg = get_main_paths(prj_name)

    tmp = []
    for pos in sys.path:
        if not pos in tmp:
            if not pos.startswith('.'):
                tmp.append(pos)
    sys.path = tmp

    from pytigon_lib.schtools.platform_info import platform_name

    base_path = os.path.dirname(os.path.abspath(__file__))
    pname = platform_name()

    if pname == 'Android':
        p = os.path.abspath(os.path.join(base_path, "..", "_android"))
        p2 = os.path.abspath(os.path.join(base_path, "..", "ext_lib"))
        if not p in sys.path: sys.path.insert(0, p)
        if not p2 in sys.path: sys.path.append(p2)
    else:
        if pname == "Windows":
            p = os.path.abspath(
                os.path.join(base_path, "..", "python"
                             "lib", "site-packages"))
        else:
            p = os.path.abspath(os.path.join(base_path , "..", "python", "lib",\
                "python%d.%d/site-packages" % (sys.version_info[0], sys.version_info[1])))

        p2 = os.path.abspath(os.path.join(base_path, "..", "ext_lib"))

        if not p in sys.path: sys.path.insert(0, p)
        if not p2 in sys.path: sys.path.append(p2)

    if not cfg["SERW_PATH"] in sys.path:
        sys.path.append(cfg["SERW_PATH"])
    if not cfg["ROOT_PATH"] in sys.path:
        sys.path.append(cfg["ROOT_PATH"])
    if not cfg["PRJ_PATH_ALT"] in sys.path:
        sys.path.append(cfg["PRJ_PATH_ALT"])

    p1 = os.path.join(cfg["ROOT_PATH"], "ext_lib")
    p2 = os.path.join(cfg["ROOT_PATH"], "appdata", "plugins")
    p3 = os.path.join(cfg["DATA_PATH"], "plugins")

    if not p1 in sys.path:
        sys.path.append(p1)
    if not p2 in sys.path:
        sys.path.append(p2)
    if not p3 in sys.path:
        sys.path.append(p3)

    environ['LD_LIBRARY_PATH'] = os.path.join(cfg['DATA_PATH'], "ext_prg",
                                              "tcc")
Exemple #2
0
def import_plugin(plugin_name, prj_name=None):
    cfg = get_main_paths()
    pytigon_cfg = [cfg["PYTIGON_PATH"], "appdata", "plugins"]
    data_path = cfg["DATA_PATH"]
    data_cfg = [data_path, "plugins"]
    prj_cfg = [cfg["PRJ_PATH"], prj_name, "applib"]
    prj_cfg_alt = [cfg["PRJ_PATH_ALT"], prj_name, "applib"]

    if prj_name:
        folders = [prj_cfg, prj_cfg_alt]
    else:
        folders = [pytigon_cfg, data_cfg]

    path = None
    for folder in folders:
        plugins_path = os.path.join(folder[0], *folder[1:])
        if prj_name:
            plugin_path = os.path.join(plugins_path, *plugin_name.split(".")[:-1])
        else:
            plugin_path = os.path.join(plugins_path, *plugin_name.split("."))
        if os.path.exists(plugin_path):
            path = plugins_path
            path2 = plugin_path
            break

    if not path:
        return None

    try:
        m = importlib.import_module(plugin_name, package=None)
        return m
    except:
        make(data_path, path2)
        try:
            m = importlib.import_module(plugin_name, package=None)
            return m
        except:
            pass
    return None
Exemple #3
0
if _PARAM == None:
    sys.exit(0)

import asyncio
from asyncio import get_event_loop, set_event_loop_policy

if sys.platform == "win32":
    set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

LOOP = get_event_loop()

from pytigon_lib.schtools.main_paths import get_main_paths

if "PRJ_NAME" in os.environ:
    PRJ_NAME = os.environ["PRJ_NAME"]
    PATHS = get_main_paths(os.environ["PRJ_NAME"])
else:
    PRJ_NAME = None
    PATHS = get_main_paths()

sys.path.append(PATHS["PRJ_PATH"])

from pytigon_lib.schtools.install_init import init

DATA_PATH = PATHS["DATA_PATH"]
PYTIGON_PATH = PATHS["PYTIGON_PATH"]

init(
    "_schall",
    PATHS["ROOT_PATH"],
    PATHS["DATA_PATH"],
Exemple #4
0
# version: "0.1a"

import os
from pytigon_lib.schhtml.basedc import BaseDc, BaseDcInfo
import io

try:
    import PIL
except:
    pass
import fpdf

from pytigon_lib.schfs.vfstools import get_temp_filename
from pytigon_lib.schtools.main_paths import get_main_paths

_cfg = get_main_paths()
# fpdf.fpdf.FPDF_FONT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../static/fonts")
fpdf.fpdf.FPDF_FONT_DIR = os.path.join(_cfg["STATIC_PATH"], "fonts")


class PDFSurface:
    def __init__(self, output_name, width, height):
        self.output_name = output_name
        self.width = width
        self.height = height
        self.pdf = fpdf.FPDF(unit="pt",
                             orientation="L" if width > height else "P")

        self.pdf.add_font("sans-serif",
                          "",
                          "DejaVuSansCondensed.ttf",
    python_path = sys.executable

    environ["START_PATH"] = os.path.abspath(os.getcwd())

    if "LOGS_TO_DOCKER" in environ and environ["LOGS_TO_DOCKER"]:
        access_logfile = "--access-logfile -"
        access_log = access_logfile.replace("logfile", "log")
        log_file = "--log-file -"
        error_logfile = "--error-logfile -"
    else:
        access_logfile = "--access-logfile /var/log/pytigon-access.log"
        access_log = access_logfile.replace("logfile", "log")
        log_file = "--log-file /var/log/pytigon-worker-err.log"
        error_logfile = "--error-logfile /var/log/pytigon-worker-err.log"

    paths = get_main_paths()

    PYTIGON_PATH = os.path.abspath(os.path.dirname(pytigon.__file__))
    STATIC_PATH = paths["STATIC_PATH"]
    DATA_PATH = paths["DATA_PATH"]
    PRJ_PATH = paths["PRJ_PATH"]
    PRJ_PATH_ALT = paths["PRJ_PATH_ALT"]
    BASE_APPS_PATH = paths["PRJ_PATH"]
    LOCAL_IP = "http://127.0.0.1"
    sys.path.append(BASE_APPS_PATH)
    sys.path.append(PRJ_PATH_ALT)

    uid, gid = pwd.getpwnam("www-data").pw_uid, pwd.getpwnam("www-data").pw_uid

    os.chown(DATA_PATH, uid, gid)
    os.chown("/var/log", uid, gid)