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

Contents of /trunk/ruby-checker/ebuild.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: 4699 byte(s)
Remove debug output and update masking code to the new 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.revision < @revision # => other's revision older
61 return -1
62 elsif other.revision > @revision # => other's revision younger
63 return 1
64 end
65
66 return 0
67 end
68
69 # Other comparing methods
70 def >(other)
71 return (other <=> self) > 0
72 end
73 def >=(other)
74 return (other <=> self) >= 0
75 end
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
86 def isRevision(other)
87 return other.onlyVersion == onlyVersion
88 end
89
90 def onlyVersion()
91 return "#{@version.join('.')}#{@suffix}" + ( (@portage_kind != '' ) ? "_#{@portage_kind}#{@portage_numb}" : "" )
92 end
93
94 def to_s
95 return "#{@version.join('.')}#{@suffix}" + ( (@portage_kind != '' ) ? "_#{@portage_kind}#{@portage_numb}" : "" ) + ( (@revision.to_i > 0 ) ? "-r#{@revision}" : "" )
96 end
97
98 attr_reader :version, :suffix, :portage_kind, :portage_numb, :revision
99 end
100
101 # Simple ebuild parser class
102 class Ebuild
103 def initialize(atom)
104 atom =~ /^([^\/]+)\/([A-Za-z0-9\-+_]+)-([0-9]+(\.[0-9]+)?.*)$/
105 @category = $1
106 @name = $2
107 @version = EbuildVersion.new($3)
108 end
109
110 def to_s
111 return "#{@category}/#{@name}-#{@version.to_s}"
112 end
113
114 def ebuild
115 return "#{@category}/#{@name}/#{@name}-#{@version.to_s}.ebuild"
116 end
117
118 def iuse
119 return variable("IUSE").split(/\s/)
120 end
121
122 def variable(var)
123 predef_var = ["WORKDIR", "A", "P", "PN"]
124 return "" if predef_var.index(var)
125
126 ebcontent = IO.read("#{ENV["PORTDIR"]}/#{@category}/#{@name}/#{@name}-#{@version.to_s}.ebuild")
127
128 if ebcontent =~ /#{var}="([^"]*)"/m # => If we're able to find it quoted..
129 value = $1.tr("\n\t", ' ')
130 elsif ebcontent =~ /#{var}=([^"\s]+)/
131 value = $1
132 else
133 value = ""
134 end
135
136 while value =~ /(\$\{?([A-Za-z]+)\}?)[^{}]*/
137 value = value.sub("#$1", variable($2))
138 puts value
139 end
140
141 value
142 end
143
144 def function(func)
145 ebcontent = IO.read("#{ENV["PORTDIR"]}/#{@category}/#{@name}/#{@name}-#{@version.to_s}.ebuild")
146 #ebcontent =~ /^#{func}\s*\(\)\s*\{\s*$([^\{]+\{[^\}]+\}[^\{].|.+)^\}\s*$/m
147 return $1
148 end
149
150 def <=>(other)
151 @version <=> other.version
152 end
153
154 attr_reader :version
155 end
156
157 ## Kate modeline: leave at the end
158 # kate: indent-width 2; replace-trailing-space-save 1; space-indent 1; backspace-indents 1;

  ViewVC Help
Powered by ViewVC 1.1.20