skilleter-thingy 0.3.14__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- skilleter_thingy/__init__.py +0 -0
- skilleter_thingy/addpath.py +107 -0
- skilleter_thingy/console_colours.py +63 -0
- skilleter_thingy/ffind.py +535 -0
- skilleter_thingy/ggit.py +88 -0
- skilleter_thingy/ggrep.py +155 -0
- skilleter_thingy/git_br.py +186 -0
- skilleter_thingy/git_ca.py +147 -0
- skilleter_thingy/git_cleanup.py +297 -0
- skilleter_thingy/git_co.py +227 -0
- skilleter_thingy/git_common.py +68 -0
- skilleter_thingy/git_hold.py +162 -0
- skilleter_thingy/git_parent.py +84 -0
- skilleter_thingy/git_retag.py +67 -0
- skilleter_thingy/git_review.py +1450 -0
- skilleter_thingy/git_update.py +398 -0
- skilleter_thingy/git_wt.py +72 -0
- skilleter_thingy/gitcmp_helper.py +328 -0
- skilleter_thingy/gitprompt.py +293 -0
- skilleter_thingy/linecount.py +154 -0
- skilleter_thingy/multigit.py +915 -0
- skilleter_thingy/py_audit.py +133 -0
- skilleter_thingy/remdir.py +127 -0
- skilleter_thingy/rpylint.py +98 -0
- skilleter_thingy/strreplace.py +82 -0
- skilleter_thingy/test.py +34 -0
- skilleter_thingy/tfm.py +948 -0
- skilleter_thingy/tfparse.py +101 -0
- skilleter_thingy/trimpath.py +82 -0
- skilleter_thingy/venv_create.py +47 -0
- skilleter_thingy/venv_template.py +47 -0
- skilleter_thingy/xchmod.py +124 -0
- skilleter_thingy/yamlcheck.py +89 -0
- skilleter_thingy-0.3.14.dist-info/METADATA +606 -0
- skilleter_thingy-0.3.14.dist-info/RECORD +39 -0
- skilleter_thingy-0.3.14.dist-info/WHEEL +5 -0
- skilleter_thingy-0.3.14.dist-info/entry_points.txt +31 -0
- skilleter_thingy-0.3.14.dist-info/licenses/LICENSE +619 -0
- skilleter_thingy-0.3.14.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#! /usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
################################################################################
|
|
4
|
+
""" Count lines of code by filetype
|
|
5
|
+
"""
|
|
6
|
+
################################################################################
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
import argparse
|
|
11
|
+
|
|
12
|
+
import filetype
|
|
13
|
+
from skilleter_modules import files
|
|
14
|
+
|
|
15
|
+
################################################################################
|
|
16
|
+
|
|
17
|
+
def guess_filetype(filepath):
|
|
18
|
+
""" Guess the type of a file """
|
|
19
|
+
|
|
20
|
+
binary = False
|
|
21
|
+
|
|
22
|
+
# Check for the filetype (usually detects binary files)
|
|
23
|
+
|
|
24
|
+
ftype = filetype.guess(filepath)
|
|
25
|
+
|
|
26
|
+
# If we have a type, store the extension and, as it is binary
|
|
27
|
+
# set the number of lines to 0
|
|
28
|
+
# Otherwise, work out the filetype and count the lines
|
|
29
|
+
|
|
30
|
+
if ftype:
|
|
31
|
+
ext = ftype.extension
|
|
32
|
+
binary = True
|
|
33
|
+
else:
|
|
34
|
+
filename = os.path.split(filepath)[1]
|
|
35
|
+
|
|
36
|
+
if '.' in filename:
|
|
37
|
+
ext = filename.split('.')[-1]
|
|
38
|
+
else:
|
|
39
|
+
if filename.startswith('Jenkins'):
|
|
40
|
+
ext = 'Jenkins'
|
|
41
|
+
elif filename.startswith('Docker'):
|
|
42
|
+
ext = 'Docker'
|
|
43
|
+
else:
|
|
44
|
+
ext = filename
|
|
45
|
+
|
|
46
|
+
return ext, binary
|
|
47
|
+
|
|
48
|
+
################################################################################
|
|
49
|
+
|
|
50
|
+
def determine_filetype(filepath):
|
|
51
|
+
""" Determine the type of a file """
|
|
52
|
+
|
|
53
|
+
file_type = files.file_type(filepath)
|
|
54
|
+
|
|
55
|
+
if file_type.startswith('a /usr/bin/env '):
|
|
56
|
+
file_type = file_type[len('a /usr/bin/env '):]
|
|
57
|
+
elif file_type.startswith('symbolic link to '):
|
|
58
|
+
file_type = 'Symbolic link'
|
|
59
|
+
|
|
60
|
+
if file_type[0].islower():
|
|
61
|
+
file_type = file_type.capitalize()
|
|
62
|
+
|
|
63
|
+
ext = file_type.split(',')[0]
|
|
64
|
+
binary = 'text' not in file_type
|
|
65
|
+
|
|
66
|
+
if file_type.startswith('ASCII text'):
|
|
67
|
+
return guess_filetype(filepath)
|
|
68
|
+
|
|
69
|
+
return ext, binary
|
|
70
|
+
|
|
71
|
+
################################################################################
|
|
72
|
+
|
|
73
|
+
def main():
|
|
74
|
+
""" Report Summary of files by name or extension """
|
|
75
|
+
|
|
76
|
+
parser = argparse.ArgumentParser(description='Summarise number of files, lines of text and total size of files in a directory tree')
|
|
77
|
+
parser.add_argument('--ext', '-e', action='store_true', help='Identify file type using the file extension (faster but less accurrate)')
|
|
78
|
+
|
|
79
|
+
args = parser.parse_args()
|
|
80
|
+
|
|
81
|
+
filetypes = {}
|
|
82
|
+
|
|
83
|
+
# Wander down the tree
|
|
84
|
+
|
|
85
|
+
for dirpath, dirnames, filenames in os.walk('.'):
|
|
86
|
+
# Skip .git directories
|
|
87
|
+
|
|
88
|
+
if '.git' in dirnames:
|
|
89
|
+
dirnames.remove('.git')
|
|
90
|
+
|
|
91
|
+
for filename in filenames:
|
|
92
|
+
# Get the file path and size
|
|
93
|
+
|
|
94
|
+
filepath = os.path.join(dirpath, filename)
|
|
95
|
+
size = os.stat(filepath).st_size
|
|
96
|
+
|
|
97
|
+
if args.ext:
|
|
98
|
+
ext, binary = guess_filetype(filepath)
|
|
99
|
+
else:
|
|
100
|
+
ext, binary = determine_filetype(filepath)
|
|
101
|
+
|
|
102
|
+
if binary:
|
|
103
|
+
lines = 0
|
|
104
|
+
else:
|
|
105
|
+
with open(filepath, 'rb') as infile:
|
|
106
|
+
lines = len(infile.readlines())
|
|
107
|
+
|
|
108
|
+
# Update the summary
|
|
109
|
+
|
|
110
|
+
if ext in filetypes:
|
|
111
|
+
filetypes[ext]['files'] += 1
|
|
112
|
+
filetypes[ext]['size'] += size
|
|
113
|
+
filetypes[ext]['lines'] += lines
|
|
114
|
+
else:
|
|
115
|
+
filetypes[ext] = {'files': 1, 'size': size, 'lines': lines}
|
|
116
|
+
|
|
117
|
+
# Work out the maximum size of each field of data
|
|
118
|
+
|
|
119
|
+
total_files = 0
|
|
120
|
+
total_lines = 0
|
|
121
|
+
total_size = 0
|
|
122
|
+
|
|
123
|
+
for ext in sorted(filetypes.keys()):
|
|
124
|
+
total_files += filetypes[ext]['files']
|
|
125
|
+
total_lines += filetypes[ext]['lines']
|
|
126
|
+
total_size += filetypes[ext]['size']
|
|
127
|
+
|
|
128
|
+
size = files.format_size(filetypes[ext]['size'])
|
|
129
|
+
print(f"{ext}: {filetypes[ext]['files']:,} files, {filetypes[ext]['lines']:,} lines, {size}")
|
|
130
|
+
|
|
131
|
+
size = files.format_size(total_size)
|
|
132
|
+
|
|
133
|
+
print()
|
|
134
|
+
print(f'Total files: {total_files:,}')
|
|
135
|
+
print(f'Total lines: {total_lines:,}')
|
|
136
|
+
print(f'Total size: {size}')
|
|
137
|
+
|
|
138
|
+
################################################################################
|
|
139
|
+
|
|
140
|
+
def linecount():
|
|
141
|
+
"""Entry point"""
|
|
142
|
+
|
|
143
|
+
try:
|
|
144
|
+
main()
|
|
145
|
+
|
|
146
|
+
except KeyboardInterrupt:
|
|
147
|
+
sys.exit(1)
|
|
148
|
+
except BrokenPipeError:
|
|
149
|
+
sys.exit(2)
|
|
150
|
+
|
|
151
|
+
################################################################################
|
|
152
|
+
|
|
153
|
+
if __name__ == '__main__':
|
|
154
|
+
linecount()
|