prune_outputs.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python
  2. # Copyright (c) 2022 Project CHIP Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import argparse
  16. import os
  17. import shutil
  18. def main():
  19. parser = argparse.ArgumentParser(
  20. description='Delete files based on an input file listing files to be removed')
  21. parser.add_argument('--keep', required=True, help="File containing names to keep (copy over)")
  22. parser.add_argument('--output-dir', required=True, help="Output directory to copy files into")
  23. parser.add_argument('--input-dir', required=True, help="Input directory to get the files from")
  24. args = parser.parse_args()
  25. with open(args.keep, "rt") as f:
  26. for source in f.readlines():
  27. source = source.strip()
  28. if not source:
  29. continue
  30. target = os.path.join(args.output_dir, source)
  31. os.makedirs(os.path.dirname(target), exist_ok=True)
  32. shutil.copyfile(os.path.join(args.input_dir, source), target)
  33. if __name__ == '__main__':
  34. main()