linux-lxc 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e86c7168089ae71c61a0ce55cd11ad3ec15b857d
4
- data.tar.gz: 179ee22a4ce4e3a2c707db3700cb009f2fc4a668
3
+ metadata.gz: c561e17dc08b0113ac3e405952735e7e525ed368
4
+ data.tar.gz: f26d4595440b473efa4a1e3f22c0d3cf6afcdf68
5
5
  SHA512:
6
- metadata.gz: b81e2d74d31261d884b83e4660dfe1d69cc522f669804d8a403178dc773987727e49d255ad5649448d6ef4bace80fdb5770d2cdb2eca17d5476147b2a294eae5
7
- data.tar.gz: 31936e38061c98f764b0d616ee4a1f15c980759c71e8d955bc95c9cec940a614d176507bb1953c109304445d16abfe52dd2e547cd24c6ed8610f621bf73e1028
6
+ metadata.gz: 1e48d4c369c63a3a4f208208bb904b7d2af9fc09dcddef6af904d20fa6e982df3b1f65907780c21faeae18332399596aee1384e961ab8368446666778c346057
7
+ data.tar.gz: c6db6179afede394feaa37c85bbac3bb253c0badd7a10b05d4fd68b01c3db92e703d1cf851a1d63b3e94c9cd36ac00965b410a21ce16577c8c6c21fa65d655de
@@ -18,8 +18,9 @@ module Linux
18
18
  return if @key == '#'
19
19
  # remove from index
20
20
  lxc.remove_from_index(self)
21
+ uncomment = to_s
21
22
  @key = '#'
22
- @value = '# ' + to_s
23
+ @value = '# ' + uncomment
23
24
  lxc.add_to_index(self)
24
25
  end
25
26
 
@@ -14,6 +14,10 @@ module Linux
14
14
  @lines.each { |line| block.call(line) }
15
15
  end
16
16
 
17
+ def select(&block)
18
+ @lines.select { |line| block.call(line) }
19
+ end
20
+
17
21
  def find(&block)
18
22
  @lines.find(&block)
19
23
  end
@@ -1,5 +1,5 @@
1
1
  module Linux
2
2
  module Lxc
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'
4
4
  end
5
5
  end
data/lib/linux/lxc.rb CHANGED
@@ -7,12 +7,28 @@ require_relative 'lxc/index'
7
7
 
8
8
  module Linux
9
9
  module Lxc
10
+ def self.numeric_prefix_order(data)
11
+ data.sort do |a,b|
12
+ a_m = a.match(/^(\d+)(.*)$/)
13
+ b_m = b.match(/^(\d+)(.*)$/)
14
+ if a_m && b_m
15
+ ret = a_m[1].to_i <=> b_m[1].to_i
16
+ if ret == 0
17
+ ret = a_m[2] <=> b_m[2]
18
+ end
19
+ ret
20
+ else
21
+ a <=> b
22
+ end
23
+ end
24
+ end
25
+
10
26
  def self.parse(file, index = Index.new)
11
27
  if ::File.directory?(file)
12
28
  fname = file
13
29
  entries = ::Dir.glob(::File.join(file, '*.conf')).select { |f| ::File.file?(f) }
14
30
  dir = index.get_directory(fname)
15
- entries.each do |entry|
31
+ numeric_prefix_order(entries).each do |entry|
16
32
  dir.add_file(entry).parse
17
33
  end
18
34
  return dir
@@ -203,6 +203,7 @@ SAMPLE
203
203
  assert_equal lxc.get('#').length, 43
204
204
  lxc.get('lxc.network').comment!
205
205
  assert_equal lxc.get('#').length, 47
206
+ assert_equal lxc.get('#')[45].to_s, '# lxc.network.link = lxcbr0'
206
207
  assert_equal lxc.get('lxc.network'), nil
207
208
  lxc.index.files.values.each do |file|
208
209
  file.real_fname = ::File.join(::File.dirname(file.file), "-.#{::File.basename(file.file)}")
@@ -290,4 +291,12 @@ SAMPLE
290
291
  assert_equal lxc_read.get('lxc.network.hwaddr').first.file, lxc.file
291
292
  assert_equal lxc_read.get('lxc.network.hwaddr').first.line, 18
292
293
  end
294
+
295
+ def test_numeric_prefix_order
296
+ assert_equal Linux::Lxc.numeric_prefix_order(["100_a", "1_b", "34d"]), ["1_b","34d","100_a"]
297
+ assert_equal Linux::Lxc.numeric_prefix_order(["1_c", "1_a", "1a"]), ["1_a","1_c","1a"]
298
+ assert_equal Linux::Lxc.numeric_prefix_order(["000100_a", "000001_b", "034d"]), ["000001_b","034d","000100_a"]
299
+ assert_equal Linux::Lxc.numeric_prefix_order(["foo","100_a", "000001_b", "bar", "34d"]), ["000001_b","34d","100_a","bar", "foo"]
300
+ assert_equal Linux::Lxc.numeric_prefix_order(["foo","yyy", "bar"]), ["bar", "foo", "yyy"]
301
+ end
293
302
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux-lxc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meno Abels
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-17 00:00:00.000000000 Z
11
+ date: 2015-10-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Parse the output of ip addr on a linux system
14
14
  email: