def init(): """ Create a default configuration in the config directory. This makes a disdat folder which contains all configuration files. """ directory = os.path.expanduser(SYSTEM_CONFIG_DIR) # Make sure disdat has not already been initialized if os.path.exists(directory): error( 'DisDat already initialized in {}.'.format(directory) ) # Create outer folder if the system does not have it yet path = os.path.dirname(directory) if not os.path.exists(path): os.mkdir(path) # Copy over default configurations src = resource.filename(disdat.config, PACKAGE_CONFIG_DIR) dst = directory shutil.copytree(src, dst) # Make sure paths are absolute in luigi config luigi_dir = os.path.join(directory, LUIGI_FILE) config = ConfigParser.ConfigParser() config.read(luigi_dir) value = config.get('core', 'logging_conf_file') config.set('core', 'logging_conf_file', os.path.expanduser(value)) with open(luigi_dir, 'wb') as handle: config.write(handle)
def _read_configuration_file(self, disdat_config_file, luigi_config_file): """ Check for environment varialbe 'DISDAT_CONFIG_PATH' -- should point to disdat.cfg Paths in the config might be relative. If so, add the prefix to them. Next, see if there is a disdat.cfg in cwd. Then configure disdat and (re)configure logging. """ # _logger.debug("Loading config file [{}]".format(disdat_config_file)) config = ConfigParser.SafeConfigParser({'meta_dir_root': self.meta_dir_root, 'ignore_code_version': 'False'}) config.read(disdat_config_file) self.meta_dir_root = os.path.expanduser(config.get('core', 'meta_dir_root')) self.meta_dir_root = DisdatConfig._fix_relative_path(disdat_config_file, self.meta_dir_root) self.ignore_code_version = config.getboolean('core', 'ignore_code_version') try: self.logging_config = os.path.expanduser(config.get('core', 'logging_conf_file')) self.logging_config = DisdatConfig._fix_relative_path(disdat_config_file, self.logging_config) logging.config.fileConfig(self.logging_config, disable_existing_loggers=False) except ConfigParser.NoOptionError: pass # Set up luigi configuration luigi.configuration.get_config().read(luigi_config_file) # Tell everything to push warnings through the logging infrastructure logging.captureWarnings(True) # unfortunately that's not enough -- kill all luigi (and disdat) warnings import warnings warnings.filterwarnings("ignore") meta_dir = os.path.join(self.meta_dir_root, META_DIR) if not os.path.exists(meta_dir): os.makedirs(meta_dir) return config