summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
author Atneya Nair <atneya@google.com> 2024-07-16 17:25:29 -0700
committer Atneya Nair <atneya@google.com> 2024-07-18 12:28:11 -0700
commit84ac591b53515b22e82204e6ebf27205b42eee45 (patch)
treea9c726bbe1868faf029841408493b47e16d2cdf8 /bin
parent30f3662693132d39f94b66b46bcd7aaef4aaef65 (diff)
dirmods: Add option to not recurse
Sometimes we just want to see the modules of a particular directory, not its subdirectories, so add an option to do so. Also some minor cleanup on os.path.sep and unicode. Test: manual Bug: trivial Change-Id: Ib22f515ade6c890dfe6c2bb8042c600192ae002c
Diffstat (limited to 'bin')
-rwxr-xr-xbin/dirmods11
1 files changed, 7 insertions, 4 deletions
diff --git a/bin/dirmods b/bin/dirmods
index a6d4de3be..c8976d53f 100755
--- a/bin/dirmods
+++ b/bin/dirmods
@@ -32,7 +32,10 @@ import modinfo
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('path')
+ parser.add_argument('--no-recurse', '-n', action='store_true',
+ help='Do not include modules defined in subdirs of path')
args = parser.parse_args()
+ should_recurse = not args.no_recurse
d = os.path.normpath(args.path)
# Fix absolute path to be relative to build top
@@ -43,15 +46,15 @@ def main():
if d.startswith(base):
d = d[len(base):]
- prefix = d + '/'
+ prefix = d + os.path.sep
module_info = modinfo.ReadModuleInfo()
results = set()
for m in module_info.values():
- for path in m.get(u'path', []):
- if path == d or path.startswith(prefix):
- name = m.get(u'module_name')
+ for path in m.get('path', []):
+ if path == d or (should_recurse and path.startswith(prefix)):
+ name = m.get('module_name')
if name:
results.add(name)