schroot 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/schroot.rb +57 -31
  3. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0736aa3c2bf393670a231765da40367d4e33c50d
4
- data.tar.gz: 81aca34c23f3f9c8f245acf8d51e93d47e84f14f
3
+ metadata.gz: 96418a492bc195394f2d36c2df2995fa38903ab9
4
+ data.tar.gz: 93f1682f71ee61a58437965a646078dadcc0e046
5
5
  SHA512:
6
- metadata.gz: 14390f1cd286f513c1e8f0c38d2112c7c0576d102e8991032570714ea868eaa8de96dec33971f250f889fc4220da35354923772369adbdda91951c5fce03a5f1
7
- data.tar.gz: 27da31f097bf5ddf2789a2e012669e1260ba1b3cf784904f83d5c58c8eb87f015ce052482fbb4c3166d01989c88f44b8e69122124402d7d8ed6014aa39b5d1da
6
+ metadata.gz: c5c09f56d4d3d802b55e277a4405f2feafeef1043975985f1dc6e370f8b4bbe516a9a10f1980164545d3ed99bb20ea5fbe108f6fa6b4da28052e43a02c9d35ae
7
+ data.tar.gz: 93c973a7780e72c691e35d67a2c59eb3b7d8a25dc0a62b085b5fe94a6abbfe6e6dc30351f9668348a7f746b7117ba251c6512d2f6d817dbdf7bb9e70cfc4bd3d
data/lib/schroot.rb CHANGED
@@ -2,56 +2,61 @@ require 'open3'
2
2
  require 'logger'
3
3
 
4
4
  SCHROOT_BASE="/var/lib/schroot"
5
+ BASE_CONF = "/etc/schroot/schroot.conf"
6
+ CONF_D = "/etc/schroot/chroot.d/"
5
7
 
6
8
  class SchrootError < StandardError
7
9
  end
8
10
 
9
- # Schroot config unit
10
- class SchrootConfigUnit
11
- attr_accessor :type, :description, :union_type,
12
- :directory, :users, :groups, :root_groups,
13
- :aliases
14
- end
15
-
16
- # Schroot config data
11
+ # Schroot config manager
17
12
  class SchrootConfig
18
- def initialize
19
- @base_conf = "/etc/schroot/schroot.conf"
20
- @conf_d = "/etc/schroot/chroot.d/"
21
- @chroots = {}
22
- end
23
-
24
- def readconf
25
- files = [@base_conf]
26
- Dir.entries(@conf_d).each do |file|
27
- files << (@conf_d+file) unless ['.','..'].include? file
13
+ # @return [Hash] representation of current config fules
14
+ def self.readconf
15
+ chroots = {}
16
+ files = [BASE_CONF]
17
+ Dir.entries(CONF_D).each do |file|
18
+ files << (CONF_D+file) unless ['.','..'].include? file
28
19
  end
29
- name_regexp = /^\s*\[([a-z0-9A-Z\-\_]+)\]/
30
- param_regexp = /^\s*([a-z0-9A-Z\-\_]+)\=(.*)$/
31
20
  files.each do |file|
32
21
  stream = File.open(file,"r")
33
22
  current = nil
34
23
  while (line = stream.gets)
35
- if name_regexp.match line
36
- current = name_regexp.match(line)[1]
37
- @chroots[current.strip] = {"source" => file}
38
- elsif current and param_regexp.match line
39
- param, value = param_regexp.match(line)[1],param_regexp.match(line)[2]
40
- @chroots[current][param.strip] = value.strip if current
24
+ if validate_name(line)
25
+ current = validate_name(line)[1]
26
+ chroots[current.strip] = {"source" => file}
27
+ elsif current and validate_param(line)
28
+ param, value = validate_param(line)[1],validate_param(line)[2]
29
+ chroots[current][param.strip] = value.strip if current
41
30
  end
42
31
  end
43
32
  end
33
+ return chroots
34
+ end
35
+
36
+ def validate_name(name)
37
+ return /^\s*\[([a-z0-9A-Z\-\_]+)\]/.match(name)
38
+ end
39
+
40
+ def validate_param(param)
41
+ return /^\s*([a-z0-9A-Z\-\_]+)\=(.*)$/.match(param)
44
42
  end
45
43
 
46
44
  # Adds new chroot configuration to .../chroot.d/ directory
47
45
  #
46
+ # @example
47
+ # SchrootConfig.add("testing", {"description" => "Debian testing",
48
+ # "file" => "/srv/chroot/testing.tgz",
49
+ # "location" => "/testing",
50
+ # "groups" => "sbuild"})
51
+ # => true
48
52
  # @param name [String] name of chroot
49
53
  # @param kwargs [Hash] options
50
- # @return [Bool]
51
- def add(name, kwargs = {})
52
- readconf()
53
- filename = @conf_d+name
54
- if @chroots[name] or File.exists?(filename)
54
+ # @param force [Bool] should we override existing config
55
+ # @return [Bool] true if operation has completed successfully
56
+ def self.add(name, kwargs = {}, force=false)
57
+ chroots = readconf()
58
+ filename = CONF_D+name
59
+ if (chroots[name] or File.exists?(filename)) and !force
55
60
  return false
56
61
  else
57
62
  begin
@@ -64,9 +69,30 @@ class SchrootConfig
64
69
  kwargs.each do |param, value|
65
70
  stream.puts "#{param}=#{value}"
66
71
  end
72
+ stream.close
67
73
  end
68
74
  return true
69
75
  end
76
+
77
+ # Removes chroot from .../chroot.d/ directory
78
+ #
79
+ # @example
80
+ # SchrootConfig.remove("testing", true)
81
+ # => true
82
+ # @param name [String] name of chroot
83
+ # @param kwargs [Hash] options
84
+ # @param force [Bool] should we override existing config
85
+ # @return [Bool] true if operation has completed successfully
86
+ def self.remove(name, force=false)
87
+ chroots = readconf()
88
+ filename = CONF_D+name
89
+ if (File.exists?(filename) and chroots[name]) or force
90
+ File.delete(filename)
91
+ return true
92
+ else
93
+ return false
94
+ end
95
+ end
70
96
  end
71
97
 
72
98
  # Schroot session handler
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schroot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniil Guzanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-06 00:00:00.000000000 Z
11
+ date: 2014-05-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Schroot bindings
14
14
  email: melkor217@gmail.com
@@ -16,10 +16,10 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
- - lib/schroot.rb
20
- - test/test_schroot.rb
21
19
  - README.md
22
20
  - Rakefile
21
+ - lib/schroot.rb
22
+ - test/test_schroot.rb
23
23
  homepage: https://github.com/melkor217/ruby-schroot
24
24
  licenses:
25
25
  - WTFPL
@@ -30,17 +30,17 @@ require_paths:
30
30
  - lib
31
31
  required_ruby_version: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - '>='
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: 1.8.6
35
+ version: '0'
36
36
  required_rubygems_version: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  requirements: []
42
42
  rubyforge_project:
43
- rubygems_version: 2.0.14
43
+ rubygems_version: 2.2.2
44
44
  signing_key:
45
45
  specification_version: 4
46
46
  summary: Schroot bindings