프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / DTI_PID / PluginScope.py @ d4f20853

이력 | 보기 | 이력해설 | 다운로드 (1.54 KB)

1
# coding: utf-8
2
""" This is PluginScope class """
3

    
4
import sys
5
import os
6
import sqlite3
7
import datetime
8
from enum import Enum
9
from PIL import PngImagePlugin, JpegImagePlugin
10
from PIL import Image
11
from PIL.ImageQt import ImageQt
12

    
13
from SingletonInstance import SingletonInstance
14
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Plugins'))
15

    
16

    
17
class PluginScope(SingletonInstance):
18
    def __init__(self):
19
        self._classes = {}
20
        self.load_modules()
21

    
22
    def get_module(self, name):
23
        """return the class which has given name"""
24
        return self._classes[name] if name in self._classes else None
25

    
26
    def load_modules(self) -> None:
27
        import os
28
        import importlib
29
        from App import App
30

    
31
        try:
32
            path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Plugins')
33
            plugin_files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) and
34
                            (os.path.splitext(f)[1].upper() == '.PY')]
35

    
36
            for f in plugin_files:
37
                module_name = os.path.splitext(os.path.basename(f))[0]
38
                module = importlib.import_module(module_name)
39
                _class = getattr(module, module_name)
40
                self._classes[module_name] = _class(App.instance())
41
        except Exception as ex:
42
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
43
                                                           sys.exc_info()[-1].tb_lineno)
44
            print(message)
클립보드 이미지 추가 (최대 크기: 500 MB)