#!/usr/bin/python """ A simple limited-scope source-code line count (a.k.a. sloc) script. See in-app About tab for license, attribution, and other logistics. """ import sys, os, sys from glob import glob # '*.py*' includes 2.X .pyc's (moot here) mains = glob('*.py') + glob('*.kv') # *.spec are gray (generated and edited) extras1 = glob('*.spec') + glob('*.xml') + glob('res/values/*.xml') extras1+= glob('pc-build/*.py') + glob('pc-build/*.spec') extras1+= glob('usbsync-pc/*.desktop') extras1+= glob('../_website/*.py') + glob('../_website/*.sh') # [1.5] moved up extras1+= glob('../_website/PC-Phone USB Sync/*.py') extras1+= glob('../_website/PC-Phone USB Sync/+screenshots/*.sh') extras1+= glob('../_website/PC-Phone USB Sync/+screenshots/_etc/*/*.sh') extras1+= glob('_dev-misc/UPLOAD-KEY/*.sh') # omit special-case dup for 'open source' publication [1.3.0] ([1.3.2]|[1.4.0]: trimmed) if os.path.exists('../_website/PC-Phone USB Sync/main.py'): extras1.remove('../_website/PC-Phone USB Sync/main.py') # embedded system (forked/tweaked); ppus-shutil.py is gray (a copy) extras2 = glob('mergeall/*.py') # in-app docs (but not _website docs) extras3 = glob('*.txt') + glob('*.html') tally = count = 0 def segment(files, accum=True): global tally, count stally, scount = 0, 0 for fname in sorted(files): if True or not fname.startswith('__sloc'): # include this script too, fobj = open(fname, 'r') # but updating its output changes it! - lcnt = len(fobj.readlines()) # run twice if add/del files stally += lcnt scount += 1 print(f'{fname} => {lcnt:,}') print(f'Segment sloc in {scount:,} file(s): {stally:,}\n') if accum: tally += stally count += scount segment(mains) segment(extras1, accum=True) segment(extras2, accum=True) segment(extras3, accum=False) print(f'Total sloc in {count:,} files: {tally:,} ' '(sans some doc txts + website htmls + showcode mods + build mods)') if sys.platform.startswith('win'): input('Press Enter') # if clicked """ ================================================================================ Example output - and current source-code counts/manifest: ''' Not counting mods to build/dists template files in ./.buildozer: see ../HOW-*.txt Added here in 1.5.0: 1k lines, 3 files: __sloc__.py, pc-build/build-source.py, website/_publish--*.sh, Added here after last 1.4.0 android app build: _website/PPUS/+screenshots/_generate.sh grew 2 lines for new galleries pc-build/build.py grew 7 lines for late Linux build changes ''' __sloc__.py => 142 main.py => 10,621 pcphoneusbsync.kv => 2,003 purgatory.py => 64 run_script_as_process.py => 61 run_script_as_service.py => 296 run_script_as_thread.py => 371 Segment sloc in 7 file(s): 13,558 ../_website/PC-Phone USB Sync/+screenshots/_etc/windows-wsl-linux/_generate.sh => 29 ../_website/PC-Phone USB Sync/+screenshots/_generate.sh => 34 ../_website/PC-Phone USB Sync/normalize-unicode-filenames.py => 117 ../_website/PC-Phone USB Sync/restore-symlinks-from-backup.py => 124 ../_website/_analytics.py => 25 ../_website/_publish--ADDS.sh => 126 ../_website/_publish--BASE.sh => 116 _dev-misc/UPLOAD-KEY/set-env-vars--PRIOR.sh => 27 _dev-misc/UPLOAD-KEY/set-env-vars.sh => 36 buildozer.spec => 1,049 fileprovider_paths.xml => 3 manifest-insert-application-attrs.xml => 3 manifest-manual-application-postattrs.xml => 59 manifest-unused-manifest-preapplication.xml => 7 pc-build/_Windows--PC-Phone USB Sync.spec => 91 pc-build/_macOS-Catalina--PC-Phone USB Sync.spec => 72 pc-build/_macOS-Sequoia--PC-Phone USB Sync.spec => 72 pc-build/_winver-maker.py => 20 pc-build/build-source.py => 182 pc-build/build.py => 972 res/values/styles.xml => 13 usbsync-pc/ppus-linux.desktop => 40 Segment sloc in 22 file(s): 3,217 mergeall/__sloc__.py => 117 mergeall/__version__.py => 7 mergeall/autoflush.py => 49 mergeall/backup.py => 1,138 mergeall/cpall.py => 729 mergeall/deltas.py => 869 mergeall/diffall.py => 471 mergeall/dirdiff.py => 134 mergeall/fix-fat-dst-modtimes.py => 136 mergeall/fix-nonportable-filenames.py => 239 mergeall/fixfrozenpaths.py => 119 mergeall/fixlongpaths.py => 486 mergeall/fixunicodedups.py => 741 mergeall/guimaker_pp4e.py => 113 mergeall/launch-mergeall-Console.py => 387 mergeall/mergeall.py => 2,052 mergeall/mergeall_configs.py => 425 mergeall/nuke-cruft-files.py => 633 mergeall/ppus_shutil.py => 1,441 mergeall/rollback.py => 161 mergeall/scandir_defunct.py => 320 mergeall/skipcruft.py => 135 Segment sloc in 22 file(s): 10,902 about-template.txt => 52 help-message.txt => 563 terms-of-use.txt => 17 Segment sloc in 3 file(s): 632 Total sloc in 51 files: 27,677 (sans some doc txts + website htmls + showcode mods + build mods) [EOF] ================================================================================ """