Mercurial > hg
annotate tests/list-tree.py @ 38775:e971d6eb4770
context: delete an obsolete comment
Obsolete since 91618801d5c3 (context: raise ProgrammingError on
repo['my-tag'], 2018-07-06).
Differential Revision: https://phab.mercurial-scm.org/D4002
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 30 Jul 2018 14:37:36 -0700 |
parents | acff41957b34 |
children | 2372284d9457 |
rev | line source |
---|---|
35217
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 from __future__ import ( |
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 absolute_import, |
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 print_function, |
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
4 ) |
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
5 |
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
6 import argparse |
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
7 import os |
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
8 |
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 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
|
10 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
|
11 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
|
12 |
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 def gather(): |
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 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
|
15 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
|
16 return |
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
17 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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 else: |
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 yield p |
aa905f9cdcda
tests: write and use a custom helper script to avoid find's -printf
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 |
35380
acff41957b34
tests: stabilize the sorted output of list-tree.py on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
35217
diff
changeset
|
27 print('\n'.join(sorted(gather(), key=lambda x: x.replace(os.path.sep, '/')))) |