def init_services() -> None: """ services table init """ project_backend = get_cwd() service_path = os.path.join(project_backend, 'config/base/services.yml') if not os.path.isfile(service_path): raise RuntimeError(f"The file {service_path} does not exist.") with open(service_path, 'r', encoding='utf-8') as load_file: service_data = yaml.load(load_file, Loader=FullLoader) query_service_dict = dict(db.session.query(Service.code, Service).all()) for code, service_values in service_data.items(): if query_service_dict.get(code): query_service = query_service_dict.get(code) for key, value in service_values.items(): if hasattr(query_service, key): setattr(query_service, key, value) else: service = Service() for key, value in service_values.items(): if hasattr(service, key): setattr(service, key, value) db.session.add(service) db.session.commit() info = "services table init successfully!" print(info)
def init_dict_code() -> None: """ Initialize dict code table """ project_backend = get_cwd() dict_code_path = os.path.join(project_backend, 'config/base/dict_code.yml') if not os.path.isfile(dict_code_path): raise RuntimeError(f"The file {dict_code_path} does not exist.") with open(dict_code_path, 'r', encoding='utf-8') as load_file: dict_code_yml = yaml.load(load_file, Loader=FullLoader) # truncate dict_code table truncate_sql = 'TRUNCATE TABLE dict_code RESTART IDENTITY;' db.engine.execute( text(truncate_sql).execution_options(autocommit=True) ) for _, dict_code_values in dict_code_yml.items(): for dict_code_value in dict_code_values: dict_code = DictCode() for key, value in dict_code_value.items(): if hasattr(dict_code, key): setattr(dict_code, key, value) db.session.add(dict_code) db.session.commit() info = "dict_code table init successfully!" print(info)
def write_py(name, code): temp_dir = get_cwd() + '/_temp' if not os.path.exists(temp_dir): os.makedirs(temp_dir) fpath = os.path.join(temp_dir, name) with open(fpath, 'w') as f: f.write(code) return fpath
def _load_roles_yml() -> Dict: """ load default roles yml file """ PROJECT_PATH = get_cwd() default_roles_path = os.path.join(PROJECT_PATH, 'config/base/default_roles.yml') if not os.path.isfile(default_roles_path): raise RuntimeError(f"The file {default_roles_path} does not exist.") with open(default_roles_path, 'r', encoding='utf-8') as load_file: roles_yml = yaml.load(load_file, Loader=FullLoader) return roles_yml
def _load_config(self): project_path = get_cwd() # get project path self.__base_config['PROJECT_PATH'] = project_path default_config_path = os.path.join(project_path, 'config/config.yml') instance_config_path = os.path.join(project_path, 'instance/config.yml') self._load_yml_config(default_config_path) if os.path.isfile(instance_config_path): self._load_yml_config(instance_config_path) self.__base_config['TIMEZONE'] = pytz.timezone( self.__base_config['TIMEZONE']) self._get_certs_path(project_path) self._load_emqx_config() self._load_actorcloud_config() self._load_stream_config()