Module: Puppet::Util::PTomulik::Packagex::Portsx::PkgSearch
- Includes:
- Functions
- Included in:
- Puppet::Util::PTomulik::Packagex::Portsx
- Defined in:
- lib/puppet/util/ptomulik/packagex/portsx/pkg_search.rb
Overview
One method is useful for mortals, the #search_packages method.
Constant Summary collapse
- PORTVERSION_MAX_NAMES =
Maximum number of package names provided to ‘portversion` when searching installed ports. Used by #portversion_search. If there is more names requested by caller, the search will be divided into mutliple stages (max 60 names per stage) to keep commandline of reasonable length at each stage.
60
Constants included from Functions
Functions::PKGNAME_RE, Functions::PORTNAME_RE, Functions::PORTORIGIN_RE, Functions::PORTVERSION_RE
Instance Method Summary collapse
- #execute_portversion(args, options = {}) ⇒ Object
-
#portversion_command(args, options) ⇒ Object
Return ‘portversion …’ command (as array) to be used with execpipe().
-
#portversion_search(names = nil, args = [], options = {}) { ... } ⇒ Object
Search for installed ports.
-
#search_packages(names = nil, fields = PkgRecord.default_fields, options = {}) {|[String,PkgRecord]|PkgRecord| ... } ⇒ Object
Search installed packages.
- #sort_names_for_portversion(names) ⇒ Object
Methods included from Functions
#escape_pattern, #fullname_to_pattern, #mk_search_pattern, #options_files, #pkgname?, #pkgname_to_pattern, #pkgng_active?, #port_dbdir, #portname?, #portname_to_pattern, #portorigin?, #portorigin_to_pattern, #portsdir, #split_pkgname, #strings_to_pattern
Instance Method Details
#execute_portversion(args, options = {}) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/puppet/util/ptomulik/packagex/portsx/pkg_search.rb', line 176 def execute_portversion(args, = {}) key_check = determine_portversion_key_check(args) execpipe = [:execpipe] || Puppet::Util::Execution.method(:execpipe) cmd = portversion_command(args, ) execpipe.call(cmd) do |process| process.each_line do |line| fields = line.strip.split(/\s+/,3) # portversion sometimes puts garbage to its output; we skip such lines if key_check.call(fields.first) yield fields end end end end |
#portversion_command(args, options) ⇒ Object
Return ‘portversion …’ command (as array) to be used with execpipe().
192 193 194 195 196 |
# File 'lib/puppet/util/ptomulik/packagex/portsx/pkg_search.rb', line 192 def portversion_command(args, ) portversion = [:portversion] || (self.respond_to?(:command) ? command(:portversion) : 'portversion') [portversion, *(args.flatten)] end |
#portversion_search(names = nil, args = [], options = {}) { ... } ⇒ Object
Search for installed ports.
This method calls ‘portversion` to search through installed ports.
The yielded ‘fields` (see below) are formed as follows:
-
‘fields` - contains the portname, pkgname or portorigin depending on what was printed by `portversion` (depending on flags in `args`),
-
‘fields` (optional) - contains the port status, it’s a single character, one of ‘<`, `=`, `>`, `?`, `!`, `#`
-
‘fields` (optional) - contains additional information about available update for the package
What is particularly yielded by #portversion_search dependends on ‘args`. See [portversion(1)](www.freebsd.org/cgi/man.cgi?query=portversion&manpath=ports&sektion=1).
Supported ‘options` are:
-
:execpipe - custom execpipe method (used to call ‘portversion`),
-
options supported by the #portversion_command method.
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/puppet/util/ptomulik/packagex/portsx/pkg_search.rb', line 120 def portversion_search(names=nil, args=[], ={}) if names names = sort_names_for_portversion(names) names.each_slice(PORTVERSION_MAX_NAMES) do |slice| portversion_search_1(slice, args, ) { |xfields| yield xfields } end else execute_portversion(args, ) { |fields| yield fields } end end |
#search_packages(names = nil, fields = PkgRecord.default_fields, options = {}) {|[String,PkgRecord]|PkgRecord| ... } ⇒ Object
Search installed packages
**Usage example 1**:
search_packages do |record|
print "#{record.inspect}\n\n"
end
**Usage example 2**:
search_packages(['apache22', 'lang/ruby']) do |name,record|
print "#{name}:\n"
print "#{record.inspect}\n\n"
end
38 39 40 41 42 43 44 45 46 |
# File 'lib/puppet/util/ptomulik/packagex/portsx/pkg_search.rb', line 38 def search_packages(names=nil, fields=PkgRecord.default_fields, ={}) amend = names ? lambda {|r| r[1].amend!(fields)} : lambda {|r| r.amend!(fields)} search_fields = PkgRecord.determine_search_fields(fields) search_packages_1(names,search_fields,) do |record| amend.call(record) yield record end end |
#sort_names_for_portversion(names) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/puppet/util/ptomulik/packagex/portsx/pkg_search.rb', line 164 def sort_names_for_portversion(names) # XXX: portversion (at least 2.4.11) sorts its output by pkgname/portname, # so we must do the same with input list to match ones to the others; this # is horrible and there are no docs saying that this sorting method is # guaranted; for now we just have to live with this uncertainity. names.sort{ |a,b| a = a.split('/').last if portorigin?(a) b = b.split('/').last if portorigin?(b) a <=> b } end |