[SCM] ci-tooling packaging branch, master, updated. 893c0e69e5a883f027ea496f0e2a302f95ed44df

Harald Sitter apachelogger-guest at moszumanska.debian.org
Mon Mar 16 15:48:40 UTC 2015


Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=701be5d

The following commit has been merged in the master branch:
commit 701be5d3eb385b9d2f6571067666176282b6aed9
Author: Harald Sitter <sitter at kde.org>
Date:   Mon Mar 16 13:48:36 2015 +0100

    write an lsb-release module
---
 lib/lsb.rb                     | 31 +++++++++++++++++++++++++++++++
 test/data/test_lsb/lsb-release |  4 ++++
 test/data/test_lsb/test_consts |  1 +
 test/data/test_lsb/test_parse  |  1 +
 test/test_lsb.rb               | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 70 insertions(+)

diff --git a/lib/lsb.rb b/lib/lsb.rb
new file mode 100644
index 0000000..7819e87
--- /dev/null
+++ b/lib/lsb.rb
@@ -0,0 +1,31 @@
+require 'shellwords'
+
+# Wrapper around lsb-release. Makes values available as non-introspectable
+# constants. For runtime introspection to_h should be used instead.
+module LSB
+  @file = '/etc/lsb-release'
+
+  def self.const_missing(name)
+    to_h[name] if to_h.key?(name)
+  end
+
+  module_function
+
+  def to_h
+    @hash ||= LSB.parse(File.read(@file).split($/))
+  end
+
+  private
+
+  def self.parse(lines)
+    hash = {}
+    lines.each do |line|
+      line.strip!
+      key, value = line.split('=')
+      value = Shellwords.split(value)
+      value = value[0] if value.size == 1
+      hash[key.to_sym] = value
+    end
+    hash
+  end
+end
diff --git a/test/data/test_lsb/lsb-release b/test/data/test_lsb/lsb-release
new file mode 100644
index 0000000..deaf4d2
--- /dev/null
+++ b/test/data/test_lsb/lsb-release
@@ -0,0 +1,4 @@
+DISTRIB_ID=Ubuntu
+DISTRIB_RELEASE=15.04
+DISTRIB_CODENAME=vivid
+DISTRIB_DESCRIPTION="Ubuntu Vivid Vervet (development branch)"
diff --git a/test/data/test_lsb/test_consts b/test/data/test_lsb/test_consts
new file mode 120000
index 0000000..c2f8954
--- /dev/null
+++ b/test/data/test_lsb/test_consts
@@ -0,0 +1 @@
+lsb-release
\ No newline at end of file
diff --git a/test/data/test_lsb/test_parse b/test/data/test_lsb/test_parse
new file mode 120000
index 0000000..c2f8954
--- /dev/null
+++ b/test/data/test_lsb/test_parse
@@ -0,0 +1 @@
+lsb-release
\ No newline at end of file
diff --git a/test/test_lsb.rb b/test/test_lsb.rb
new file mode 100644
index 0000000..37048df
--- /dev/null
+++ b/test/test_lsb.rb
@@ -0,0 +1,33 @@
+require 'test/unit'
+
+require_relative '../lib/lsb'
+
+# Test lsb
+class LSBTest < Test::Unit::TestCase
+  def setup
+    script_base_path = File.expand_path(File.dirname(__FILE__))
+    script_name = File.basename(__FILE__, '.rb')
+    @datadir = File.join(script_base_path, 'data', script_name)
+
+    @orig_file = LSB.instance_variable_get(:@file)
+    LSB.instance_variable_set(:@file, File.join(@datadir, method_name))
+  end
+
+  def teardown
+    LSB.instance_variable_set(:@file, @orig_file)
+  end
+
+  def test_parse
+    ref = { :DISTRIB_ID => 'Ubuntu',
+            :DISTRIB_RELEASE => '15.04',
+            :DISTRIB_CODENAME => 'vivid',
+            :DISTRIB_DESCRIPTION => 'Ubuntu Vivid Vervet (development branch)'
+    }
+    assert_equal(ref, LSB.to_h)
+  end
+
+  def test_consts
+    assert_equal('Ubuntu', LSB::DISTRIB_ID)
+    assert_equal('vivid', LSB::DISTRIB_CODENAME)
+  end
+end

-- 
ci-tooling packaging



More information about the pkg-kde-commits mailing list