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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20