5"""Tool for listing Dart source files.
7If the first argument is 'relative', the script produces paths relative to the
8current working directory. If the first argument is 'absolute', the script
9produces absolute paths.
12 python3 tools/list_dart_files.py {absolute, relative} <directory> <pattern>
22 if mode
not in [
'absolute',
'relative']:
23 raise Exception(
"First argument must be 'absolute' or 'relative'")
25 if mode
in 'absolute' and not os.path.isabs(directory):
26 directory = os.path.realpath(directory)
30 pattern = re.compile(argv[3])
32 for root, directories, files
in os.walk(directory):
34 for skip_dir
in [
'.git',
'gen',
'test']:
35 if skip_dir
in directories:
36 directories.remove(skip_dir)
40 if pattern
and root == directory:
41 directories[:] = filter(pattern.match, directories)
43 for filename
in files:
45 '.dart')
and not filename.endswith(
'_test.dart'):
46 if mode
in 'absolute':
47 fullname = os.path.join(directory, root, filename)
49 fullname = os.path.relpath(os.path.join(root, filename))
50 fullname = fullname.replace(os.sep,
'/')
54if __name__ ==
'__main__':
55 sys.exit(
main(sys.argv))
def print(*args, **kwargs)