tests/list-tree.py
author Manuel Jacob <me@manueljacob.de>
Thu, 15 Sep 2022 01:48:38 +0200
changeset 49494 c96ed4029fda
parent 48875 6000f5b25c9b
permissions -rw-r--r--
templates: add filter to reverse list The filter supports only lists because for lists, it’s straightforward to implement. Reversing text doesn’t seem very useful and is hard to implement. Reversing the bytes would break multi-bytes encodings. Reversing the code points would break characters consisting of multiple code points. Reversing graphemes is non-trivial without using a library not included in the standard library.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35217
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
import argparse
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
import os
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
ap = argparse.ArgumentParser()
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
ap.add_argument('path', nargs='+')
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
opts = ap.parse_args()
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 35380
diff changeset
     8
35217
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
def gather():
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
    for p in opts.path:
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
        if not os.path.exists(p):
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
            return
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
        if os.path.isdir(p):
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
            yield p + os.path.sep
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
            for dirpath, dirs, files in os.walk(p):
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
                for d in dirs:
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
    17
                    yield os.path.join(dirpath, d) + os.path.sep
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
                for f in files:
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
                    yield os.path.join(dirpath, f)
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
        else:
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
            yield p
aa905f9cdcda tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 35380
diff changeset
    23
35380
acff41957b34 tests: stabilize the sorted output of list-tree.py on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 35217
diff changeset
    24
print('\n'.join(sorted(gather(), key=lambda x: x.replace(os.path.sep, '/'))))