#!/usr/bin/python3 """ simple source-code line count script, used for dev metrics only [2.2] """ import os, glob, sys srcenc = 'utf8' # allow for Unicode source files def collect(paths): manifest = [] for path in paths: manifest += glob.glob(path.replace('/', os.sep)) return manifest # the basics sources = ('*.py', '*.pyw', '*.bat') # files here # imported tools from PP4E, many updated much for 2.2 pkg = '../../..' sources += ( pkg + '/PP4E/Gui/Tools/guimaker.py', # menus, toolbars pkg + '/PP4E/Gui/ShellGui/formrows.py', # input fields pkg + '/PP4E/Gui/Tour/scrolledlist.py', # grep list pkg + '/PP4E/Tools/find.py', # grep walk pkg + '/PP4E/launchmodes.py' # run code exec ) # app/exe build scripts and count too (but skip iconify.py and tools/) sources += ('build/build-app-exe/*/*.py',) sources += ('build/build-source/*.py',) # skip generated Mac, Windows, and Linux stdlib module list files skips = ('setup.py', 'hook-os.py') tally = count = 0 for fname in collect(sources): # used files in this tree if (not fname.startswith('__') and # skip self and extras in '.' not fname.endswith(skips)): # skip generated stdlib lists fobj = open(fname, encoding=srcenc) # else do os.path.basename() lcnt = len(fobj.readlines()) tally += lcnt count += 1 print(fname, '=>', lcnt) print('Total sloc in %d files: %s' % (count, tally)) if sys.platform.startswith('win'): input('Press Enter') # if clicked on Windows """ ================================================================================ example output (current counts/manifest): fixfrozenpaths.py => 324 multiprocessing_exe_patch.py => 180 subprocproxy.py => 369 textConfig.py => 642 textEditor.py => 5105 textEditorNoConsole.pyw => 12 pyedit.bat => 27 ../../../PP4E/Gui/Tools/guimaker.py => 667 ../../../PP4E/Gui/ShellGui/formrows.py => 60 ../../../PP4E/Gui/Tour/scrolledlist.py => 62 ../../../PP4E/Tools/find.py => 32 ../../../PP4E/launchmodes.py => 629 build/build-app-exe/linux/build.py => 160 build/build-app-exe/linux/include-full-stdlib.py => 108 build/build-app-exe/macosx/build.py => 196 build/build-app-exe/macosx/include-full-stdlib.py => 144 build/build-app-exe/macosx/setup-base.py => 66 build/build-app-exe/windows/build.py => 269 build/build-app-exe/windows/include-full-stdlib.py => 139 build/build-source/build.py => 105 Total sloc in 20 files: 9296 ================================================================================ """