aboutsummaryrefslogtreecommitdiffstats
path: root/longbow/src/python/longbow-vocabulary-report.py
blob: 25004428b88801dd5f4a1f7ca00468127b368a37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! /usr/bin/env python
# Copyright (c) 2017 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#

import sys
import argparse

sys.path.append("@INSTALL_PYTHON_DIR@")
sys.path.append("@DEPENDENCY_PYTHON_DIR@")
sys.path.append("../site-packages/longbow/")
import VocabularyReport
import hfcca

def main(argv):
	desc = '''
Print the vocabulary (number of tokens) of functions and files.

The option --function displays the file name, function name,
line number of the function, the number of tokens

The default option --summary displays the file name, the average vocabulary
of all functions in the file and a score ranging from 0 to 100.

Usage:
$ longbow-vocabulary-report parc_JSON.c
parc_JSON.c  51.00 100.00
$
$ echo parc_JSON.c | longbow-vocabulary-report --function -o csv -
vocabulary,parc_JSON.c,parcJSON_Create,49,50,100.00
...
$

'''

	parser = argparse.ArgumentParser(prog='longbow-vocabulary-report', formatter_class=argparse.RawDescriptionHelpFormatter, description=desc)
	parser.add_argument('-s', '--summary', default=False, action="store_true", help="print the average vocabulary of each target file.")
	parser.add_argument('-f', '--function', default=False, action="store_true", help="print the vocabulary of each function in each target file.")
	parser.add_argument('-', '--stdin', default=False, action="store_true", required=False, help="read the list of files from standard input rather than the command line.")
	parser.add_argument('-a', '--average', default=False, action="store_true", required=False, help="display only the simple average of the average vocabulary of each target file.")
	parser.add_argument('-o', '--output', default="text", action="store", required=False, type=str, help="the output format: \"text\" or \"csv\"")
	parser.add_argument("files", help="Files to check", nargs="*")

	args = parser.parse_args()

        VocabularyReport.commandLineMain(args, hfcca)


if __name__ == "__main__":
	'''
@(#) longbow-vocabulary-report @VERSION@ @DATE@
@(#)   All Rights Reserved. Use is subject to license terms.
	'''
	main(sys.argv)