本文整理匯總了Python中LongBow.countLines方法的典型用法代碼示例。如果您正苦於以下問題:Python LongBow.countLines方法的具體用法?Python LongBow.countLines怎麽用?Python LongBow.countLines使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LongBow
的用法示例。
在下文中一共展示了LongBow.countLines方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: csvSummary
# 需要導入模塊: import LongBow [as 別名]
# 或者: from LongBow import countLines [as 別名]
def csvSummary(distribution, documentation):
formatString ="documentation,%s,%d,%d,%.2f%%"
for entry in documentation:
badLines = len(documentation[entry])
totalLines = LongBow.countLines(entry)
score = float(totalLines - badLines) / float(totalLines) * 100.0
LongBow.scorePrinter(distribution, score, formatString % (entry, totalLines, badLines, score))
return
示例2: textualSummary
# 需要導入模塊: import LongBow [as 別名]
# 或者: from LongBow import countLines [as 別名]
def textualSummary(distribution, documentation):
maxWidth = 0
for entry in documentation:
if len(entry) > maxWidth:
maxWidth = len(entry)
formatString ="%-" + str(maxWidth) + "s %8d %8d %.2f%%"
for entry in documentation:
badLines = len(documentation[entry])
totalLines = LongBow.countLines(entry)
score = float(totalLines - badLines) / float(totalLines) * 100.0
LongBow.scorePrinter(distribution, score, formatString % (entry, totalLines, badLines, score))
return
示例3: textualAverage
# 需要導入模塊: import LongBow [as 別名]
# 或者: from LongBow import countLines [as 別名]
def textualAverage(distribution, documentation, format):
sum = 0.0
for entry in documentation:
badLines = len(documentation[entry])
totalLines = LongBow.countLines(entry)
score = float(totalLines - badLines) / float(totalLines) * 100.0
sum = sum + score
if len(documentation) == 0:
averageScore = 100.0
else:
averageScore = sum / float(len(documentation))
LongBow.scorePrinter(distribution, averageScore, format % averageScore)
示例4: main
# 需要導入模塊: import LongBow [as 別名]
# 或者: from LongBow import countLines [as 別名]
def main():
desc = '''
Report on number of lines of one or more C source or header files.
Input is either from a list of files supplied as command line parameters,
or as a list of newline separated file names read from standard input.
Output is a plain text (default) or a CSV file reporting
the file name and the total number of lines in the file.
Usage:
% longbow-size-report *.[ch]
Report the number of lines in .c and .h files specified as command line parameters.
% longbow-size-report -
Read the lists of files from standard input, one file per line.
$ longbow-size-report parc_JSON.c
parc_JSON.c 239
$
$
$ echo parc_JSON.c | longbow-size-report -o csv -
parc_JSON.c,239
$
'''
parser = argparse.ArgumentParser(prog='longbow-size-report', formatter_class=argparse.RawDescriptionHelpFormatter, description=desc)
parser.add_argument('-', '--stdin', default=False, action="store_true", required=False, help="read the list of files from standard input.")
parser.add_argument('-s', '--summary', default=False, action="store_true", required=False, help="display the number of lines for each file")
parser.add_argument('-t', '--total', default=False, action="store_true", required=False, help="display the total number of lines for all files")
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()
if args.summary == False and args.total == False:
args.summary = True
targets = []
if args.stdin:
for line in sys.stdin:
t = line.strip()
if len(t) > 0:
targets.append(t)
else:
targets = args.files
if len(targets) == 0:
parser.print_usage()
sys.exit(1)
files = map(lambda fileName: [ fileName, LongBow.countLines(fileName)], targets)
total = sum(map(lambda element: element[1], files))
if args.summary:
if args.output == "text":
textSummary(files)
else:
csvSummary(files)
if args.total:
if args.output == "text":
textTotal(files)
else:
csvTotal(files)