1#!/usr/bin/env python
2#
3#
4# Licensed to the Apache Software Foundation (ASF) under one
5# or more contributor license agreements.  See the NOTICE file
6# distributed with this work for additional information
7# regarding copyright ownership.  The ASF licenses this file
8# to you under the Apache License, Version 2.0 (the
9# "License"); you may not use this file except in compliance
10# with the License.  You may obtain a copy of the License at
11#
12#   http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing,
15# software distributed under the License is distributed on an
16# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17# KIND, either express or implied.  See the License for the
18# specific language governing permissions and limitations
19# under the License.
20#
21#
22
23import os, sys
24
25SKIP = ['deprecated.c',
26        'entries.c',
27        'entries.h',
28        'old-and-busted.c']
29
30TERMS = ['svn_wc_adm_access_t',
31         'svn_wc_entry_t',
32         'svn_wc__node_',
33         'svn_wc__db_temp_',
34         'svn_wc__db_node_hidden',
35         'svn_wc__loggy',
36         'svn_wc__db_wq_add',
37         ]
38
39
40def get_files_in(path):
41  names = os.listdir(path)
42  for skip in SKIP:
43    try:
44      names.remove(skip)
45    except ValueError:
46      pass
47  return [os.path.join(path, fname) for fname in names
48          if fname.endswith('.c') or fname.endswith('.h')]
49
50
51def count_terms_in(path):
52  files = get_files_in(path)
53  counts = {}
54  for term in TERMS:
55    counts[term] = 0
56  for filepath in get_files_in(path):
57    contents = open(filepath).read()
58    for term in TERMS:
59      counts[term] += contents.count(term)
60  return counts
61
62
63def print_report(wcroot):
64  client = count_terms_in(os.path.join(wcroot, 'subversion', 'libsvn_client'))
65  wc = count_terms_in(os.path.join(wcroot, 'subversion', 'libsvn_wc'))
66
67  client_total = 0
68  wc_total = 0
69
70  FMT = '%22s |%14s |%10s |%6s'
71  SEP = '%s+%s+%s+%s' % (23*'-', 15*'-', 11*'-', 7*'-')
72
73  print(FMT % ('', 'libsvn_client', 'libsvn_wc', 'Total'))
74  print(SEP)
75  for term in TERMS:
76    print(FMT % (term, client[term], wc[term], client[term] + wc[term]))
77    client_total += client[term]
78    wc_total += wc[term]
79  print(SEP)
80  print(FMT % ('Total', client_total, wc_total, client_total + wc_total))
81
82
83def usage():
84  print("""\
85Usage: %s [WCROOT]
86       %s --help
87
88Show statistics related to outstanding WC-NG code conversion work
89items in working copy branch root WCROOT.  If WCROOT is omitted, this
90program will attempt to guess it using the assumption that it is being
91run from within the working copy of interest."""
92% (sys.argv[0], sys.argv[0]))
93
94  sys.exit(0)
95
96
97if __name__ == '__main__':
98  if len(sys.argv) > 1:
99    if '--help' in sys.argv[1:]:
100      usage()
101
102    print_report(sys.argv[1])
103  else:
104    cwd = os.path.abspath(os.getcwd())
105    idx = cwd.rfind(os.sep + 'subversion')
106    if idx > 0:
107      wcroot = cwd[:idx]
108    else:
109      idx = cwd.rfind(os.sep + 'tools')
110      if idx > 0:
111        wcroot = cwd[:idx]
112      elif os.path.exists(os.path.join(cwd, 'subversion')):
113        wcroot = cwd
114      else:
115        print("ERROR: the root of 'trunk' cannot be located -- please provide")
116        sys.exit(1)
117    print_report(wcroot)
118