Source code for tools.report

import os, argparse

[docs]ignoreFolder = [ '__pycache__', '__qsscache__', 'img', ]
[docs]ignoreFile = [ '__init__', ]
[docs]acceptFile = [ '.py', '.qss', '.h', '.cpp', ]
[docs]scanTarget = [ 'editor', 'engine', 'data/themes', ]
[docs]lineCounter = { 'pyLines' : 0, 'qssLines' : 0, 'nativeLines' : 0, }
[docs]def countFileLines(path): with open(path, encoding = 'utf-8') as f: return len(f.readlines())
[docs]def getFileExt( file ): return os.path.splitext(file)[-1]
[docs]def processDir( path ): for name in os.listdir( path ): child = f'{path}/{name}' if os.path.isdir( child ): if name in ignoreFolder: continue processDir( child ) else: if name in ignoreFile: continue ext = getFileExt( name ) if ext not in acceptFile: continue processFile( child, ext )
[docs]def processFile( path, ext ): global lineCounter if ext == '.py': lineCounter['pyLines'] += countFileLines( path ) elif ext == '.qss': lineCounter['qssLines'] += countFileLines( path ) elif ext == '.h' or ext == '.cpp': lineCounter['nativeLines'] += countFileLines( path )
[docs]def description(): return 'report statistics of code lines'
[docs]def main( argv ): parser = argparse.ArgumentParser(prog = 'dear report', description = description()) args = parser.parse_args(argv) basepath = os.environ[ 'DEAR_BASE_PATH' ] + '/' for target in scanTarget: processDir( basepath + target ) print( 'report results:' ) print( ' - editor script lines: {:>8}'.format( lineCounter['pyLines'] ) ) print( ' - editor themes lines: {:>8}'.format( lineCounter['qssLines'] ) ) print( ' - native code lines: {:>8}'.format( lineCounter['nativeLines'] ) ) total = lineCounter['pyLines'] + lineCounter['qssLines'] + lineCounter['nativeLines'] print( 'total lines: {0}, keep going...'.format( total ) )