Class: SchrootConfig
- Inherits:
-
Object
- Object
- SchrootConfig
- Defined in:
- lib/schroot.rb
Overview
Schroot config manager
Class Method Summary collapse
-
.add(name, kwargs = {}, force = false) ⇒ Bool
Adds new chroot configuration to …/chroot.d/ directory.
- .match_name(name) ⇒ Object
- .match_param(param) ⇒ Object
-
.readconf ⇒ Hash
Representation of current config fules.
-
.remove(name, force = false) ⇒ Bool
Removes chroot from …/chroot.d/ directory.
Class Method Details
.add(name, kwargs = {}, force = false) ⇒ Bool
Adds new chroot configuration to …/chroot.d/ directory
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/schroot.rb', line 58 def self.add(name, kwargs = {}, force=false) chroots = readconf() filename = CONF_D+CONF_D_PREFIX+name if (chroots[name] or File.exists?(filename)) and !force 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 stream.close end return true end |
.match_name(name) ⇒ Object
38 39 40 |
# File 'lib/schroot.rb', line 38 def self.match_name(name) return /^\s*\[([a-z0-9A-Z\-\_]+)\]/.match(name) end |
.match_param(param) ⇒ Object
42 43 44 |
# File 'lib/schroot.rb', line 42 def self.match_param(param) return /^\s*([a-z0-9A-Z\-\_]+)\=(.*)$/.match(param) end |
.readconf ⇒ Hash
Returns representation of current config fules.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/schroot.rb', line 15 def self.readconf chroots = {} files = [BASE_CONF] Dir.entries(CONF_D).each do |file| files << (CONF_D+CONF_D_PREFIX+file) unless ['.','..'].include? file end files.each do |file| stream = File.open(file,"r") current = nil while (line = stream.gets) if match_name(line) current = match_name(line)[1] chroots[current.strip] = {"source" => file} elsif current and match_param(line) param, value = match_param(line)[1],match_param(line)[2] chroots[current][param.strip] = value.strip if current end end stream.close end return chroots end |
.remove(name, force = false) ⇒ Bool
Removes chroot from …/chroot.d/ directory
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/schroot.rb', line 88 def self.remove(name, force=false) chroots = readconf() filename = CONF_D+CONF_D_PREFIX+name if (File.exists?(filename) and chroots[name]) or force File.delete(filename) return true else return false end end |