/[gentoo-alt]/trunk/ruby-checker/package.rb
Gentoo

Contents of /trunk/ruby-checker/package.rb

Parent Directory Parent Directory | Revision Log Revision Log


Revision 940 - (hide annotations) (download)
Sun Dec 25 15:57:22 2005 UTC (8 years, 7 months ago) by flameeyes
File size: 3882 byte(s)
Add requirement of pmask unit.
1 flameeyes 793 require("rexml/document")
2    
3 flameeyes 940 require 'pmask.rb'
4    
5 flameeyes 793 # Package class define an unversioned atom and allows access to single ebuilds
6     class Package
7     def initialize(atom)
8     atom =~ /^([^\/]+)\/([^\/]+)/ # => Split the atom in category + name
9     @category = $1
10     @name = $2
11     end
12    
13     def ebuilds
14     list = Array.new # => New array
15     Dir.foreach("#{ENV["PORTDIR"]}/#{@category}/#{@name}") do |f|
16     # => looks for files in package's directory
17     list << f if f =~ /.*\.ebuild$/ # => if the file is an ebuild, add it to the list
18     end
19    
20     return list
21     end
22    
23     # restrict is a restriction applied to the atom (=..* restriction aren't supported for now)
24     # if mask is true the restriction will be considered as a mask (returns the ones not satisfying it)
25     def versions(restrict = '', mask = false)
26     name_re=@name.gsub('+', "[+]") # => Name for regexps
27     list = Array.new # => New array
28     for ebuild in ebuilds
29     ebuild =~ /#{name_re}-(.+)\.ebuild$/
30     # => Take out the version
31 flameeyes 861 list << Ebuild.new("#{@category}/#{@name}-#$1")
32 flameeyes 793 end
33    
34 flameeyes 883 list = list.sort
35 flameeyes 793
36     if restrict != '' && restrict != "#{@category}/#{@name}"
37     # => if we have a restriction (not full)
38     return list unless restrict =~ /^(>|>=|=|<=|<|~)#{@category}\/#{name_re}-(.+)\*?$/
39    
40     operator = $1 # => restriction operator
41     version = EbuildVersion.new($2) # => version to restrict to
42    
43     newlist = Array.new # => new list
44    
45     case operator
46     when '>'
47     list.each do |v|
48 flameeyes 862 newlist << v if v.version > version
49 flameeyes 793 end
50     when '>='
51     list.each do |v|
52 flameeyes 862 newlist << v if v.version >= version
53 flameeyes 793 end
54     when '='
55     list.each do |v|
56 flameeyes 862 newlist << v if v.version == version
57 flameeyes 793 end
58     when '<'
59     list.each do |v|
60 flameeyes 862 newlist << v if v.version < version
61 flameeyes 793 end
62     when '<='
63     list.each do |v|
64 flameeyes 862 newlist << v if v.version <= version
65 flameeyes 793 end
66     when '~'
67     list.each do |v|
68 flameeyes 862 newlist << v if v.version.isRevision(version)
69 flameeyes 793 end
70     end
71    
72     unless mask # =< If mask you must prune the list
73     return newlist
74     else
75     return list - newlist
76     end
77     end
78    
79 flameeyes 861 list_str = Array.new
80     list.each do |val|
81     list_str << val.to_s
82     end
83    
84     return list_str
85 flameeyes 793 end
86    
87     # Get unmasked versions, references package.mask file
88     def unmasked
89     all = versions
90    
91     masks = Pdotmask.new.masksfor("#{@category}/#{@name}")
92     masks.each do |mask|
93     all = all - versions(mask)
94     end
95    
96     return all
97     end
98    
99     def herds
100     return [] unless File.exists?("#{ENV["PORTDIR"]}/#{@category}/#{@name}/metadata.xml")
101     metadata = REXML::Document.new File.new("#{ENV["PORTDIR"]}/#{@category}/#{@name}/metadata.xml")
102     return [] unless metadata
103    
104     list = Array.new
105     metadata.elements.each("pkgmetadata/herd") { |el| list << el.text unless el.text == "no-herd" }
106     return list
107     end
108    
109     def maintainers
110     return [] unless File.exists?("#{ENV["PORTDIR"]}/#{@category}/#{@name}/metadata.xml")
111     metadata = REXML::Document.new File.new("#{ENV["PORTDIR"]}/#{@category}/#{@name}/metadata.xml")
112     return [] unless metadata
113    
114     list = Array.new
115     metadata.elements.each("pkgmetadata/maintainer/email") { |el| list << el.text unless el.text == "bug-wranglers@gentoo.org" }
116     return list
117     end
118    
119     attr_reader :category, :name
120     end
121    
122     ## Kate modeline: leave at the end
123     # kate: indent-width 2; replace-trailing-space-save 1; space-indent 1; backspace-indents 1;

  ViewVC Help
Powered by ViewVC 1.1.20