File: ziptools/ziptools/__sloc__.py

#!/usr/bin/python
"""
A simple limited-scope source-code line count (a.k.a. sloc) script.
See ziptools' ./_README.html for license, author, and other logistics.
"""

# py 2.X compatibility
from __future__ import print_function
import sys
if sys.version_info[0] == 2: input = raw_input

import os, glob, sys
tally = count = 0

extras = glob.glob('ziptools' + os.sep + '*.py')    # now nested package here
extras += ['_publish.sh']                           # build scripts count too

for fname in sorted(glob.glob('*.py*') + extras):   # files in this dir 
    if not fname.startswith(('__sloc',)):           # skip self, keep __init__
        fobj = open(fname)
        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


"""
================================================================================
Example output (current counts/manifest):

__init__.py => 1
__version__.py => 9
_publish.sh => 123
fix-nonportable-filenames.py => 238
selftest.py => 109
zip-create.py => 389
zip-extract.py => 297
zip-list.py => 50
ziptools/__init__.py => 3
ziptools/zipcruft.py => 105
ziptools/ziplongpaths.py => 102
ziptools/zipmodtimeutc.py => 199
ziptools/zipsymlinks.py => 402
ziptools/ziptools.py => 1482
Total sloc in 14 files: 3509

================================================================================
"""



[Home page] Books Code Blog Python Author Train Find ©M.Lutz