annotate scripts/dump_sln_cache.py @ 14:0aa61944e518

Add utility script to print the contents of a solution's cache.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 29 Aug 2023 12:52:12 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import os.path
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import pickle
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 import pprint
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 import logging
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 import argparse
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 from vsutil import SolutionCache
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 def main():
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 parser = argparse.ArgumentParser()
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 parser.add_argument('cache',
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 help="The path to the cache file")
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 parser.add_argument('-v', '--verbose',
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 action='store_true')
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 args = parser.parse_args()
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 loglevel = logging.INFO
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 if args.verbose:
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 loglevel = logging.DEBUG
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 logging.basicConfig(level=loglevel)
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 logger = logging.getLogger()
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 cachepath = args.cache
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 try:
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 with open(cachepath, 'rb') as fp:
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 cache = pickle.load(fp)
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 except Exception as ex:
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 logger.error("Error loading solution cache: %s" % ex)
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 return 1
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 loaded_ver = getattr(cache, '_saved_version', 0)
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 if loaded_ver != SolutionCache.VERSION:
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 logger.warn(f"Cache was saved with older format: {cachepath} "
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 f"(got {loaded_ver}, expected {SolutionCache.VERSION})")
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 else:
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 logger.info(f"Cache has correct version: {loaded_ver}")
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 logger.info(f"VSSolution: {cache.slnobj.path}")
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 logger.info(f"Projects: {len(cache.slnobj.projects)}")
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 for proj in cache.slnobj.projects:
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 logger.info(f" {proj.name}: {proj.path}")
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 logger.info(f"Sections: {len(cache.slnobj.sections)}")
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 for section in cache.slnobj.sections:
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 logger.info(f" {section.name} ({len(section.entries)} entries)")
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 if __name__ == '__main__':
0aa61944e518 Add utility script to print the contents of a solution's cache.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 main()