aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoman Gräf <romangraef@loves.dicksinhisan.us>2020-06-21 02:44:06 +0200
committerRoman Gräf <romangraef@loves.dicksinhisan.us>2020-06-21 02:44:06 +0200
commit090b44edd8bf42e3d9574680dfa2e27cae8e595e (patch)
treec04a9bd456984218d84e7e4c5bb41c44055fff42 /lib
parenta23529ccbd1237db2e7cbf5a8075437461fb5abe (diff)
downloadtabsvsspaces-090b44edd8bf42e3d9574680dfa2e27cae8e595e.tar.gz
tabsvsspaces-090b44edd8bf42e3d9574680dfa2e27cae8e595e.tar.bz2
tabsvsspaces-090b44edd8bf42e3d9574680dfa2e27cae8e595e.zip
pypi release
Diffstat (limited to 'lib')
-rw-r--r--lib/argparse/pathtype.py63
-rw-r--r--lib/print_stats.py17
-rw-r--r--lib/stats.py26
3 files changed, 0 insertions, 106 deletions
diff --git a/lib/argparse/pathtype.py b/lib/argparse/pathtype.py
deleted file mode 100644
index 39128cc..0000000
--- a/lib/argparse/pathtype.py
+++ /dev/null
@@ -1,63 +0,0 @@
-# As usual: copied form stack overflow
-# https://stackoverflow.com/a/33181083
-
-from argparse import ArgumentTypeError as err
-import os
-
-
-class PathType(object):
- def __init__(self, exists=True, type='file', dash_ok=True):
- """exists:
- True: a path that does exist
- False: a path that does not exist, in a valid parent directory
- None: don't care
- type: file, dir, symlink, None, or a function returning True for valid paths
- None: don't care
- dash_ok: whether to allow "-" as stdin/stdout"""
-
- assert exists in (True, False, None)
- assert type in ('file', 'dir', 'symlink', None) or hasattr(type, '__call__')
-
- self._exists = exists
- self._type = type
- self._dash_ok = dash_ok
-
- def __call__(self, string):
- if string == '-':
- # the special argument "-" means sys.std{in,out}
- if self._type == 'dir':
- raise err('standard input/output (-) not allowed as directory path')
- elif self._type == 'symlink':
- raise err('standard input/output (-) not allowed as symlink path')
- elif not self._dash_ok:
- raise err('standard input/output (-) not allowed')
- else:
- e = os.path.exists(string)
- if self._exists:
- if not e:
- raise err("path does not exist: '%s'" % string)
-
- if self._type is None:
- pass
- elif self._type == 'file':
- if not os.path.isfile(string):
- raise err("path is not a file: '%s'" % string)
- elif self._type == 'symlink':
- if not os.path.symlink(string):
- raise err("path is not a symlink: '%s'" % string)
- elif self._type == 'dir':
- if not os.path.isdir(string):
- raise err("path is not a directory: '%s'" % string)
- elif not self._type(string):
- raise err("path not valid: '%s'" % string)
- else:
- if not self._exists and e:
- raise err("path exists: '%s'" % string)
-
- p = os.path.dirname(os.path.normpath(string)) or '.'
- if not os.path.isdir(p):
- raise err("parent path is not a directory: '%s'" % p)
- elif not os.path.exists(p):
- raise err("parent directory does not exist: '%s'" % p)
-
- return string
diff --git a/lib/print_stats.py b/lib/print_stats.py
deleted file mode 100644
index 9616caa..0000000
--- a/lib/print_stats.py
+++ /dev/null
@@ -1,17 +0,0 @@
-from lib.stats import Statistics
-
-
-def print_stats(stats: Statistics, by_extension: bool):
- print('spaces:', stats.all_spaces)
- print('tabs:', stats.all_tabs)
- print('mixed:', stats.all_mixed)
- if by_extension:
- for ext in set(stats.space_dict.keys()) | stats.tab_dict.keys() | stats.mixed_line_dict.keys():
- print(ext + ':')
- print(' ', 'spaces:', stats.space_dict[ext])
- print(' ', 'tabs:', stats.tab_dict[ext])
- print(' ', 'mixed:', stats.mixed_line_dict[ext])
- if stats.all_mixed > 0:
- print('files_with_mixed_lines:')
- for file in stats.mixed_files:
- print(' -', file)
diff --git a/lib/stats.py b/lib/stats.py
deleted file mode 100644
index 42e4461..0000000
--- a/lib/stats.py
+++ /dev/null
@@ -1,26 +0,0 @@
-from collections import defaultdict
-from typing import Set
-
-
-class Statistics:
- def __init__(self):
- self.space_dict = defaultdict(int)
- self.tab_dict = defaultdict(int)
- self.mixed_line_dict = defaultdict(int)
- self.mixed_files: Set[str] = set()
- self.all_tabs = 0
- self.all_spaces = 0
- self.all_mixed = 0
-
- def add_spaces(self, extension='', count=1):
- self.space_dict[extension] += count
- self.all_spaces += count
-
- def add_tabs(self, extension='', count=1):
- self.tab_dict[extension] += count
- self.all_tabs += count
-
- def add_mixed_line(self, extension='', count=1, filename=''):
- self.mixed_line_dict[extension] += count
- self.mixed_files.add(filename)
- self.all_mixed += count