Example #1
0
    def _load(self):
        '''加载配置
        :returns: Settings - 设置读取接口
        '''
        # get PROJECT_MODE from user settings
        try:
            pre_settings = self._load_proj_settings_module(
                "testbase.conf.pre_settings")
        except ImportError as e:
            logger.warn("[WARNING]settings module not found: %s" % str(e))
            pre_settings = None

        mode = getattr(pre_settings, "PROJECT_MODE",
                       getattr(qtaf_settings, 'PROJECT_MODE', None))

        if mode == "standard":  # library mode
            installed_apps = getattr(
                pre_settings, "INSTALLED_APPS",
                getattr(qtaf_settings, 'INSTALLED_APPS', []))

        else:  # egg mode
            proj_root = self._get_standalone_project_root(pre_settings)
            installed_apps = ExLibManager(proj_root).list_names()

        # load settings from qtaf
        self._load_setting_from_module(qtaf_settings)

        # load settings from installed apps
        for appname in installed_apps:
            modname = "%s.settings" % appname
            try:
                __import__(modname)
            except ImportError as e:
                logger.warn(
                    "[WARN]load library settings module \"%s\" failed: %s" %
                    (modname, str(e)))
            else:
                self._load_setting_from_module(sys.modules[modname])

        # load settings from user settings
        try:
            proj_settings = self._load_proj_settings_module(
                "testbase.conf.settings")
        except ImportError:
            pass
        else:
            self._load_setting_from_module(proj_settings)

        # trying to set project root automatically
        if mode != "standard":
            self.PROJECT_ROOT = proj_root
            self.INSTALLED_APPS = ExLibManager(proj_root).list_names()
        else:
            proj_root = getattr(self, "PROJECT_ROOT", None)
            if pre_settings is not None and not proj_root:
                proj_root = os.path.dirname(pre_settings.__file__)
                setattr(self, "PROJECT_ROOT", proj_root)
Example #2
0
    def _load(self):
        '''加载配置
        :returns: Settings - 设置读取接口
        '''
        #先加载一次项目配置
        try:
            pre_settings = self._load_proj_settings_module(
                "testbase.conf.pre_settings")
        except ImportError:  #非测试项目情况下使用没有项目settings.py
            pre_settings = None

        mode = getattr(pre_settings, "PROJECT_MODE",
                       getattr(qtaf_settings, 'PROJECT_MODE', None))

        #加载扩展库或应用配置
        if mode == "standard":  #Python标准模式
            installed_apps = getattr(
                pre_settings, "INSTALLED_APPS",
                getattr(qtaf_settings, 'INSTALLED_APPS', []))

        else:  #独立模式
            proj_root = self._get_standalone_project_root(pre_settings)
            installed_apps = ExLibManager(proj_root).list_names()

        #优先加载QTAF设置
        self._load_setting_from_module(qtaf_settings)

        for appname in installed_apps:
            modname = "%s.settings" % appname
            try:
                __import__(modname)
            except ImportError:
                pass
            else:
                self._load_setting_from_module(sys.modules[modname])

        #加载用户自定义设置
        try:
            proj_settings = self._load_proj_settings_module(
                "testbase.conf.settings")
        except ImportError:  #非测试项目情况下使用没有项目settings.py
            pass
        else:
            self._load_setting_from_module(proj_settings)

        #非标准模式下需要设置项目根目录,标准模式要求项目在settings中显式设置
        if mode != "standard":
            self.PROJECT_ROOT = proj_root
            self.INSTALLED_APPS = ExLibManager(proj_root).list_names()
Example #3
0
    def _load(self):
        '''加载配置
        :returns: Settings - 设置读取接口
        '''
        # get PROJECT_MODE from user settings
        default_mode = getattr(qtaf_settings, 'PROJECT_MODE', None)
        try:
            pre_settings = self._load_proj_settings_module(
                "testbase.conf.pre_settings")
            mode = getattr(pre_settings, "PROJECT_MODE", default_mode)
        except ImportError as e:
            pre_settings = None
            if os.path.isfile(__file__):
                mode = "standard"
            else:
                mode = "standalone"

        if mode == "standard":  # library mode
            proj_root = getattr(pre_settings, "PROJECT_ROOT", os.getcwd())
            installed_apps = getattr(
                pre_settings, "INSTALLED_APPS",
                getattr(qtaf_settings, 'INSTALLED_APPS', []))

        else:  # egg mode
            proj_root = self._get_standalone_project_root(pre_settings)
            installed_apps = ExLibManager(proj_root).list_names()

        # load settings from qtaf
        self._load_setting_from_module(qtaf_settings)

        # load settings from installed apps
        for appname in installed_apps:
            modname = "%s.settings" % appname
            try:
                __import__(modname)
            except:
                stack = traceback.format_exc()
                logger.warn(
                    "[WARN]load library settings module \"%s\" failed:\n%s" %
                    (modname, stack))
            else:
                self._load_setting_from_module(sys.modules[modname])

        # load settings from user settings
        try:
            proj_settings = self._load_proj_settings_module(
                "testbase.conf.settings")
        except ImportError as e:
            if e.args[0] not in [
                    "No module named settings", "No module named 'settings'"
            ]:
                # project settings found and there was an error
                stack = traceback.format_exc()
                logger.warn("[WARN]load project settings failed:\n%s" % stack)
        else:
            self._load_setting_from_module(proj_settings)

        # trying to set project root automatically
        setattr(self, "PROJECT_ROOT", proj_root)
        setattr(self, "INSTALLED_APPS", installed_apps)
Example #4
0
 def _load(self):
     '''加载配置
     :returns: Settings - 设置读取接口
     '''
     top_dir=ExLibManager.find_top_dir()
         
     #优先加载QTAF设置
     self._load_setting_from_module(qtaf_settings)
     
     #加载exlib中其他egg的配置
     for lib_settings in self._load_libs_settings():
         self._load_setting_from_module(lib_settings)
             
     #加载用户自定义设置 
     try:
         user_settings=os.environ.get("QTAF_SETTINGS_MODULE",None)
         if user_settings:
             parts=user_settings.split('.')
             parts_temp=parts[:]
             dir_path=None
             while parts_temp:
                 if dir_path:
                     fd,dir_path,desc=imp.find_module(parts_temp[0],[dir_path])
                 else:
                     fd,dir_path,desc=imp.find_module(parts_temp[0])
                 del parts_temp[0]
         else:
             name="settings"
             fd, dir_path, desc = imp.find_module(name, [top_dir])
         mod = imp.load_module("testbase.conf.settings", fd, dir_path, desc)
         self._load_setting_from_module(mod)
     except ImportError:
         pass
Example #5
0
 def _load_libs_settings(self):
     '''获取已安装的lib的配置文件
     '''
     mods = []
     for libname in ExLibManager().list_names():
             modname = '%s.settings' % libname
             try:
                 __import__(modname)
             except ImportError:
                 continue
             else:
                 mods.append(sys.modules[modname])
     return mods    
Example #6
0
 def _load_libs_cmds(self):
     '''从lib中加载命令
     '''
     cmds = []
     for libname in ExLibManager().list_names():
         if not libname:
             continue
         modname = '%s.cmds' % libname
         try:
             __import__(modname)
         except ImportError:
             continue
         else:
             for cmd in self._load_cmd_from_module(sys.modules[modname]):
                 cmd.name = libname + '.' + cmd.name
                 cmds.append(cmd)
     return cmds
Example #7
0
 def execute(self, args):
     """执行过程
     """
     ExLibManager(settings.PROJECT_ROOT).install(args.egg_path)
Example #8
0
 def execute(self, args):
     '''执行过程
     '''
     ExLibManager().install(args.egg_path)