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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20