Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
list_dart_files.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5"""Tool for listing Dart source files.
6
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.
10
11Usage:
12 python3 tools/list_dart_files.py {absolute, relative} <directory> <pattern>
13"""
14
15import os
16import re
17import sys
18
19
20def main(argv):
21 mode = argv[1]
22 if mode not in ['absolute', 'relative']:
23 raise Exception("First argument must be 'absolute' or 'relative'")
24 directory = argv[2]
25 if mode in 'absolute' and not os.path.isabs(directory):
26 directory = os.path.realpath(directory)
27
28 pattern = None
29 if len(argv) > 3:
30 pattern = re.compile(argv[3])
31
32 for root, directories, files in os.walk(directory):
33 # We only care about actual source files, not generated code or tests.
34 for skip_dir in ['.git', 'gen', 'test']:
35 if skip_dir in directories:
36 directories.remove(skip_dir)
37
38 # If we are looking at the root directory, filter the immediate
39 # subdirectories by the given pattern.
40 if pattern and root == directory:
41 directories[:] = filter(pattern.match, directories)
42
43 for filename in files:
44 if filename.endswith(
45 '.dart') and not filename.endswith('_test.dart'):
46 if mode in 'absolute':
47 fullname = os.path.join(directory, root, filename)
48 else:
49 fullname = os.path.relpath(os.path.join(root, filename))
50 fullname = fullname.replace(os.sep, '/')
51 print(fullname)
52
53
54if __name__ == '__main__':
55 sys.exit(main(sys.argv))
void print(void *str)
Definition bridge.cpp:126
Definition main.py:1