-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
78 changed files
with
3,192 additions
and
3,153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
|
||
|
||
def count_spaces_tabs(path): | ||
try: | ||
with open(path, encoding='utf-8') as fp: | ||
content = fp.read() | ||
except UnicodeDecodeError: | ||
print(f'Unable to decode {path}. Skipping...') | ||
return None, None | ||
spaces = content.count(' ') | ||
tabs = content.count('\t') | ||
return spaces, tabs | ||
|
||
|
||
def print_spaces_tabs(path, spaces, tabs, force=False): | ||
if not force and (spaces == 0 or tabs == 0): | ||
return | ||
total = spaces + tabs | ||
percent_spaces = round(spaces / total * 100, 1) | ||
percent_tabs = round(tabs / total * 100, 1) | ||
if tabs > spaces: | ||
print(f'{path} has {percent_tabs:.1f}% tabs/{percent_spaces:.1f}% spaces ({tabs}/{spaces})') | ||
else: | ||
print(f'{path} has {percent_spaces:.1f}% spaces/{percent_tabs:.1f}% tabs ({spaces}/{tabs})') | ||
|
||
|
||
def main(): | ||
for (cur, dirs, files) in os.walk('src'): | ||
for file in files: | ||
file = os.path.join(cur, file) | ||
spaces, tabs = count_spaces_tabs(file) | ||
if spaces is None: | ||
continue | ||
print_spaces_tabs(file, spaces, tabs) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.