Improve error reporting of ValueExceptions emitted by rcsparse.
[cvs2svn.git] / contrib / profile-repos.py
blobb339e777ecf146b12b7d7ff22fb8bec6d284c5d6
1 #!/usr/bin/env python
2 # ====================================================================
3 # Copyright (c) 2000-2006 CollabNet. All rights reserved.
5 # This software is licensed as described in the file COPYING, which
6 # you should have received as part of this distribution. The terms
7 # are also available at http://subversion.tigris.org/license-1.html.
8 # If newer versions of this license are posted there, you may use a
9 # newer version instead, at your option.
11 # This software consists of voluntary contributions made by many
12 # individuals. For exact contribution history, see the revision
13 # history and logs, available at http://cvs2svn.tigris.org/.
14 # ====================================================================
17 """
18 Report information about CVS revisions, tags, and branches in a CVS
19 repository by examining the temporary files output by pass 1 of cvs2svn
20 on that repository. NOTE: You have to run the conversion pass yourself!
21 """
23 import sys, os, os.path
25 from cvs2svn_lib.common import DB_OPEN_READ
26 from cvs2svn_lib.config import CVS_PATHS_DB
27 from cvs2svn_lib.config import CVS_ITEMS_DB
28 from cvs2svn_lib.config import CVS_ITEMS_ALL_DATAFILE
29 from cvs2svn_lib.cvs_path_database import CVSPathDatabase
30 from cvs2svn_lib.cvs_item_database import CVSItemDatabase
32 def do_it():
33 cvs_path_db = CVSPathDatabase(CVS_PATHS_DB, DB_OPEN_READ)
34 cvs_items_db = CVSItemDatabase(cvs_path_db, CVS_ITEMS_DB, DB_OPEN_READ)
35 fp = open(CVS_ITEMS_ALL_DATAFILE, 'r')
37 tags = { }
38 branches = { }
40 max_tags = 0
41 max_branches = 0
42 line_count = 0
43 total_tags = 0
44 total_branches = 0
46 while 1:
47 line_count = line_count + 1
48 line = fp.readline()
49 if not line:
50 break
52 cvs_rev_key = line.strip()
53 cvs_rev = cvs_items_db[cvs_rev_key]
55 # Handle tags
56 num_tags = len(cvs_rev.tags)
57 max_tags = (num_tags > max_tags) \
58 and num_tags or max_tags
59 total_tags = total_tags + num_tags
60 for tag in cvs_rev.tags:
61 tags[tag] = None
63 # Handle branches
64 num_branches = len(cvs_rev.branches)
65 max_branches = (num_branches > max_branches) \
66 and num_branches or max_branches
67 total_branches = total_branches + num_branches
68 for branch in cvs_rev.branches:
69 branches[branch] = None
71 symbols = {}
72 symbols.update(tags)
73 symbols.update(branches)
75 num_symbols = len(symbols.keys())
76 num_tags = len(tags.keys())
77 num_branches = len(branches.keys())
78 avg_tags = total_tags * 1.0 / line_count
79 avg_branches = total_branches * 1.0 / line_count
81 print ' Total CVS Revisions: %d\n' \
82 ' Total Unique Tags: %d\n' \
83 ' Peak Revision Tags: %d\n' \
84 ' Avg. Tags/Revision: %2.1f\n' \
85 ' Total Unique Branches: %d\n' \
86 'Peak Revision Branches: %d\n' \
87 'Avg. Branches/Revision: %2.1f\n' \
88 ' Total Unique Symbols: %d%s\n' \
89 % (line_count,
90 num_tags,
91 max_tags,
92 avg_tags,
93 num_branches,
94 max_branches,
95 avg_branches,
96 num_symbols,
97 num_symbols == num_tags + num_branches and ' ' or ' (!)',
101 if __name__ == "__main__":
102 argc = len(sys.argv)
103 if argc < 2:
104 print 'Usage: %s /path/to/cvs2svn-temporary-directory' \
105 % (os.path.basename(sys.argv[0]))
106 print __doc__
107 sys.exit(0)
108 os.chdir(sys.argv[1])
109 do_it()