Module: Puppet::Util::PTomulik::Package::Ports::PkgSearch
- Included in:
- Puppet::Util::PTomulik::Package::Ports
- Defined in:
- lib/puppet/util/ptomulik/package/ports/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 Execution
Methods included from Functions
#escape_pattern, #fullname_to_pattern, #mk_search_pattern, #options_files, #options_files_default_syntax, #options_files_portorigin, #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
179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/puppet/util/ptomulik/package/ports/pkg_search.rb', line 179 def execute_portversion(args, = {}) key_check = determine_portversion_key_check(args) cmd = portversion_command(args, ) execute_command(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().
194 195 196 197 198 |
# File 'lib/puppet/util/ptomulik/package/ports/pkg_search.rb', line 194 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.
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/puppet/util/ptomulik/package/ports/pkg_search.rb', line 123 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
41 42 43 44 45 46 47 48 49 |
# File 'lib/puppet/util/ptomulik/package/ports/pkg_search.rb', line 41 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
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/puppet/util/ptomulik/package/ports/pkg_search.rb', line 167 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 |