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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 883 - (show annotations) (download)
Tue Nov 15 12:34:16 2005 UTC (8 years, 5 months ago) by flameeyes
File size: 4913 byte(s)
Finally fixed ordering logic.
1 # Basic utilities for ebuild manipulation
2
3 # Simple class to order ebuils by version
4 # Simple examples:
5 # 1.0.1_beta
6 # 1.0.1
7 # 1.0.1_p1
8 # 1.0.1a
9 # 1.1
10 class EbuildVersion
11 def initialize(version)
12 version =~ /^([0-9.]+)([a-z]*)(_(alpha|beta|pre|rc|p)([0-9]*))?(-r([0-9]+))?$/
13 # => This splits the version in components
14
15 verstr = $1
16 @suffix = $2 != nil ? $2 : '' # => take the suffix (or empty if nothing)
17 @portage_kind = $4 != nil ? $4 : '' # => take the kind of portage suffix
18 @portage_numb = $5 != nil ? $5 : 0 # => take the level of suffix
19 @revision = $7 != nil ? $7.to_i : 0 # => take the revision
20 @version = verstr.split('.') # => split the version in an array of numbers
21 end
22
23 def <=>(other)
24 len = @version.length
25 len = other.version.length unless other.version.length < @version.length
26 for ti in 0...len # => First of all, check the version
27 if @version[ti] == nil && other.version[ti] == nil
28 break
29 else
30 ov = other.version[ti].to_i
31 ov = 0 unless ov
32 cv = @version[ti].to_i
33 cv = 0 unless cv
34 if ov > cv
35 # => if there's no indexed value on other (and we're not 0),
36 # or it's lesser, return 1 (minor)
37 return -1
38 elsif ( ov < cv ) # => if the other has a greater index return -1 (major)
39 return 1
40 end
41 end
42 end
43
44 if ( other.suffix > @suffix ) # => if they don't have one or our is greater
45 return -1
46 elsif ( other.suffix < @suffix ) # => if their is greater
47 return 1
48 end
49
50 portage_versions = [ 'alpha', 'beta', 'pre', 'rc', '', 'p' ]
51
52 if portage_versions.index(other.portage_kind) > portage_versions.index(@portage_kind)
53 # => if the other's portage kind is older..
54 return -1
55 elsif portage_versions.index(other.portage_kind) < portage_versions.index(@portage_kind)
56 # => if the other's portage is younger
57 return 1
58 end
59
60 if other.portage_numb > @portage_numb # => other's revision older
61 return -1
62 elsif other.portage_numb < @portage_numb # => other's revision younger
63 return 1
64 end
65
66 if other.revision > @revision # => other's revision older
67 return -1
68 elsif other.revision < @revision # => other's revision younger
69 return 1
70 end
71
72 return 0
73 end
74
75 # Other comparing methods
76 def >(other)
77 return (other <=> self) < 0
78 end
79 def >=(other)
80 return (other <=> self) <= 0
81 end
82 def ==(other)
83 return (other <=> self) == 0
84 end
85 def <=(other)
86 return (other <=> self) >= 0
87 end
88 def <(other)
89 return (other <=> self) > 0
90 end
91
92 def isRevision(other)
93 return other.onlyVersion == onlyVersion
94 end
95
96 def onlyVersion()
97 return "#{@version.join('.')}#{@suffix}" + ( (@portage_kind != '' ) ? "_#{@portage_kind}#{@portage_numb}" : "" )
98 end
99
100 def to_s
101 return "#{@version.join('.')}#{@suffix}" + ( (@portage_kind != '' ) ? "_#{@portage_kind}#{@portage_numb}" : "" ) + ( (@revision.to_i > 0 ) ? "-r#{@revision}" : "" )
102 end
103
104 attr_reader :version, :suffix, :portage_kind, :portage_numb, :revision
105 end
106
107 # Simple ebuild parser class
108 class Ebuild
109 def initialize(atom)
110 atom =~ /^([^\/]+)\/([A-Za-z0-9\-+_]+)-([0-9]+(\.[0-9]+)?.*)$/
111 @category = $1
112 @name = $2
113 @version = EbuildVersion.new($3)
114 end
115
116 def to_s
117 return "#{@category}/#{@name}-#{@version.to_s}"
118 end
119
120 def ebuild
121 return "#{@category}/#{@name}/#{@name}-#{@version.to_s}.ebuild"
122 end
123
124 def iuse
125 return variable("IUSE").split(/\s/)
126 end
127
128 def variable(var)
129 predef_var = ["WORKDIR", "A", "P", "PN"]
130 return "" if predef_var.index(var)
131
132 ebcontent = IO.read("#{ENV["PORTDIR"]}/#{@category}/#{@name}/#{@name}-#{@version.to_s}.ebuild")
133
134 if ebcontent =~ /#{var}="([^"]*)"/m # => If we're able to find it quoted..
135 value = $1.tr("\n\t", ' ')
136 elsif ebcontent =~ /#{var}=([^"\s]+)/
137 value = $1
138 else
139 value = ""
140 end
141
142 while value =~ /(\$\{?([A-Za-z]+)\}?)[^{}]*/
143 value = value.sub("#$1", variable($2))
144 puts value
145 end
146
147 value
148 end
149
150 def function(func)
151 ebcontent = IO.read("#{ENV["PORTDIR"]}/#{@category}/#{@name}/#{@name}-#{@version.to_s}.ebuild")
152 #ebcontent =~ /^#{func}\s*\(\)\s*\{\s*$([^\{]+\{[^\}]+\}[^\{].|.+)^\}\s*$/m
153 return $1
154 end
155
156 def <=>(other)
157 @version <=> other.version
158 end
159
160 attr_reader :version
161 end
162
163 ## Kate modeline: leave at the end
164 # kate: indent-width 2; replace-trailing-space-save 1; space-indent 1; backspace-indents 1;

  ViewVC Help
Powered by ViewVC 1.1.20