summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2020-04-11 23:59:42 (GMT)
committerWilliam Deegan <bill@baddogconsulting.com>2020-04-11 23:59:42 (GMT)
commit7819d4c757bba420ec4b96251c188f7665a49369 (patch)
treeab4a9ca7edf1a01a6dede1981dada9af4e3c6433 /bin
parenta9ab8cae92f95e7410cb534020ff03e15c753f9e (diff)
downloadSCons-7819d4c757bba420ec4b96251c188f7665a49369.zip
SCons-7819d4c757bba420ec4b96251c188f7665a49369.tar.gz
SCons-7819d4c757bba420ec4b96251c188f7665a49369.tar.bz2
Address github review notes and sider issues
Diffstat (limited to 'bin')
-rw-r--r--bin/SConsDoc.py3
-rw-r--r--bin/scons-time.py180
2 files changed, 97 insertions, 86 deletions
diff --git a/bin/SConsDoc.py b/bin/SConsDoc.py
index 1e88c5b..e211b3c 100644
--- a/bin/SConsDoc.py
+++ b/bin/SConsDoc.py
@@ -114,6 +114,7 @@ import os.path
import re
import sys
import copy
+import importlib
# Do we have libxml2/libxslt/lxml?
has_libxml2 = True
@@ -867,7 +868,7 @@ def importfile(path):
try:
return importlib._bootstrap._load(spec)
except ImportError:
- raise ErrorDuringImport(path, sys.exc_info())
+ raise Exception(path, sys.exc_info())
# Local Variables:
# tab-width:4
diff --git a/bin/scons-time.py b/bin/scons-time.py
index 6494349..37de2f0 100644
--- a/bin/scons-time.py
+++ b/bin/scons-time.py
@@ -40,7 +40,7 @@ import shutil
import sys
import tempfile
import time
-import subprocess
+
def HACK_for_exec(cmd, *args):
"""
@@ -49,9 +49,13 @@ def HACK_for_exec(cmd, *args):
This function is a hack that calls exec() in a function with no
internal functions.
"""
- if not args: exec(cmd)
- elif len(args) == 1: exec(cmd, args[0])
- else: exec(cmd, args[0], args[1])
+ if not args:
+ exec(cmd)
+ elif len(args) == 1:
+ exec(cmd, args[0])
+ else:
+ exec(cmd, args[0], args[1])
+
class Plotter(object):
def increment_size(self, largest):
@@ -76,6 +80,7 @@ class Plotter(object):
increment = self.increment_size(largest)
return ((largest + increment - 1) // increment) * increment
+
class Line(object):
def __init__(self, points, type, title, label, comment, fmt="%s %s"):
self.points = points
@@ -111,10 +116,11 @@ class Line(object):
print('e')
def get_x_values(self):
- return [ p[0] for p in self.points ]
+ return [p[0] for p in self.points]
def get_y_values(self):
- return [ p[1] for p in self.points ]
+ return [p[1] for p in self.points]
+
class Gnuplotter(Plotter):
@@ -201,22 +207,21 @@ class Gnuplotter(Plotter):
max_y = self.max_graph_value(self.get_max_y())
incr = (max_y - min_y) / 10.0
start = min_y + (max_y / 2.0) + (2.0 * incr)
- position = [ start - (i * incr) for i in range(5) ]
+ position = [start - (i * incr) for i in range(5)]
inx = 1
for line in self.lines:
- line.print_label(inx, line.points[0][0]-1,
- position[(inx-1) % len(position)])
+ line.print_label(inx, line.points[0][0] - 1,
+ position[(inx - 1) % len(position)])
inx += 1
- plot_strings = [ self.plot_string(l) for l in self.lines ]
+ plot_strings = [self.plot_string(l) for l in self.lines]
print('plot ' + ', \\\n '.join(plot_strings))
for line in self.lines:
line.print_points()
-
def untar(fname):
import tarfile
tar = tarfile.open(name=fname, mode='r')
@@ -224,6 +229,7 @@ def untar(fname):
tar.extract(tarinfo)
tar.close()
+
def unzip(fname):
import zipfile
zf = zipfile.ZipFile(fname, 'r')
@@ -231,11 +237,12 @@ def unzip(fname):
dir = os.path.dirname(name)
try:
os.makedirs(dir)
- except:
+ except OSError:
pass
with open(name, 'wb') as f:
f.write(zf.read(name))
+
def read_tree(dir):
for dirpath, dirnames, filenames in os.walk(dir):
for fn in filenames:
@@ -244,14 +251,15 @@ def read_tree(dir):
with open(fn, 'rb') as f:
f.read()
+
def redirect_to_file(command, log):
return '%s > %s 2>&1' % (command, log)
+
def tee_to_file(command, log):
return '%s 2>&1 | tee %s' % (command, log)
-
class SConsTimer(object):
"""
Usage: scons-time SUBCOMMAND [ARGUMENTS]
@@ -267,45 +275,45 @@ class SConsTimer(object):
"""
name = 'scons-time'
- name_spaces = ' '*len(name)
+ name_spaces = ' ' * len(name)
def makedict(**kw):
return kw
default_settings = makedict(
- chdir = None,
- config_file = None,
- initial_commands = [],
- key_location = 'bottom left',
- orig_cwd = os.getcwd(),
- outdir = None,
- prefix = '',
- python = '"%s"' % sys.executable,
- redirect = redirect_to_file,
- scons = None,
- scons_flags = '--debug=count --debug=memory --debug=time --debug=memoizer',
- scons_lib_dir = None,
- scons_wrapper = None,
- startup_targets = '--help',
- subdir = None,
- subversion_url = None,
- svn = 'svn',
- svn_co_flag = '-q',
- tar = 'tar',
- targets = '',
- targets0 = None,
- targets1 = None,
- targets2 = None,
- title = None,
- unzip = 'unzip',
- verbose = False,
- vertical_bars = [],
-
- unpack_map = {
- '.tar.gz' : (untar, '%(tar)s xzf %%s'),
- '.tgz' : (untar, '%(tar)s xzf %%s'),
- '.tar' : (untar, '%(tar)s xf %%s'),
- '.zip' : (unzip, '%(unzip)s %%s'),
+ chdir=None,
+ config_file=None,
+ initial_commands=[],
+ key_location='bottom left',
+ orig_cwd=os.getcwd(),
+ outdir=None,
+ prefix='',
+ python='"%s"' % sys.executable,
+ redirect=redirect_to_file,
+ scons=None,
+ scons_flags='--debug=count --debug=memory --debug=time --debug=memoizer',
+ scons_lib_dir=None,
+ scons_wrapper=None,
+ startup_targets='--help',
+ subdir=None,
+ subversion_url=None,
+ svn='svn',
+ svn_co_flag='-q',
+ tar='tar',
+ targets='',
+ targets0=None,
+ targets1=None,
+ targets2=None,
+ title=None,
+ unzip='unzip',
+ verbose=False,
+ vertical_bars=[],
+
+ unpack_map={
+ '.tar.gz': (untar, '%(tar)s xzf %%s'),
+ '.tgz': (untar, '%(tar)s xzf %%s'),
+ '.tar': (untar, '%(tar)s xf %%s'),
+ '.zip': (unzip, '%(unzip)s %%s'),
},
)
@@ -329,10 +337,10 @@ class SConsTimer(object):
]
stage_strings = {
- 'pre-read' : 'Memory before reading SConscript files:',
- 'post-read' : 'Memory after reading SConscript files:',
- 'pre-build' : 'Memory before building targets:',
- 'post-build' : 'Memory after building targets:',
+ 'pre-read': 'Memory before reading SConscript files:',
+ 'post-read': 'Memory after reading SConscript files:',
+ 'pre-build': 'Memory before building targets:',
+ 'post-build': 'Memory after building targets:',
}
memory_string_all = 'Memory '
@@ -340,10 +348,10 @@ class SConsTimer(object):
default_stage = stages[-1]
time_strings = {
- 'total' : 'Total build time',
- 'SConscripts' : 'Total SConscript file execution time',
- 'SCons' : 'Total SCons execution time',
- 'commands' : 'Total command execution time',
+ 'total': 'Total build time',
+ 'SConscripts': 'Total SConscript file execution time',
+ 'SCons': 'Total SCons execution time',
+ 'commands': 'Total command execution time',
}
time_string_all = 'Total .* time'
@@ -425,7 +433,7 @@ class SConsTimer(object):
Executes a list of commands, substituting values from the
specified dictionary.
"""
- commands = [ self.subst_variables(c, dict) for c in commands ]
+ commands = [self.subst_variables(c, dict) for c in commands]
for action, string, args in commands:
self.display(string, *args)
sys.stdout.flush()
@@ -444,11 +452,11 @@ class SConsTimer(object):
p = os.popen(command)
output = p.read()
p.close()
- #TODO: convert to subrocess, os.popen is obsolete. This didn't work:
- #process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
- #output = process.stdout.read()
- #process.stdout.close()
- #process.wait()
+ # TODO: convert to subrocess, os.popen is obsolete. This didn't work:
+ # process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
+ # output = process.stdout.read()
+ # process.stdout.close()
+ # process.wait()
if self.verbose:
sys.stdout.write(output)
# TODO: Figure out
@@ -563,7 +571,7 @@ class SConsTimer(object):
except IndexError:
t = '??? %s ???' % i
results[i].sort()
- gp.line(results[i], i+1, t, None, t, fmt=fmt)
+ gp.line(results[i], i + 1, t, None, t, fmt=fmt)
for bar_tuple in self.vertical_bars:
try:
@@ -592,11 +600,13 @@ class SConsTimer(object):
if lines[0] == '':
lines = lines[1:]
spaces = re.match(' *', lines[0]).group(0)
- def strip_initial_spaces(l, s=spaces):
- if l.startswith(spaces):
- l = l[len(spaces):]
- return l
- return '\n'.join([ strip_initial_spaces(l) for l in lines ]) + '\n'
+
+ def strip_initial_spaces(line, s=spaces):
+ if line.startswith(spaces):
+ line = line[len(spaces):]
+ return line
+
+ return '\n'.join([strip_initial_spaces(l) for l in lines]) + '\n'
def profile_name(self, invocation):
"""
@@ -625,7 +635,7 @@ class SConsTimer(object):
sys.stderr.write('file %s has no contents!\n' % repr(file))
return None
result = re.findall(r'%s: ([\d.]*)' % search_string, contents)[-4:]
- result = [ float(r) for r in result ]
+ result = [float(r) for r in result]
if time_string is not None:
try:
result = result[0]
@@ -646,7 +656,7 @@ class SConsTimer(object):
sys.stderr.write('%s Cannot use the "func" subcommand.\n' % self.name_spaces)
sys.exit(1)
statistics = pstats.Stats(file).stats
- matches = [ e for e in statistics.items() if e[0][2] == function ]
+ matches = [e for e in statistics.items() if e[0][2] == function]
r = matches[0]
return r[0][0], r[0][1], r[0][2], r[1][3]
@@ -667,8 +677,8 @@ class SConsTimer(object):
search_string = memory_string
with open(file) as f:
lines = f.readlines()
- lines = [ l for l in lines if l.startswith(search_string) ][-4:]
- result = [ int(l.split()[-1]) for l in lines[-4:] ]
+ lines = [l for l in lines if l.startswith(search_string)][-4:]
+ result = [int(l.split()[-1]) for l in lines[-4:]]
if len(result) == 1:
result = result[0]
return result
@@ -680,13 +690,12 @@ class SConsTimer(object):
object_string = ' ' + object_name + '\n'
with open(file) as f:
lines = f.readlines()
- line = [ l for l in lines if l.endswith(object_string) ][0]
- result = [ int(field) for field in line.split()[:4] ]
+ line = [l for l in lines if l.endswith(object_string)][0]
+ result = [int(field) for field in line.split()[:4]]
if index is not None:
result = result[index]
return result
-
command_alias = {}
def execute_subcommand(self, argv):
@@ -841,7 +850,7 @@ class SConsTimer(object):
for file in args:
try:
f, line, func, time = \
- self.get_function_profile(file, function_name)
+ self.get_function_profile(file, function_name)
except ValueError as e:
sys.stderr.write("%s: func: %s: %s\n" %
(self.name, file, e))
@@ -956,7 +965,7 @@ class SConsTimer(object):
args = self.args_to_files(args, tail)
- cwd_ = os.getcwd() + os.sep
+ # cwd_ = os.getcwd() + os.sep
if format == 'ascii':
@@ -1216,11 +1225,11 @@ class SConsTimer(object):
except ValueError:
result.append(int(n))
else:
- result.extend(list(range(int(x), int(y)+1)))
+ result.extend(list(range(int(x), int(y) + 1)))
return result
def scons_path(self, dir):
- return os.path.join(dir,'scripts', 'scons.py')
+ return os.path.join(dir, 'scripts', 'scons.py')
def scons_lib_dir_path(self, dir):
return os.path.join(dir, 'src', 'engine')
@@ -1247,9 +1256,9 @@ class SConsTimer(object):
if prepare:
prepare(commands, removals)
- save_scons = self.scons
- save_scons_wrapper = self.scons_wrapper
- save_scons_lib_dir = self.scons_lib_dir
+ save_scons = self.scons
+ save_scons_wrapper = self.scons_wrapper
+ save_scons_lib_dir = self.scons_lib_dir
if self.outdir is None:
self.outdir = self.orig_cwd
@@ -1308,7 +1317,7 @@ class SConsTimer(object):
commands.extend([
(lambda: read_tree('.'),
- 'find * -type f | xargs cat > /dev/null'),
+ 'find * -type f | xargs cat > /dev/null'),
(self.set_env, 'export %%s=%%s',
'SCONS_LIB_DIR', self.scons_lib_dir),
@@ -1338,9 +1347,9 @@ class SConsTimer(object):
self.run_command_list(commands, self.__dict__)
- self.scons = save_scons
- self.scons_lib_dir = save_scons_lib_dir
- self.scons_wrapper = save_scons_wrapper
+ self.scons = save_scons
+ self.scons_lib_dir = save_scons_lib_dir
+ self.scons_wrapper = save_scons_wrapper
#
@@ -1454,6 +1463,7 @@ class SConsTimer(object):
sys.stderr.write('%s: time: Unknown format "%s".\n' % (self.name, format))
sys.exit(1)
+
if __name__ == '__main__':
opts, args = getopt.getopt(sys.argv[1:], 'h?V', ['help', 'version'])