summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspiros <andyspiros@gmail.com>2011-08-09 01:59:39 +0200
committerspiros <andyspiros@gmail.com>2011-08-09 01:59:39 +0200
commitc6b10b2698803d97f41cc2d95c384fcae690361f (patch)
treea4098c0aa13b8f04c7ed0d209ca959c5d694cb58
parentMerge branch 'unstable' of git+ssh://git.overlays.gentoo.org/proj/auto-numeri... (diff)
downloadauto-numerical-bench-c6b10b2698803d97f41cc2d95c384fcae690361f.tar.gz
auto-numerical-bench-c6b10b2698803d97f41cc2d95c384fcae690361f.tar.bz2
auto-numerical-bench-c6b10b2698803d97f41cc2d95c384fcae690361f.zip
Added main logging. Solved issues with utils and Portage.
-rw-r--r--PortageUtils.py62
-rw-r--r--benchconfig.py7
-rw-r--r--benchprint.py21
-rw-r--r--benchutils.py5
4 files changed, 58 insertions, 37 deletions
diff --git a/PortageUtils.py b/PortageUtils.py
index 8280d1c..f06c53d 100644
--- a/PortageUtils.py
+++ b/PortageUtils.py
@@ -8,6 +8,35 @@ class InstallException(Exception):
def __init__(self, command, logfile):
self.command = command
self.logfile = logfile
+
+def _getEnv(root='/', envAdds={}):
+ denv = os.environ.copy()
+
+ #PATH
+ denv['PATH'] = ':'.join([pjoin(root, i) for i in ('bin', 'usr/bin')])
+ if os.environ.has_key('PATH'):
+ denv['PATH'] += ':' + os.environ['PATH']
+ denv['ROOTPATH'] = denv['PATH']
+ #LIBRARY_PATH
+ denv['LIBRARY_PATH'] = ':'.join([pjoin(root, i) for i in \
+ ('usr/lib', 'usr/lib64', 'usr/lib32')])
+ if os.environ.has_key('LIBRARY_PATH'):
+ denv['LIBRARY_PATH'] += ':' + os.environ['LIBRARY_PATH']
+ #LD_LIBRARY_PATH
+ denv['LD_LIBRARY_PATH'] = ':'.join([pjoin(root, i) for i in \
+ ('usr/lib', 'usr/lib64', 'usr/lib32')])
+ if os.environ.has_key('LD_LIBRARY_PATH'):
+ denv['LD_LIBRARY_PATH'] += ':' + os.environ['LD_LIBRARY_PATH']
+ #INCLUDE_PATH
+ denv['INCLUDE_PATH'] = ':'.join([pjoin(root, i) for i in ('usr/include',)])
+ if os.environ.has_key('INCLUDE_PATH'):
+ denv['INCLUDE_PATH'] += ':' + os.environ['INCLUDE_PATH']
+
+ # Adds
+ for k,v in envAdds.items():
+ denv[k] = v
+
+ return denv
def available_packages(pattern):
"""Returns a list of packages matching the given pattern.
@@ -51,9 +80,7 @@ def install_dependencies(package, env={}, root='/',
logdir = "/var/log/benchmarks/.unordered"
# Adjust environment
- denv = os.environ
- for k,v in env.items():
- denv[k] = v
+ denv = _getEnv(root, dict(PKGDIR=pkgdir))
# Retrieve dependencies
deps = get_dependencies(package, denv, False)
@@ -83,31 +110,10 @@ def install_package(package, env={}, root='/', pkgdir='usr/portage/packages',
The function has no return value and raises an exception in case of building
or emerging failure. Note: dependencies will NOT be emerged!
"""
-
- # Adjust environment
- denv = os.environ.copy()
- for k,v in env.items():
- denv[k] = v
- denv['PKGDIR'] = pkgdir
- #PATH
- denv['PATH'] = ':'.join([pjoin(root, i) for i in ('bin', 'usr/bin')])
- if os.environ.has_key('PATH'):
- denv['PATH'] += ':' + os.environ['PATH']
- denv['ROOTPATH'] = denv['PATH']
- #LIBRARY_PATH
- denv['LIBRARY_PATH'] = ':'.join([pjoin(root, i) for i in \
- ('usr/lib', 'usr/lib64', 'usr/lib32')])
- if os.environ.has_key('LIBRARY_PATH'):
- denv['LIBRARY_PATH'] += ':' + os.environ['LIBRARY_PATH']
- #LD_LIBRARY_PATH
- denv['LD_LIBRARY_PATH'] = ':'.join([pjoin(root, i) for i in \
- ('usr/lib', 'usr/lib64', 'usr/lib32')])
- if os.environ.has_key('LD_LIBRARY_PATH'):
- denv['LD_LIBRARY_PATH'] += ':' + os.environ['LD_LIBRARY_PATH']
- #INCLUDE_PATH
- denv['INCLUDE_PATH'] = ':'.join([pjoin(root, i) for i in ('usr/include',)])
- if os.environ.has_key('INCLUDE_PATH'):
- denv['INCLUDE_PATH'] += ':' + os.environ['INCLUDE_PATH']
+ envAdds = env.copy()
+ envAdds['PKGDIR'] = pkgdir
+ denv = _getEnv(root, envAdds)
+ del envAdds
# Retrieve package string
pkg = normalize_cpv(package)
diff --git a/benchconfig.py b/benchconfig.py
index c684685..f707959 100644
--- a/benchconfig.py
+++ b/benchconfig.py
@@ -32,6 +32,7 @@ if needsinitialization:
testsdir = "/var/tmp/benchmarks/tests/"
rootsdir = "/var/tmp/benchmarks/roots/"
pkgsdir = "/var/cache/benchmarks/packages/"
+
reportdirb = "/var/cache/benchmarks/reports/"
logdirb = "/var/log/benchmarks/"+modname+"_"+time.strftime('%Y-%m-%d')
else:
@@ -42,6 +43,10 @@ if needsinitialization:
logdirb = pjoin(os.environ['HOME'], ".benchmarks/log",
modname + "_" + time.strftime('%Y-%m-%d'))
+ bu.mkdir(testsdir)
+ bu.mkdir(rootsdir)
+ bu.mkdir(pkgsdir)
+
# Report directory
reportdirb += modname + "_" + time.strftime('%Y-%m-%d')
if os.path.exists(reportdirb):
@@ -76,4 +81,4 @@ def makedirs():
-inizialized = True \ No newline at end of file
+inizialized = True
diff --git a/benchprint.py b/benchprint.py
index b91da66..e4b7e41 100644
--- a/benchprint.py
+++ b/benchprint.py
@@ -5,24 +5,37 @@ except NameError:
if needsinitialization:
+ import benchconfig as cfg, benchutils as bu
+ from os.path import dirname, join as pjoin
+
class _Print:
- def __init__(self, maxlevel=10):
+ def __init__(self, logfile, maxlevel=10):
self._level = 0
self._maxlevel = maxlevel
+ bu.mkdir(dirname(logfile))
+ self._logfile = file(logfile, 'w')
def __call__(self, arg):
if self._level > self._maxlevel:
return
+
if self._level <= 0:
print str(arg)
+ print >> self._logfile, str(arg)
+ self._logfile.flush()
return
- print (self._level-1)*" " + "-- " + str(arg)
+
+ printstr = (self._level-1)*" " + "-- " + str(arg)
+ if self._level <= self._maxlevel-1:
+ print >> self._logfile, printstr
+ self._logfile.flush()
+ print printstr
def up(self, n=1):
self._level = max(self._level-n, 0)
def down(self, n=1):
self._level = max(self._level+n, 0)
- Print = _Print(3)
+ Print = _Print(pjoin(cfg.logdir, 'main.log'), 3)
-initialized = True \ No newline at end of file
+initialized = True
diff --git a/benchutils.py b/benchutils.py
index 748f928..df12ee9 100644
--- a/benchutils.py
+++ b/benchutils.py
@@ -1,11 +1,8 @@
import os, sys
-from os.path import join as pjoin, basename, dirname
import subprocess as sp
-import benchconfig as cfg
-import benchpkgconfig as pc
def mkdir(dir):
if not os.path.exists(dir):
os.makedirs(dir)
-run_cmd = lambda c : sp.Popen(c, stdout=sp.PIPE).communicate()[0] \ No newline at end of file
+run_cmd = lambda c : sp.Popen(c, stdout=sp.PIPE).communicate()[0]