Ejemplo n.º 1
0
    def __init__(self, root, is_type_editor):
        """
        Args:
            root: path of project root folder
            is_type_editor: bool. see class docstring                
        """
        self.path = util.normpath(os.path.abspath(root))
        self.is_type_editor = is_type_editor
        self._auto_create_clazz_folder = True

        # Must be the first
        self.event_manager = EventManager()
        self.type_manager = TypeManager()
        self.fs_manager = FileSystemManager(
            self, os.path.join(self.path, const.PROJECT_FOLDER_DATA))
        # should after fs_manager
        self.object_manager = ObjectManager(self)
        # should after object_manager
        self.ref_manager = RefManager()

        # self._langauges = ('en', )
        self._default_language = 'en'
        self._translations = {}
        self._verifier = None
        self._loading_errors = AttrVerifyLogger()

        self.tags = set()

        self._next_ids = {}  # {clazz_name: next_id}
        self._loaded = False
        self._editor_project = None
Ejemplo n.º 2
0
    def __init__(self, root, is_type_editor):
        """
        Args:
            root: path of project root folder
            is_type_editor: bool. see class docstring                
        """
        self.path = util.normpath(os.path.abspath(root))
        self.is_type_editor = is_type_editor        
        self._auto_create_clazz_folder = True
        
        # Must be the first
        self.event_manager = EventManager()        
        self.type_manager = TypeManager()        
        self.fs_manager = FileSystemManager(self, os.path.join(self.path, const.PROJECT_FOLDER_DATA))
        # should after fs_manager
        self.object_manager = ObjectManager(self)
        # should after object_manager
        self.ref_manager = RefManager()        
        
        # self._langauges = ('en', )
        self._default_language = 'en'
        self._translations = {}
        self._verifier = None
        self._loading_errors = AttrVerifyLogger()

        self.tags = set()
        
        self._next_ids = {}  # {clazz_name: next_id}
        self._loaded = False
        self._editor_project = None
Ejemplo n.º 3
0
class Project(object):
    """Holds all information of a project.
    
    Attributes:
        path: Path of project root.
        is_type_editor: bool. True if the project is used by type editor, load types from editor_types.py
        auto_create_clazz_folder: automaticly creates a folder for each clazz under root
         
        type_manager: An instance of TypeManager, which holds all Clazz infos.
        fs_manager: An instance of FileSystemManager
        ref_manager: An instance of RefManager, which manages all relations between all objects.
    """    
    def __init__(self, root, is_type_editor):
        """
        Args:
            root: path of project root folder
            is_type_editor: bool. see class docstring                
        """
        self.path = util.normpath(os.path.abspath(root))
        self.is_type_editor = is_type_editor        
        self._auto_create_clazz_folder = True
        
        # Must be the first
        self.event_manager = EventManager()        
        self.type_manager = TypeManager()        
        self.fs_manager = FileSystemManager(self, os.path.join(self.path, const.PROJECT_FOLDER_DATA))
        # should after fs_manager
        self.object_manager = ObjectManager(self)
        # should after object_manager
        self.ref_manager = RefManager()        
        
        # self._langauges = ('en', )
        self._default_language = 'en'
        self._translations = {}
        self._verifier = None
        self._loading_errors = AttrVerifyLogger()

        self.tags = set()
        
        self._next_ids = {}  # {clazz_name: next_id}
        self._loaded = False
        self._editor_project = None

    @property
    def name(self):
        p = os.path.split(self.path)
        return p[-1]
        
    def load(self):
        """ Load the project 
        Returns:
            True if it's a new project, otherwise False
        """
        assert not self._loaded
        self._loaded = True
        
        if self.is_type_editor:
            self.type_manager.load_editor_types()
                        
        else:
            self._editor_project = p = Project(os.path.join(self.path, const.PROJECT_FOLDER_TYPE), True)
            p.load()

            # noinspection PyBroadException
            try:
                self.type_manager.load_types(p)
            except Exception, e:
                self._loading_errors.error('Failed to load types: %s', e)
                traceback.print_exc()
                                        
            # load setting
            setting_objs = p.object_manager.get_objects(editor_types.CLAZZ_NAME_SETTING)        
            if len(setting_objs) == 1:
                setting_obj = setting_objs[0]                
                self._translations = dict(setting_obj.get_attr_value('translations'))
                self.tags = set(setting_obj.get_attr_value('tags', []))
                self.tags.add('export')
                self._auto_create_clazz_folder = setting_obj.get_attr_value('auto_create_clazz_folder')
                verifier = setting_obj.get_attr_value('verifier')
                if verifier:
                    self._verifier = make_verifier(verifier)
            elif len(setting_objs) > 1:
                log.error('too many Setting objects: %s', len(setting_objs))
                self._loading_errors.error('too many Setting objects: %s', len(setting_objs))
            
        is_new = self.fs_manager.load()
        self.object_manager.load(self._loading_errors)

        # todo: enable evt_manager here. previously events should be ignored.
                
        # Creates root folder for each Clazz, if it's a new project
        if self._auto_create_clazz_folder:
            for clazz in self.type_manager.get_clazzes():
                if not self.fs_manager.root.get_sub_folder_by_name(clazz.name):                    
                    self.fs_manager.create_folder(self.fs_manager.root, clazz.name)

        return is_new
Ejemplo n.º 4
0
class Project(object):
    """Holds all information of a project.
    
    Attributes:
        path: Path of project root.
        is_type_editor: bool. True if the project is used by type editor, load types from editor_types.py
        auto_create_clazz_folder: automaticly creates a folder for each clazz under root
         
        type_manager: An instance of TypeManager, which holds all Clazz infos.
        fs_manager: An instance of FileSystemManager
        ref_manager: An instance of RefManager, which manages all relations between all objects.
    """
    def __init__(self, root, is_type_editor):
        """
        Args:
            root: path of project root folder
            is_type_editor: bool. see class docstring                
        """
        self.path = util.normpath(os.path.abspath(root))
        self.is_type_editor = is_type_editor
        self._auto_create_clazz_folder = True

        # Must be the first
        self.event_manager = EventManager()
        self.type_manager = TypeManager()
        self.fs_manager = FileSystemManager(
            self, os.path.join(self.path, const.PROJECT_FOLDER_DATA))
        # should after fs_manager
        self.object_manager = ObjectManager(self)
        # should after object_manager
        self.ref_manager = RefManager()

        # self._langauges = ('en', )
        self._default_language = 'en'
        self._translations = {}
        self._verifier = None
        self._loading_errors = AttrVerifyLogger()

        self.tags = set()

        self._next_ids = {}  # {clazz_name: next_id}
        self._loaded = False
        self._editor_project = None

    @property
    def name(self):
        p = os.path.split(self.path)
        return p[-1]

    def load(self):
        """ Load the project 
        Returns:
            True if it's a new project, otherwise False
        """
        assert not self._loaded
        self._loaded = True

        if self.is_type_editor:
            self.type_manager.load_editor_types()

        else:
            self._editor_project = p = Project(
                os.path.join(self.path, const.PROJECT_FOLDER_TYPE), True)
            p.load()

            # noinspection PyBroadException
            try:
                self.type_manager.load_types(p)
            except Exception, e:
                self._loading_errors.error('Failed to load types: %s', e)
                traceback.print_exc()

            # load setting
            setting_objs = p.object_manager.get_objects(
                editor_types.CLAZZ_NAME_SETTING)
            if len(setting_objs) == 1:
                setting_obj = setting_objs[0]
                self._translations = dict(
                    setting_obj.get_attr_value('translations'))
                self.tags = set(setting_obj.get_attr_value('tags', []))
                self.tags.add('export')
                self._auto_create_clazz_folder = setting_obj.get_attr_value(
                    'auto_create_clazz_folder')
                verifier = setting_obj.get_attr_value('verifier')
                if verifier:
                    self._verifier = make_verifier(verifier)
            elif len(setting_objs) > 1:
                log.error('too many Setting objects: %s', len(setting_objs))
                self._loading_errors.error('too many Setting objects: %s',
                                           len(setting_objs))

        is_new = self.fs_manager.load()
        self.object_manager.load(self._loading_errors)

        # todo: enable evt_manager here. previously events should be ignored.

        # Creates root folder for each Clazz, if it's a new project
        if self._auto_create_clazz_folder:
            for clazz in self.type_manager.get_clazzes():
                if not self.fs_manager.root.get_sub_folder_by_name(clazz.name):
                    self.fs_manager.create_folder(self.fs_manager.root,
                                                  clazz.name)

        return is_new