def _validate_config_files(self):
"""
Validates the configuration files necessary for the application. An exception is thrown
if any of the required files are inaccessible.
"""
# Determine the module of the derived class
mod = self.__class__.__module__
# If the configuration directory exists in the library, create config files as necessary
# This check also provides backwards compatibility for projects that don't have the
# configuration files in the library.
if pkg_resources.resource_exists(mod, self.LIB_CONFIG_DIR):
# Create configuration directory if not found
if not os.access(self._config_dir, os.R_OK):
logger.info("Configuration directory '{0}' not found, creating...".format(self._config_dir))
os.makedirs(self._config_dir)
# Count of current configuration files
config_files_count = len([name for name in os.listdir(self._config_dir)
if os.path.isfile(os.path.join(self._config_dir, name))])
# Create configuration files if not found
files = pkg_resources.resource_listdir(mod, self.LIB_APP_CONFIG_DIR)
for f in files:
config_path = os.path.join(self._config_dir, f)
if not os.access(config_path, os.R_OK):
f_lower = f.lower()
# Copy configuration file. Only copy logging file if the directory was empty
if not(f_lower.endswith(".py") or f_lower.endswith(".pyc")) and \
(f_lower != Application.LOGGING_CONFIG_FILE or config_files_count == 0):
logger.info("Configuration file '{0}' not found, creating...".format(f))
shutil.copyfile(pkg_resources.resource_filename(
mod, self.LIB_APP_CONFIG_DIR + "/" + f), config_path)
if not os.access(self._dxlclient_config_path, os.R_OK):
raise Exception(
"Unable to access client configuration file: {0}".format(
self._dxlclient_config_path))
if not os.access(self._app_config_path, os.R_OK):
raise Exception(
"Unable to access application configuration file: {0}".format(
self._app_config_path))
评论列表
文章目录