Browse Source

[trac615] Don't hurt absolute names

Michal 'vorner' Vaner 14 years ago
parent
commit
1faf02bda8
1 changed files with 22 additions and 11 deletions
  1. 22 11
      src/lib/python/isc/config/cfgmgr.py

+ 22 - 11
src/lib/python/isc/config/cfgmgr.py

@@ -48,21 +48,32 @@ class ConfigManagerData:
         """Initialize the data for the configuration manager, and
         """Initialize the data for the configuration manager, and
            set the version and path for the data store. Initializing
            set the version and path for the data store. Initializing
            this does not yet read the database, a call to
            this does not yet read the database, a call to
-           read_from_file is needed for that."""
+           read_from_file is needed for that.
+
+           In case the file_name is absolute, data_path is ignored
+           and the directory where the file_name lives is used instead.
+           """
         self.data = {}
         self.data = {}
         self.data['version'] = config_data.BIND10_CONFIG_DATA_VERSION
         self.data['version'] = config_data.BIND10_CONFIG_DATA_VERSION
-        self.data_path = data_path
+        if os.path.isabs(file_name):
-        self.db_filename = data_path + os.sep + file_name
+            self.db_filename = file_name
+            self.data_path = os.path.dirname(file_name)
+        else:
+            self.db_filename = data_path + os.sep + file_name
+            self.data_path = data_path
 
 
     def read_from_file(data_path, file_name = "b10-config.db"):
     def read_from_file(data_path, file_name = "b10-config.db"):
-        """Read the current configuration found in the file at
+        """Read the current configuration found in the file file_name.
-           data_path. If the file does not exist, a
+           If file_name is absolute, data_path is ignored. Otherwise
-           ConfigManagerDataEmpty exception is raised. If there is a
+           we look for the file_name in data_path directory.
-           parse error, or if the data in the file has the wrong
+
-           version, a ConfigManagerDataReadError is raised. In the first
+           If the file does not exist, a ConfigManagerDataEmpty exception is
-           case, it is probably safe to log and ignore. In the case of
+           raised. If there is a parse error, or if the data in the file has
-           the second exception, the best way is probably to report the
+           the wrong version, a ConfigManagerDataReadError is raised. In the
-           error and stop loading the system."""
+           first case, it is probably safe to log and ignore. In the case of
+           the second exception, the best way is probably to report the error
+           and stop loading the system.
+           """
         config = ConfigManagerData(data_path, file_name)
         config = ConfigManagerData(data_path, file_name)
         file = None
         file = None
         try:
         try: