Gentoo Archives: gentoo-commits

From: "Sławek Lis" <lis.slawek@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoolkit:revdep-rebuild commit in: pym/gentoolkit/revdep_rebuild/
Date: Tue, 02 Oct 2012 06:42:59
Message-Id: 1349160241.bb34f3532d586186a009a08c0e40c9d5fda91fb5.slis@gentoo
1 commit: bb34f3532d586186a009a08c0e40c9d5fda91fb5
2 Author: Slawek <lis.slawek <AT> gmail <DOT> com>
3 AuthorDate: Tue Oct 2 06:44:01 2012 +0000
4 Commit: Sławek Lis <lis.slawek <AT> gmail <DOT> com>
5 CommitDate: Tue Oct 2 06:44:01 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=bb34f353
7
8 Cleanup in revdep-rebuild file; improved multi-core analyzing (speedup on multi-core cpu to about 60% original time)
9
10 ---
11 pym/gentoolkit/revdep_rebuild/analyse.py | 5 +
12 pym/gentoolkit/revdep_rebuild/rebuild.py | 9 ++-
13 pym/gentoolkit/revdep_rebuild/revdep-rebuild.py | 17 ++++
14 pym/gentoolkit/revdep_rebuild/runner.py | 114 +++++++++++++++++++++++
15 4 files changed, 144 insertions(+), 1 deletions(-)
16
17 diff --git a/pym/gentoolkit/revdep_rebuild/analyse.py b/pym/gentoolkit/revdep_rebuild/analyse.py
18 index d94365e..1b7372c 100644
19 --- a/pym/gentoolkit/revdep_rebuild/analyse.py
20 +++ b/pym/gentoolkit/revdep_rebuild/analyse.py
21 @@ -21,6 +21,11 @@ def prepare_checks(files_to_check, libraries, bits, cmd_max_args):
22 dependencies = [] # list of lists of files (from file_to_check) that uses
23 # library (for dependencies[id] and libs[id] => id==id)
24
25 +
26 +# from runner import ScanRunner
27 +# sr = ScanRunner(['-M', str(bits), '-nBF', '%F %n'], files_to_check, cmd_max_args)
28 +# sr.wait()
29 +
30 for line in scan(['-M', str(bits), '-nBF', '%F %n'], files_to_check, cmd_max_args):
31 #call_program(['scanelf', '-M', str(bits), '-nBF', '%F %n',]+files_to_check).strip().split('\n'):
32 r = line.strip().split(' ')
33
34 diff --git a/pym/gentoolkit/revdep_rebuild/rebuild.py b/pym/gentoolkit/revdep_rebuild/rebuild.py
35 index 834170e..3d9ce82 100644
36 --- a/pym/gentoolkit/revdep_rebuild/rebuild.py
37 +++ b/pym/gentoolkit/revdep_rebuild/rebuild.py
38 @@ -170,9 +170,11 @@ def rebuild(logger, assigned, settings):
39 def main(settings=None, logger=None):
40
41 if settings is None:
42 - print("NO Input settings, using defaults...")
43 +# print("NO Input settings, using defaults...")
44 settings = DEFAULTS.copy()
45
46 + parse_options()
47 +
48 if logger is None:
49 logger = init_logger(settings)
50
51 @@ -237,3 +239,8 @@ def main(settings=None, logger=None):
52 success = rebuild(logger, assigned, settings)
53 logger.debug("rebuild return code = %i" %success)
54 return success
55 +
56 +
57 +if __name__ == '__main__':
58 + main()
59 +
60
61 diff --git a/pym/gentoolkit/revdep_rebuild/revdep-rebuild.py b/pym/gentoolkit/revdep_rebuild/revdep-rebuild.py
62 new file mode 100755
63 index 0000000..2619ee0
64 --- /dev/null
65 +++ b/pym/gentoolkit/revdep_rebuild/revdep-rebuild.py
66 @@ -0,0 +1,17 @@
67 +#!/usr/bin/python
68 +# -*- coding: utf-8 -*-
69 +
70 +
71 +# Author: Sławomir Lis <lis.slawek@×××××.com>
72 +# revdep-rebuild original author: Stanislav Brabec
73 +# revdep-rebuild original rewrite Author: Michael A. Smith
74 +# Current Maintainer: Paul Varner <fuzzyray@g.o>
75 +
76 +# Creation date: 2010/10/17
77 +# License: BSD
78 +
79 +from rebuild import APP_NAME, VERSION, main
80 +
81 +if __name__ == '__main__':
82 + # instead of revdep-rebuild.py call rebuild.py
83 + main()
84
85 diff --git a/pym/gentoolkit/revdep_rebuild/runner.py b/pym/gentoolkit/revdep_rebuild/runner.py
86 new file mode 100644
87 index 0000000..24411a5
88 --- /dev/null
89 +++ b/pym/gentoolkit/revdep_rebuild/runner.py
90 @@ -0,0 +1,114 @@
91 +# -*- coding: utf-8 -*-
92 +
93 +import threading
94 +import subprocess
95 +
96 +
97 +class ProcessRunner(threading.Thread):
98 + '''
99 + ProcessRunner is class designed to run arbitrary command
100 + in background (separate thread). It's replacement for old
101 + stuff.call_program function.
102 +
103 + When called program is finished, its output can be accessed
104 + through .stdout and .stderr fields
105 + '''
106 +
107 + def __init__(self, args, autorun=True):
108 + '''
109 + @param args - program name and its arguments
110 + @param autorun - if True, then automatically starts new thread
111 + '''
112 +
113 + threading.Thread.__init__(self)
114 + self.args = args
115 + self.lock = threading.Lock()
116 + self.stdout = ''
117 + self.stderr = ''
118 +
119 + if autorun:
120 + self.start()
121 +
122 +
123 +
124 + def run(self):
125 + self.lock.acquire()
126 +
127 + subp = subprocess.Popen(self.args, stdout=subprocess.PIPE, \
128 + stderr=subprocess.PIPE)
129 + self.stdout, self.stderr = subp.communicate()
130 + self.lock.release()
131 +
132 +
133 + def is_ready(self):
134 + ''' Checks whether current command is finished '''
135 + return not self.lock.locked()
136 +
137 +
138 + def wait(self):
139 + ''' Waits until called program finishes '''
140 + self.lock.acquire()
141 + self.lock.release()
142 +
143 +
144 +
145 +
146 +class ScanRunner(threading.Thread):
147 + '''
148 + ScanRunner is a class for calling scanelf in separate
149 + thread, so several instances could be called at a time,
150 + and then all results could be consolidated.
151 +
152 + Consolidated output is available through .out
153 + '''
154 +
155 + def __init__(self, params, files, max_args, autorun=True):
156 + '''
157 + @param params is list of parameters that should be passed into scanelf app.
158 + @param files list of files to scan.
159 + @param max_args number of files to process at once
160 + @param autorun automatically start new thread
161 +
162 + When files count is greater CMD_MAX_ARGS, then scanelf will be called
163 + several times.
164 + '''
165 +
166 + threading.Thread.__init__(self)
167 + self.params = params
168 + self.files = files
169 + self.max_args = max_args
170 +
171 + self.out = []
172 + self.lock = threading.Lock()
173 +
174 + if autorun:
175 + self.start()
176 +
177 +
178 + def run(self):
179 + self.lock.acquire()
180 +
181 + process_pool = []
182 + for i in range(0, len(self.files), self.max_args):
183 + process_pool.append(ProcessRunner(['scanelf'] + self.params + self.files[i:i+self.max_args]))
184 +
185 + while process_pool:
186 + p = process_pool.pop()
187 + p.wait()
188 + self.out += p.stdout.strip().split('\n')
189 +
190 + self.lock.release()
191 +
192 +
193 + def is_ready(self):
194 + ''' Checks whether scanning is finished '''
195 + return not self.lock.locked()
196 +
197 +
198 + def wait(self):
199 + ''' Waits until all scanning instances are finished '''
200 + self.lock.acquire()
201 + self.lock.release()
202 +
203 +
204 +
205 \ No newline at end of file