util.py 830 B

1234567891011121314151617181920212223
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. IGNORED_FILE_PREFIXES = ["."]
  5. IGNORED_FILE_SUFFIXES = ["~", ".swp"]
  6. IGNORED_DIRS = [".git", ".svn", ".hg"]
  7. def filter_filenames(filenames, ignored_files=[".hgignore"]):
  8. for filename in filenames:
  9. if filename in ignored_files:
  10. continue
  11. if any([filename.startswith(suffix)
  12. for suffix in IGNORED_FILE_PREFIXES]):
  13. continue
  14. if any([filename.endswith(suffix)
  15. for suffix in IGNORED_FILE_SUFFIXES]):
  16. continue
  17. yield filename
  18. def filter_dirnames(dirnames):
  19. return [dirname for dirname in dirnames if dirname not in IGNORED_DIRS]