diff options
author | Greg Noel <GregNoel@tigris.org> | 2010-03-27 07:39:52 (GMT) |
---|---|---|
committer | Greg Noel <GregNoel@tigris.org> | 2010-03-27 07:39:52 (GMT) |
commit | 59ed0a109bf5add2efcef459080837b11066c6fb (patch) | |
tree | fff879b4f9676a72e16c0f7b4dd969f050038b4f /src/script | |
parent | 00a3188193ba1feef927cf18e7f5fc20ad71b848 (diff) | |
download | SCons-59ed0a109bf5add2efcef459080837b11066c6fb.zip SCons-59ed0a109bf5add2efcef459080837b11066c6fb.tar.gz SCons-59ed0a109bf5add2efcef459080837b11066c6fb.tar.bz2 |
http://scons.tigris.org/issues/show_bug.cgi?id=2329
Applied a number of idiomatic changes.
Uses of the 'sort()' method were converted into calls of 'sorted()' when
possible and the sorted() expression was inserted into a subsequent statement
whenever that made sense.
The statement 'while 1:' was changed to 'while True:'.
Names from the 'types' module (e.g., 'types.FooType') were converted to the
equivalent build-in type (e.g., 'foo').
Comparisons between types were changed to use 'isinstance()'.
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/scons-time.py | 35 | ||||
-rw-r--r-- | src/script/sconsign.py | 11 |
2 files changed, 31 insertions, 15 deletions
diff --git a/src/script/scons-time.py b/src/script/scons-time.py index c75bc13..04fa573 100644 --- a/src/script/scons-time.py +++ b/src/script/scons-time.py @@ -59,6 +59,32 @@ except NameError: import __builtin__ __builtin__.True = not 0 +try: + sorted +except NameError: + # Pre-2.4 Python has no sorted() function. + # + # The pre-2.4 Python list.sort() method does not support + # list.sort(key=) nor list.sort(reverse=) keyword arguments, so + # we must implement the functionality of those keyword arguments + # by hand instead of passing them to list.sort(). + def sorted(iterable, cmp=None, key=None, reverse=False): + if key is not None: + result = [(key(x), x) for x in iterable] + else: + result = iterable[:] + if cmp is None: + # Pre-2.3 Python does not support list.sort(None). + result.sort() + else: + result.sort(cmp) + if key is not None: + result = [t1 for t0,t1 in result] + if reverse: + result.reverse() + return result + __builtin__.sorted = sorted + def make_temp_file(**kw): try: result = tempfile.mktemp(**kw) @@ -505,9 +531,7 @@ class SConsTimer: """ files = [] for a in args: - g = glob.glob(a) - g.sort() - files.extend(g) + files.extend(sorted(glob.glob(a))) if tail: files = files[-tail:] @@ -589,10 +613,7 @@ class SConsTimer: """ gp = Gnuplotter(self.title, self.key_location) - indices = results.keys() - indices.sort() - - for i in indices: + for i in sorted(results.keys()): try: t = self.run_titles[i] except IndexError: diff --git a/src/script/sconsign.py b/src/script/sconsign.py index fb3bd5e..ac619a5 100644 --- a/src/script/sconsign.py +++ b/src/script/sconsign.py @@ -282,8 +282,7 @@ def nodeinfo_raw(name, ninfo, prefix=""): try: keys = ninfo.field_list + ['_version_id'] except AttributeError: - keys = d.keys() - keys.sort() + keys = sorted(d.keys()) l = [] for k in keys: l.append('%s: %s' % (repr(k), repr(d.get(k)))) @@ -336,9 +335,7 @@ def printentries(entries, location): print nodeinfo_string(name, entry.ninfo) printfield(name, entry.binfo) else: - names = entries.keys() - names.sort() - for name in names: + for name in sorted(entries.keys()): entry = entries[name] try: ninfo = entry.ninfo @@ -402,9 +399,7 @@ class Do_SConsignDB: else: self.printentries(dir, val) else: - keys = db.keys() - keys.sort() - for dir in keys: + for dir in sorted(db.keys()): self.printentries(dir, db[dir]) def printentries(self, dir, val): |