Gentoo Archives: gentoo-commits

From: "André Erdmann" <dywi@×××××××.de>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/stats/
Date: Fri, 02 Aug 2013 10:34:46
Message-Id: 1375438804.a343c180f2d22c0411086c3dbca5eb2d85da235e.dywi@gentoo
1 commit: a343c180f2d22c0411086c3dbca5eb2d85da235e
2 Author: André Erdmann <dywi <AT> mailerd <DOT> de>
3 AuthorDate: Fri Aug 2 10:20:04 2013 +0000
4 Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
5 CommitDate: Fri Aug 2 10:20:04 2013 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=a343c180
7
8 stats collection: has_changes(), count imports
9
10 * overlay_has_changes()
11 * count imported ebuilds
12
13 ---
14 roverlay/stats/abstract.py | 54 ++++++++++++++++++++++++++++++++++++++++-----
15 roverlay/stats/base.py | 36 ++++++++++++++++++++++++------
16 roverlay/stats/collector.py | 7 ++++++
17 3 files changed, 84 insertions(+), 13 deletions(-)
18
19 diff --git a/roverlay/stats/abstract.py b/roverlay/stats/abstract.py
20 index 68728f4..5ac87bc 100644
21 --- a/roverlay/stats/abstract.py
22 +++ b/roverlay/stats/abstract.py
23 @@ -9,7 +9,8 @@ from __future__ import division
24 import collections
25 import time
26
27 -from roverlay.util.objects import MethodNotImplementedError
28 +import roverlay.util.objects
29 +from roverlay.util.objects import MethodNotImplementedError, abstractmethod
30
31
32 class RoverlayStatsBase ( object ):
33 @@ -47,15 +48,15 @@ class RoverlayStatsBase ( object ):
34 getattr ( self, member ).merge_with ( getattr ( other, member ) )
35 # --- end of merge_members (...) ---
36
37 - def _iter_members ( self, nofail=False ):
38 + def iter_members ( self, nofail=False ):
39 if not nofail or hasattr ( self, '_MEMBERS' ):
40 for member in self.__class__._MEMBERS:
41 yield getattr ( self, member )
42 - # --- end of _iter_members (...) ---
43 + # --- end of iter_members (...) ---
44
45 def has_nonzero ( self ):
46 if hasattr ( self, '_MEMBERS' ):
47 - for member in self._iter_members():
48 + for member in self.iter_members():
49 if int ( member ) != 0:
50 return member
51 else:
52 @@ -63,7 +64,7 @@ class RoverlayStatsBase ( object ):
53 # --- end of has_nonzero (...) ---
54
55 def reset_members ( self ):
56 - for member in self._iter_members():
57 + for member in self.iter_members():
58 member.reset()
59 # --- end of reset_members (...) ---
60
61 @@ -86,7 +87,7 @@ class RoverlayStatsBase ( object ):
62 if desc:
63 yield desc
64
65 - for member in self._iter_members( nofail=True ):
66 + for member in self.iter_members( nofail=True ):
67 yield str ( member )
68 # --- end of gen_str (...) ---
69
70 @@ -103,6 +104,15 @@ class RoverlayStatsBase ( object ):
71
72 class RoverlayStats ( RoverlayStatsBase ):
73 pass
74 +
75 + @abstractmethod
76 + def has_changes ( self ):
77 + """Returns True if this stats item has any numbers indicating that
78 + the overlay has changes.
79 + """
80 + return False
81 + # --- end of has_changes (...) ---
82 +
83 # --- end of RoverlayStats ---
84
85
86 @@ -143,6 +153,10 @@ class TimeStats ( RoverlayStats ):
87 self._timestats = collections.OrderedDict()
88 # --- end of __init__ (...) ---
89
90 + def has_changes ( self ):
91 + return False
92 + # --- end of has_changes (...) ---
93 +
94 def merge_with ( self, other ):
95 self._timestats.update ( other._timestats )
96 # --- end of merge_with (...) ---
97 @@ -225,6 +239,10 @@ class Counter ( RoverlayStatsBase ):
98 return float ( self.total_count )
99 # --- end of __float__ (...) ---
100
101 + def __bool__ ( self ):
102 + return bool ( self.total_count )
103 + # --- end of __bool__ (...) ---
104 +
105 def __add__ ( self, other ):
106 return self.total_count + int ( other )
107 # --- end of __add__ (...) ---
108 @@ -233,6 +251,30 @@ class Counter ( RoverlayStatsBase ):
109 return self.total_count - int ( other )
110 # --- end of __sub__ (...) ---
111
112 + def __gt__ ( self, other ):
113 + return self.total_count > int ( other )
114 + # --- end of __gt__ (...) ---
115 +
116 + def __ge__ ( self, other ):
117 + return self.total_count >= int ( other )
118 + # --- end of __ge__ (...) ---
119 +
120 + def __lt__ ( self, other ):
121 + return self.total_count < int ( other )
122 + # --- end of __lt__ (...) ---
123 +
124 + def __le__ ( self, other ):
125 + return self.total_count <= int ( other )
126 + # --- end of __le__ (...) ---
127 +
128 + def __eq__ ( self, other ):
129 + return self.total_count == int ( other )
130 + # --- end of __eq__ (...) ---
131 +
132 + def __ne__ ( self, other ):
133 + return self.total_count != int ( other )
134 + # --- end of __ne__ (...) ---
135 +
136 def has_details ( self ):
137 return False
138 # --- end of has_details (...) ---
139
140 diff --git a/roverlay/stats/base.py b/roverlay/stats/base.py
141 index 28531c2..282ff78 100644
142 --- a/roverlay/stats/base.py
143 +++ b/roverlay/stats/base.py
144 @@ -19,6 +19,10 @@ class RepoStats ( abstract.RoverlayStats ):
145 )
146 # --- end of __init__ (...) ---
147
148 + def has_changes ( self ):
149 + return False
150 + # --- end of has_changes (...) ---
151 +
152 def package_file_found ( self, repo ):
153 self.pkg_count.inc ( repo.name )
154 # --- end of add_package (...) ---
155 @@ -37,6 +41,10 @@ class DistmapStats ( abstract.RoverlayStats ):
156 )
157 # --- end of __init__ (...) ---
158
159 + def has_changes ( self ):
160 + return False
161 + # --- end of has_changes (...) ---
162 +
163 def file_added ( self, *origin ):
164 self.pkg_count.inc ( *origin )
165 # --- end of file_added (...) ---
166 @@ -58,6 +66,10 @@ class OverlayCreationWorkerStats ( abstract.RoverlayStats ):
167 self.pkg_success = abstract.Counter ( "success" )
168 # --- end of __init__ (...) ---
169
170 + def has_changes ( self ):
171 + return bool ( self.pkg_success )
172 + # --- end of has_changes (...) ---
173 +
174 # --- end of OverlayCreationWorkerStats ---
175
176
177 @@ -103,24 +115,34 @@ class OverlayStats ( abstract.RoverlayStats ):
178
179 _MEMBERS = (
180 'scan_time', 'write_time',
181 - 'ebuilds_scanned', 'ebuild_count', 'revbump_count', 'ebuilds_written',
182 + 'ebuilds_scanned', 'ebuild_count', 'revbump_count',
183 + 'ebuilds_imported', 'ebuilds_written',
184 )
185
186 def __init__ ( self ):
187 super ( OverlayStats, self ).__init__()
188 # ebuilds_scanned: ebuild count prior to running overlay creation
189 - self.ebuilds_scanned = abstract.Counter ( "pre" )
190 + self.ebuilds_scanned = abstract.Counter ( "pre" )
191
192 # ebuild count: ebuild count after writing the overlay
193 - self.ebuild_count = abstract.Counter ( "post" )
194 + self.ebuild_count = abstract.Counter ( "post" )
195
196 - self.revbump_count = abstract.Counter ( "revbumps" )
197 - self.ebuilds_written = abstract.Counter ( "written" )
198 + self.revbump_count = abstract.Counter ( "revbumps" )
199 + self.ebuilds_written = abstract.Counter ( "written" )
200 + self.ebuilds_imported = abstract.Counter ( "imported" )
201
202 - self.write_time = abstract.TimeStats ( "write_time" )
203 - self.scan_time = abstract.TimeStats ( "scan_time" )
204 + self.write_time = abstract.TimeStats ( "write_time" )
205 + self.scan_time = abstract.TimeStats ( "scan_time" )
206 # --- end of __init__ (...) ---
207
208 + def has_changes ( self ):
209 + return (
210 + ( self.ebuild_count - self.ebuilds_scanned ) != 0 or
211 + self.ebuilds_written > 0 or
212 + self.revbump_count > 0
213 + )
214 + # --- end of has_changes (...) ---
215 +
216 def set_ebuild_written ( self, p_info ):
217 self.ebuilds_written.inc()
218 # direct dict access
219
220 diff --git a/roverlay/stats/collector.py b/roverlay/stats/collector.py
221 index 85eb358..ebae1a6 100644
222 --- a/roverlay/stats/collector.py
223 +++ b/roverlay/stats/collector.py
224 @@ -26,6 +26,13 @@ class StatsCollector ( abstract.RoverlayStatsBase ):
225 return cls._instance
226 # --- end of instance (...) ---
227
228 + def overlay_has_any_changes ( self ):
229 + """Returns True if the resulting overlay has any changes (according to
230 + stats).
231 + """
232 + return any ( x.has_changes() for x in self.iter_members() )
233 + # --- end of overlay_has_any_changes (...) ---
234 +
235 def get_success_ratio ( self ):
236 # success ratio for "this" run:
237 # new ebuilds / relevant package count (new packages - unsuitable,