Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/148512

Change subject: wmflib: add apt_version()
......................................................................

wmflib: add apt_version()

Gets the version of an apt package. If the package is installed, gets
the installed version. If not, gets the candidate version. If no such
package exists, returns nil.

   apt_version('apache2')  # => "2.4.7-1ubuntu4"
   apt_version('fake123')  # => nil

Change-Id: I7b12c2b2061d83d5724aabe594979aa01772618e
---
A modules/wmflib/lib/puppet/parser/functions/apt_version.rb
1 file changed, 36 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/12/148512/1

diff --git a/modules/wmflib/lib/puppet/parser/functions/apt_version.rb 
b/modules/wmflib/lib/puppet/parser/functions/apt_version.rb
new file mode 100644
index 0000000..bbe3395
--- /dev/null
+++ b/modules/wmflib/lib/puppet/parser/functions/apt_version.rb
@@ -0,0 +1,36 @@
+# == Function: apt_version
+#
+# === Description
+#
+# Gets the version of an apt package. If the package is installed, gets
+# the installed version. If not, gets the candidate version. If no such
+# package exists, returns nil.
+#
+# === Examples
+#
+#    apt_version('apache2')  # => "2.4.7-1ubuntu4"
+#    apt_version('fake123')  # => nil
+#
+module Puppet::Parser::Functions
+  newfunction(
+    :apt_version,
+    :type => :rvalue,
+    :doc  => <<-END
+      Gets the version of an apt package. If the package is installed, gets
+      the installed version. If not, gets the candidate version. If no such
+      package exists, returns nil.
+
+      Examples:
+
+         apt_version('apache2')  # => "2.4.7-1ubuntu4"
+         apt_version('fake123')  # => nil
+
+    END
+  ) do |args|
+    unless args.length == 1 and args.first.is_a? String
+        raise Puppet::ParseError, 'apt_version() takes a single string 
argument'
+    end
+    cmd = "/usr/bin/apt-cache policy -q #{args.first} 2>/dev/null"
+    /: ([^(]\S*)/ =~ Facter::Util::Resolution.exec(cmd) ? $1 : nil
+  end
+end

-- 
To view, visit https://gerrit.wikimedia.org/r/148512
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7b12c2b2061d83d5724aabe594979aa01772618e
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to