tests/list-tree.py
author pacien <pacien.trangirard@pacien.net>
Thu, 22 Sep 2022 16:09:53 +0200
changeset 49499 4f36738a869a
parent 48875 6000f5b25c9b
permissions -rw-r--r--
tests: fix http-bad-server expected errors for python 3.10 (issue6643) The format of the error message changed with this version of Python. This also removes obsolete Python 3 checks.
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, '/'))))