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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 793 - (show annotations) (download) (as text)
Sun Oct 2 13:43:15 2005 UTC (13 years, 6 months ago) by flameeyes
File MIME type: application/x-ruby
File size: 4603 byte(s)
Aded ruby script to run checks on the portage tree.
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 << "#{@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 v =~ /^#{@category}\/#{name_re}-(.*)$/
47 just_version = EbuildVersion.new($1) # => Split just the version
48 newlist << v if just_version > version
49 end
50 when '>='
51 list.each do |v|
52 v =~ /^#{@category}\/#{name_re}-(.*)$/
53 just_version = EbuildVersion.new($1) # => Split just the version
54 newlist << v if just_version >= version
55 end
56 when '='
57 list.each do |v|
58 v =~ /^#{@category}\/#{name_re}-(.*)$/
59 just_version = EbuildVersion.new($1) # => Split just the version
60 newlist << v if just_version == version
61 end
62 when '<'
63 list.each do |v|
64 v =~ /^#{@category}\/#{name_re}-(.*)$/
65 just_version = EbuildVersion.new($1) # => Split just the version
66 newlist << v if just_version < version
67 end
68 when '<='
69 list.each do |v|
70 v =~ /^#{@category}\/#{name_re}-(.*)$/
71 just_version = EbuildVersion.new($1) # => Split just the version
72 newlist << v if just_version <= version
73 end
74 when '~'
75 list.each do |v|
76 v =~ /^#{@category}\/#{name_re}-(.*)$/
77 just_version = EbuildVersion.new($1) # => Split just the version
78 newlist << v if just_version.isRevision(version)
79 end
80 end
81
82 unless mask # =< If mask you must prune the list
83 return newlist
84 else
85 return list - newlist
86 end
87 end
88
89 return list
90 end
91
92 # Get unmasked versions, references package.mask file
93 def unmasked
94 all = versions
95
96 masks = Pdotmask.new.masksfor("#{@category}/#{@name}")
97 masks.each do |mask|
98 all = all - versions(mask)
99 end
100
101 return all
102 end
103
104 def herds
105 return [] unless File.exists?("#{ENV["PORTDIR"]}/#{@category}/#{@name}/metadata.xml")
106 metadata = REXML::Document.new File.new("#{ENV["PORTDIR"]}/#{@category}/#{@name}/metadata.xml")
107 return [] unless metadata
108
109 list = Array.new
110 metadata.elements.each("pkgmetadata/herd") { |el| list << el.text unless el.text == "no-herd" }
111 return list
112 end
113
114 def maintainers
115 return [] unless File.exists?("#{ENV["PORTDIR"]}/#{@category}/#{@name}/metadata.xml")
116 metadata = REXML::Document.new File.new("#{ENV["PORTDIR"]}/#{@category}/#{@name}/metadata.xml")
117 return [] unless metadata
118
119 list = Array.new
120 metadata.elements.each("pkgmetadata/maintainer/email") { |el| list << el.text unless el.text == "bug-wranglers@gentoo.org" }
121 return list
122 end
123
124 attr_reader :category, :name
125 end
126
127 ## Kate modeline: leave at the end
128 # kate: indent-width 2; replace-trailing-space-save 1; space-indent 1; backspace-indents 1;

  ViewVC Help
Powered by ViewVC 1.1.20