make_snapshot.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. import argparse
  9. import pickle
  10. import sys
  11. """This is a command line entry point that, given an out file name, and a folder to scan
  12. generates a file which contains the current snapshot of the files and folders in that folder.
  13. It is to be used later by compare_snapshot.py
  14. If you want to use this in a scripting environment instead of a CLI, use the dump_snapshot
  15. function or use FolderSnapshot.CreateSnapshot directly.
  16. """
  17. default_ignore_patterns = ['*.pyc', '__pycache__', '*.snapshot', 'Cache', 'build_*', 'build' ]
  18. from snapshot_folder.snapshot_folder import FolderSnapshot, SnapshotComparison
  19. def dump_snapshot(folder_to_scan, filename, ignore_patterns):
  20. """Workhorse function of this module. Saves the snapshot to the given file"""
  21. snap = FolderSnapshot.CreateSnapshot(folder_to_scan, ignore_patterns=ignore_patterns)
  22. pickle.dump(snap, open(filename, 'wb'))
  23. def init_parser():
  24. """Prepares the command line parser"""
  25. parser = argparse.ArgumentParser()
  26. parser.description = "Takes a snapshot of the current files and folders into a given file for later comparison"
  27. parser.add_argument('path_to_check', default='.', help='Path To start iterating at')
  28. parser.add_argument('--out', required=True, help='Path to output to')
  29. parser.add_argument('--ignore', action='append', nargs='+', default=default_ignore_patterns)
  30. return parser
  31. def main():
  32. """ Entry point to use if you want to supply args on the command line"""
  33. parser = init_parser()
  34. args = parser.parse_args()
  35. print(f"Snapshotting: {args.path_to_check} into {args.out} with ignore {args.ignore}")
  36. return dump_snapshot(args.path_to_check, args.out, args.ignore)
  37. if __name__ == '__main__':
  38. main()