aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlawek <lis.slawek@gmail.com>2012-10-02 08:44:01 +0200
committerSlawek <lis.slawek@gmail.com>2012-10-02 08:44:01 +0200
commitbb34f3532d586186a009a08c0e40c9d5fda91fb5 (patch)
treef9798da4f70a0747653ba7d6ecdb42b0c482feb2
parentFixed --library checking when not using cache (diff)
downloadgentoolkit-bb34f3532d586186a009a08c0e40c9d5fda91fb5.tar.gz
gentoolkit-bb34f3532d586186a009a08c0e40c9d5fda91fb5.tar.bz2
gentoolkit-bb34f3532d586186a009a08c0e40c9d5fda91fb5.zip
Cleanup in revdep-rebuild file; improved multi-core analyzing (speedup on multi-core cpu to about 60% original time)
-rw-r--r--pym/gentoolkit/revdep_rebuild/analyse.py5
-rw-r--r--pym/gentoolkit/revdep_rebuild/rebuild.py9
-rwxr-xr-xpym/gentoolkit/revdep_rebuild/revdep-rebuild.py17
-rw-r--r--pym/gentoolkit/revdep_rebuild/runner.py114
4 files changed, 144 insertions, 1 deletions
diff --git a/pym/gentoolkit/revdep_rebuild/analyse.py b/pym/gentoolkit/revdep_rebuild/analyse.py
index d94365e..1b7372c 100644
--- a/pym/gentoolkit/revdep_rebuild/analyse.py
+++ b/pym/gentoolkit/revdep_rebuild/analyse.py
@@ -21,6 +21,11 @@ def prepare_checks(files_to_check, libraries, bits, cmd_max_args):
dependencies = [] # list of lists of files (from file_to_check) that uses
# library (for dependencies[id] and libs[id] => id==id)
+
+# from runner import ScanRunner
+# sr = ScanRunner(['-M', str(bits), '-nBF', '%F %n'], files_to_check, cmd_max_args)
+# sr.wait()
+
for line in scan(['-M', str(bits), '-nBF', '%F %n'], files_to_check, cmd_max_args):
#call_program(['scanelf', '-M', str(bits), '-nBF', '%F %n',]+files_to_check).strip().split('\n'):
r = line.strip().split(' ')
diff --git a/pym/gentoolkit/revdep_rebuild/rebuild.py b/pym/gentoolkit/revdep_rebuild/rebuild.py
index 834170e..3d9ce82 100644
--- a/pym/gentoolkit/revdep_rebuild/rebuild.py
+++ b/pym/gentoolkit/revdep_rebuild/rebuild.py
@@ -170,9 +170,11 @@ def rebuild(logger, assigned, settings):
def main(settings=None, logger=None):
if settings is None:
- print("NO Input settings, using defaults...")
+# print("NO Input settings, using defaults...")
settings = DEFAULTS.copy()
+ parse_options()
+
if logger is None:
logger = init_logger(settings)
@@ -237,3 +239,8 @@ def main(settings=None, logger=None):
success = rebuild(logger, assigned, settings)
logger.debug("rebuild return code = %i" %success)
return success
+
+
+if __name__ == '__main__':
+ main()
+
diff --git a/pym/gentoolkit/revdep_rebuild/revdep-rebuild.py b/pym/gentoolkit/revdep_rebuild/revdep-rebuild.py
new file mode 100755
index 0000000..2619ee0
--- /dev/null
+++ b/pym/gentoolkit/revdep_rebuild/revdep-rebuild.py
@@ -0,0 +1,17 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+
+# Author: Sławomir Lis <lis.slawek@gmail.com>
+# revdep-rebuild original author: Stanislav Brabec
+# revdep-rebuild original rewrite Author: Michael A. Smith
+# Current Maintainer: Paul Varner <fuzzyray@gentoo.org>
+
+# Creation date: 2010/10/17
+# License: BSD
+
+from rebuild import APP_NAME, VERSION, main
+
+if __name__ == '__main__':
+ # instead of revdep-rebuild.py call rebuild.py
+ main()
diff --git a/pym/gentoolkit/revdep_rebuild/runner.py b/pym/gentoolkit/revdep_rebuild/runner.py
new file mode 100644
index 0000000..24411a5
--- /dev/null
+++ b/pym/gentoolkit/revdep_rebuild/runner.py
@@ -0,0 +1,114 @@
+# -*- coding: utf-8 -*-
+
+import threading
+import subprocess
+
+
+class ProcessRunner(threading.Thread):
+ '''
+ ProcessRunner is class designed to run arbitrary command
+ in background (separate thread). It's replacement for old
+ stuff.call_program function.
+
+ When called program is finished, its output can be accessed
+ through .stdout and .stderr fields
+ '''
+
+ def __init__(self, args, autorun=True):
+ '''
+ @param args - program name and its arguments
+ @param autorun - if True, then automatically starts new thread
+ '''
+
+ threading.Thread.__init__(self)
+ self.args = args
+ self.lock = threading.Lock()
+ self.stdout = ''
+ self.stderr = ''
+
+ if autorun:
+ self.start()
+
+
+
+ def run(self):
+ self.lock.acquire()
+
+ subp = subprocess.Popen(self.args, stdout=subprocess.PIPE, \
+ stderr=subprocess.PIPE)
+ self.stdout, self.stderr = subp.communicate()
+ self.lock.release()
+
+
+ def is_ready(self):
+ ''' Checks whether current command is finished '''
+ return not self.lock.locked()
+
+
+ def wait(self):
+ ''' Waits until called program finishes '''
+ self.lock.acquire()
+ self.lock.release()
+
+
+
+
+class ScanRunner(threading.Thread):
+ '''
+ ScanRunner is a class for calling scanelf in separate
+ thread, so several instances could be called at a time,
+ and then all results could be consolidated.
+
+ Consolidated output is available through .out
+ '''
+
+ def __init__(self, params, files, max_args, autorun=True):
+ '''
+ @param params is list of parameters that should be passed into scanelf app.
+ @param files list of files to scan.
+ @param max_args number of files to process at once
+ @param autorun automatically start new thread
+
+ When files count is greater CMD_MAX_ARGS, then scanelf will be called
+ several times.
+ '''
+
+ threading.Thread.__init__(self)
+ self.params = params
+ self.files = files
+ self.max_args = max_args
+
+ self.out = []
+ self.lock = threading.Lock()
+
+ if autorun:
+ self.start()
+
+
+ def run(self):
+ self.lock.acquire()
+
+ process_pool = []
+ for i in range(0, len(self.files), self.max_args):
+ process_pool.append(ProcessRunner(['scanelf'] + self.params + self.files[i:i+self.max_args]))
+
+ while process_pool:
+ p = process_pool.pop()
+ p.wait()
+ self.out += p.stdout.strip().split('\n')
+
+ self.lock.release()
+
+
+ def is_ready(self):
+ ''' Checks whether scanning is finished '''
+ return not self.lock.locked()
+
+
+ def wait(self):
+ ''' Waits until all scanning instances are finished '''
+ self.lock.acquire()
+ self.lock.release()
+
+
+ \ No newline at end of file