Class: Pkg_noisrev::FbsdPort
- Inherits:
-
Object
- Object
- Pkg_noisrev::FbsdPort
- Defined in:
- lib/pkg_noisrev/fbsdpackage.rb
Defined Under Namespace
Classes: Moved
Class Method Summary collapse
-
.moved(ports_dir) ⇒ Object
Parse /usr/ports/MOVED file into a hash.
-
.ver(ports_dir, origin, rlevel = 0) ⇒ Object
Return a string that represents a port version.
-
.ver_slow(ports_dir, origin) ⇒ Object
The last resort method of getting a version number: execute ‘make’ command.
Class Method Details
.moved(ports_dir) ⇒ Object
Parse /usr/ports/MOVED file into a hash. Return an empty hash on error.
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/pkg_noisrev/fbsdpackage.rb', line 330 def self.moved(ports_dir) db_moved = ports_dir + '/MOVED' r = {} begin File.open(db_moved) {|f| f.each {|line| next if line =~ /^\s*(#.*|\s*)$/ # comment or blank line next if (entry = line.split '|').size != 4 r[entry.first] = Moved.new *entry[1..-1] } } rescue Trestle.warnx "parsing #{db_moved} failed: #{$!}" return {} end r end |
.ver(ports_dir, origin, rlevel = 0) ⇒ Object
Return a string that represents a port version.
Tries to do that in 2 ways: (a) by primitive regexp parsing of Makefile and if that fails (b) by executing external ‘make’ command.
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/pkg_noisrev/fbsdpackage.rb', line 272 def self.ver(ports_dir, origin, rlevel = 0) fail "recursion level for #{origin} is too high" if rlevel >= 3 makefile = ports_dir + '/' + origin + '/' + 'Makefile' ver = {} begin File.open(makefile) {|f| f.each {|line| ['MASTERDIR', 'DISTVERSION', 'PORTVERSION', 'PORTREVISION', 'PORTEPOCH'].each {|idx| ver[idx] = $1 if line.match(/^\s*#{idx}\s*[?:!]?=\s*(\S+)$/) } } } rescue fail "(rlevel=#{rlevel}) #{$!}" end # Recursion! Some ports Makefiles don't contain version definitions # but a link to a 'master' port. if ver['MASTERDIR'] rlevel += 1 master_origin = ver['MASTERDIR'].sub(/\${.CURDIR}/, origin) return ver(ports_dir, master_origin, rlevel) end # check if vars contain sane values ok = true ver.each {|k,v| if v !~ /^[a-zA-Z0-9_,.-]+$/ ok = false # puts makefile break end } ver['PORTVERSION'] = ver['DISTVERSION'] = nil if !ok if ver['PORTVERSION'] || ver['DISTVERSION'] r = ver['PORTVERSION'] || ver['DISTVERSION'] r += "_#{ver['PORTREVISION']}" if ver['PORTREVISION'] r += ",#{ver['PORTEPOCH']}" if ver['PORTEPOCH'] return r end # try a dumb method return FbsdPort.ver_slow(ports_dir, origin) rescue fail "(rlevel=#{rlevel}) #{$!}" fail "(rlevel=#{rlevel}) cannot extract the version for #{makefile}" end |
.ver_slow(ports_dir, origin) ⇒ Object
The last resort method of getting a version number: execute ‘make’ command.
Return a string that represents a port version.
253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/pkg_noisrev/fbsdpackage.rb', line 253 def self.ver_slow(ports_dir, origin) # cannot use just a block for Dir.chdir due to a annoing warning # under the another thread dirsave = Dir.pwd Dir.chdir ports_dir + '/' + origin r = Trestle.cmd_run('make -V PKGVERSION') Dir.chdir dirsave fail "even executing make didn't help #{origin}" if r[0] != 0 r[2].strip end |