find_and_tar.py 479 B

12345678910111213141516171819202122
  1. import os
  2. import sys
  3. import tarfile
  4. def find_gcno(dirname, tail):
  5. for cur, _dirs, files in os.walk(dirname):
  6. for f in files:
  7. if f.endswith(tail):
  8. yield os.path.relpath(os.path.join(cur, f))
  9. def main(args):
  10. output = args[0]
  11. tail = args[1] if len(args) > 1 else ''
  12. with tarfile.open(output, 'w:') as tf:
  13. for f in find_gcno(os.getcwd(), tail):
  14. tf.add(f)
  15. if __name__ == '__main__':
  16. main(sys.argv[1:])