Class: SchrootConfig
- Inherits:
-
Object
- Object
- SchrootConfig
- Defined in:
- lib/schroot.rb
Overview
Schroot config data
Instance Method Summary collapse
-
#add(name, kwargs = {}) ⇒ Bool
Adds new chroot configuration to …/chroot.d/ directory.
-
#initialize ⇒ SchrootConfig
constructor
A new instance of SchrootConfig.
- #readconf ⇒ Object
Constructor Details
#initialize ⇒ SchrootConfig
Returns a new instance of SchrootConfig.
18 19 20 21 22 |
# File 'lib/schroot.rb', line 18 def initialize @base_conf = "/etc/schroot/schroot.conf" @conf_d = "/etc/schroot/chroot.d/" @chroots = {} end |
Instance Method Details
#add(name, kwargs = {}) ⇒ Bool
Adds new chroot configuration to …/chroot.d/ directory
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/schroot.rb', line 51 def add(name, kwargs = {}) readconf() filename = @conf_d+name if @chroots[name] or File.exists?(filename) return false else begin stream = File.open(filename,"w") rescue Errno::EACCES raise SchrootError, "Cannot open #{filename} for writing" end stream.puts "# Generated automatically with ruby-schroot" stream.puts "[#{name}]" kwargs.each do |param, value| stream.puts "#{param}=#{value}" end end return true end |
#readconf ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/schroot.rb', line 24 def readconf files = [@base_conf] Dir.entries(@conf_d).each do |file| files << (@conf_d+file) unless ['.','..'].include? file end name_regexp = /^\s*\[([a-z0-9A-Z\-\_]+)\]/ param_regexp = /^\s*([a-z0-9A-Z\-\_]+)\=(.*)$/ files.each do |file| stream = File.open(file,"r") current = nil while (line = stream.gets) if name_regexp.match line current = name_regexp.match(line)[1] @chroots[current.strip] = {"source" => file} elsif current and param_regexp.match line param, value = param_regexp.match(line)[1],param_regexp.match(line)[2] @chroots[current][param.strip] = value.strip if current end end end end |