def _update_config(self, canari_config, load=True, remote=False, **kwargs): with PushDir(os.path.dirname(canari_config)): config = CanariConfigParser() config.read(canari_config) configs_option = OPTION_REMOTE_CONFIGS if remote else OPTION_LOCAL_CONFIGS config_section = SECTION_REMOTE if remote else SECTION_LOCAL if configs_option not in config: if config_section not in config: config.add_section(config_section) config[configs_option] = '' configs = config.get_as_list(configs_option) if load: for (k, v) in kwargs.get('additional_options', {}).items(): config['.'.join([config_section, k])] = v if self.config_file not in configs: print('Updating %s...' % canari_config, file=sys.stderr) configs.append(self.config_file) config[configs_option] = configs if remote: packages = config.get_as_list(OPTION_REMOTE_PACKAGES) if self.name not in packages: packages.append(self.name) config[OPTION_REMOTE_PACKAGES] = packages else: if self.config_file in configs: print('Updating %s...' % canari_config, file=sys.stderr) configs.remove(self.config_file) config[configs_option] = configs if remote: packages = config.get_as_list(OPTION_REMOTE_PACKAGES) if self.name in packages: packages.remove(self.name) config[OPTION_REMOTE_PACKAGES] = packages config.write(open(canari_config, mode='w'))
def _update_config(self, canari_config, load=True, remote=False): with PushDir(os.path.dirname(canari_config)): config = CanariConfigParser() config.read(canari_config) configs_option = OPTION_REMOTE_CONFIGS if remote else OPTION_LOCAL_CONFIGS config_section = SECTION_REMOTE if remote else SECTION_LOCAL if configs_option not in config: if config_section not in config: config.add_section(config_section) config[configs_option] = '' configs = config.get_as_list(configs_option) if load: if self.config_file not in configs: print ('Updating %s...' % canari_config) configs.append(self.config_file) config[configs_option] = configs if remote: packages = config.get_as_list(OPTION_REMOTE_PACKAGES) if self.name not in packages: packages.append(self.name) config[OPTION_REMOTE_PACKAGES] = packages else: if self.config_file in configs: print ('Updating %s...' % canari_config) configs.remove(self.config_file) config[configs_option] = configs if remote: packages = config.get_as_list(OPTION_REMOTE_PACKAGES) if self.name in packages: packages.remove(self.name) config[OPTION_REMOTE_PACKAGES] = packages config.write(file(canari_config, mode='wb'))