1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
#=====================================================
# Copyright (C) 2011-2012 Andrea Arteaga <andyspiros@gmail.com>
#=====================================================
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
import sys, os, time, subprocess as sp
from os.path import join as pjoin
# Arguments
arguments = None
inputfile = None
clean = None
imageformat = None
# Directories
curdir = None
scriptdir = None
btldir = None
libdir = None
# Storage directories
basedir = None
testsdir = None
rootsdir = None
pkgsdir = None
reportdir = None
logdir = None
copyreport = None
# Module
module = None
modulename = None
moduleargs = None
reportTitle = None
# Other
isroot = not os.getuid()
tests = None
def parseArguments():
global arguments, inputfile, clean, imageformat, basedir, copyreport
arguments = []
clean = False
imageformat = 'svg'
# Directories have not yet been set up
curdir = os.path.abspath('.')
skipargs = 0
for i, a in enumerate(sys.argv[1:], 1):
if skipargs > 0:
skipargs -= 1
continue
if a[0] != '-':
inputfile = os.path.realpath(a)
continue
if a in ('-d', '--directory'):
basedir = pjoin(curdir, sys.argv[i + 1])
skipargs += 1
continue
if a in ('-c', '--clean'):
clean = True
continue
if a in ('-i', '--imageformat'):
imageformat = sys.argv[i + 1]
skipargs += 1
continue
if a in ('-r', '--copy-report'):
copyreport = sys.argv[i + 1]
skipargs += 1
continue
arguments.append(a)
def setDirs():
global curdir, scriptdir, btldir, libdir, basedir
global testsdir, rootsdir, pkgsdir, reportdir, logdir
# Script directories
curdir = os.path.abspath('.')
scriptdir = os.path.dirname(os.path.realpath(__file__))
if os.environ.has_key('BTLDIR'):
btldir = os.environ['BTLDIR']
else:
btldir = '/usr/include/numbench/btl'
# Library directory (lib vs. lib32 vs. lib64)
libdir = sp.Popen \
('ABI=$(portageq envvar ABI); echo `portageq envvar LIBDIR_$ABI`', \
stdout=sp.PIPE, shell=True).communicate()[0].strip()
if not libdir:
libdir = 'usr/lib'
else:
libdir = 'usr/' + libdir
# Storage directories
if basedir is None:
if modulename is None:
raise RuntimeError("Module is not defined")
basedirb = pjoin(os.environ['HOME'], '.numbench') \
+ '/numbench_' + modulename + '_' + time.strftime('%Y-%m-%d')
# Find suitable base directory
if os.path.exists(basedirb):
n = 1
while True:
basedir = basedirb + "_%i" % n
if not os.path.exists(basedir):
break
n += 1
else:
basedir = basedirb
del basedirb
testsdir, rootsdir, pkgsdir, reportdir, logdir = tuple([pjoin(basedir, i) \
for i in ('tests', 'roots', 'packages', 'report', 'log')])
|