Class: CFA::GenericSysconfig
- Inherits:
-
BaseModel
- Object
- BaseModel
- CFA::GenericSysconfig
- Includes:
- Yast::Logger
- Defined in:
- src/lib/cfa/generic_sysconfig.rb
Class Method Summary collapse
-
.merge_files(original_path, modified_path) ⇒ Object
do merge of sysconfigs value in a sense that values not in new file is kept in the original one and also all comments are kept.
Instance Method Summary collapse
-
#attributes ⇒ Hash<String, String>
attributes in file.
-
#initialize(path, file_handler: nil) ⇒ GenericSysconfig
constructor
A new instance of GenericSysconfig.
Constructor Details
#initialize(path, file_handler: nil) ⇒ GenericSysconfig
Returns a new instance of GenericSysconfig.
30 31 32 |
# File 'src/lib/cfa/generic_sysconfig.rb', line 30 def initialize(path, file_handler: nil) super(AugeasParser.new("Sysconfig.lns"), path, file_handler: file_handler) end |
Class Method Details
.merge_files(original_path, modified_path) ⇒ Object
do merge of sysconfigs value in a sense that values not in new file is kept in the original one and also all comments are kept.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'src/lib/cfa/generic_sysconfig.rb', line 45 def self.merge_files(original_path, modified_path) # use ::File handle to ensure that SCR is not taken in account modified_model = new(modified_path, file_handler: ::File) target_model = new(original_path, file_handler: ::File) modified_model.load # if old part into which we merge does not exist, then just copy new content begin target_model.load rescue IOError, SystemCallError => e log.error "Failed to load #{original_path} with #{e.inspect}. Copying just new content." ::FileUtils.cp modified_path, original_path return end modified_model.attributes.each_pair do |key, value| target_model.generic_set(key, value) end target_model.save end |
Instance Method Details
#attributes ⇒ Hash<String, String>
attributes in file
36 37 38 39 |
# File 'src/lib/cfa/generic_sysconfig.rb', line 36 def attributes attrs = data.select(CFA::Matcher.new { |k, _v| k != "#comment[]" }) Hash[attrs.map { |v| [v[:key], v[:value]] }] end |