treex-cli 0.1.2__tar.gz → 0.1.3__tar.gz
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.
- {treex_cli-0.1.2/treex_cli.egg-info → treex_cli-0.1.3}/PKG-INFO +1 -1
- {treex_cli-0.1.2 → treex_cli-0.1.3}/pyproject.toml +1 -1
- {treex_cli-0.1.2 → treex_cli-0.1.3}/treex.py +12 -12
- {treex_cli-0.1.2 → treex_cli-0.1.3/treex_cli.egg-info}/PKG-INFO +1 -1
- {treex_cli-0.1.2 → treex_cli-0.1.3}/LICENSE +0 -0
- {treex_cli-0.1.2 → treex_cli-0.1.3}/README.md +0 -0
- {treex_cli-0.1.2 → treex_cli-0.1.3}/setup.cfg +0 -0
- {treex_cli-0.1.2 → treex_cli-0.1.3}/treex_cli.egg-info/SOURCES.txt +0 -0
- {treex_cli-0.1.2 → treex_cli-0.1.3}/treex_cli.egg-info/dependency_links.txt +0 -0
- {treex_cli-0.1.2 → treex_cli-0.1.3}/treex_cli.egg-info/entry_points.txt +0 -0
- {treex_cli-0.1.2 → treex_cli-0.1.3}/treex_cli.egg-info/top_level.txt +0 -0
|
@@ -60,7 +60,7 @@ class GitIgnore:
|
|
|
60
60
|
return result.returncode == 0
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
def
|
|
63
|
+
def _format_size(size): # noqa: RET503
|
|
64
64
|
"""Format bytes as a human-readable size."""
|
|
65
65
|
units = ["B", "KB", "MB", "GB", "TB"]
|
|
66
66
|
for unit in units:
|
|
@@ -71,12 +71,12 @@ def format_size(size): # noqa: RET503
|
|
|
71
71
|
size /= 1024
|
|
72
72
|
|
|
73
73
|
|
|
74
|
-
def
|
|
74
|
+
def _format_modified(timestamp):
|
|
75
75
|
"""Format a modification timestamp."""
|
|
76
76
|
return datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M")
|
|
77
77
|
|
|
78
78
|
|
|
79
|
-
def
|
|
79
|
+
def _is_binary_file(path, chunk_size=8192):
|
|
80
80
|
"""Check if the file appears to be binary."""
|
|
81
81
|
try:
|
|
82
82
|
with path.open("rb") as f:
|
|
@@ -97,7 +97,7 @@ def is_binary_file(path, chunk_size=8192):
|
|
|
97
97
|
return True
|
|
98
98
|
|
|
99
99
|
|
|
100
|
-
def
|
|
100
|
+
def _count_lines(path):
|
|
101
101
|
"""Count lines without loading the entire file into memory."""
|
|
102
102
|
try:
|
|
103
103
|
with path.open("rb") as f:
|
|
@@ -106,18 +106,18 @@ def count_lines(path):
|
|
|
106
106
|
return None
|
|
107
107
|
|
|
108
108
|
|
|
109
|
-
def
|
|
110
|
-
"""Get file
|
|
109
|
+
def _file_metadata(path):
|
|
110
|
+
"""Get file metadata."""
|
|
111
111
|
try:
|
|
112
112
|
stat = path.stat()
|
|
113
113
|
size = stat.st_size
|
|
114
|
-
modified =
|
|
114
|
+
modified = _format_modified(stat.st_mtime)
|
|
115
115
|
except OSError:
|
|
116
116
|
return "?", "[unreadable]", 0, None
|
|
117
|
-
size_text =
|
|
118
|
-
if
|
|
117
|
+
size_text = _format_size(size)
|
|
118
|
+
if _is_binary_file(path):
|
|
119
119
|
return size_text, "[binary]", size, modified
|
|
120
|
-
lines =
|
|
120
|
+
lines = _count_lines(path)
|
|
121
121
|
if lines is None:
|
|
122
122
|
return size_text, "[unreadable]", size, modified
|
|
123
123
|
return size_text, f"{lines:,} lines", size, modified
|
|
@@ -173,7 +173,7 @@ def _collect_tree(
|
|
|
173
173
|
)
|
|
174
174
|
elif entry.is_file():
|
|
175
175
|
stats["files"] += 1
|
|
176
|
-
size_text, info, size, modified =
|
|
176
|
+
size_text, info, size, modified = _file_metadata(entry)
|
|
177
177
|
stats["total_size"] += size
|
|
178
178
|
timestamp = modified if show_modified else None
|
|
179
179
|
rows.append((tree_name, (size_text, info, timestamp)))
|
|
@@ -266,7 +266,7 @@ def main():
|
|
|
266
266
|
print(
|
|
267
267
|
f"{stats['directories']} directories • "
|
|
268
268
|
f"{stats['files']} files • "
|
|
269
|
-
f"{
|
|
269
|
+
f"{_format_size(stats['total_size'])}"
|
|
270
270
|
)
|
|
271
271
|
return 0
|
|
272
272
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|