treex-cli 0.1.2__tar.gz → 0.1.4__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.4}/PKG-INFO +5 -5
- {treex_cli-0.1.2 → treex_cli-0.1.4}/README.md +4 -4
- {treex_cli-0.1.2 → treex_cli-0.1.4}/pyproject.toml +1 -1
- {treex_cli-0.1.2 → treex_cli-0.1.4}/treex.py +20 -16
- {treex_cli-0.1.2 → treex_cli-0.1.4/treex_cli.egg-info}/PKG-INFO +5 -5
- {treex_cli-0.1.2 → treex_cli-0.1.4}/LICENSE +0 -0
- {treex_cli-0.1.2 → treex_cli-0.1.4}/setup.cfg +0 -0
- {treex_cli-0.1.2 → treex_cli-0.1.4}/treex_cli.egg-info/SOURCES.txt +0 -0
- {treex_cli-0.1.2 → treex_cli-0.1.4}/treex_cli.egg-info/dependency_links.txt +0 -0
- {treex_cli-0.1.2 → treex_cli-0.1.4}/treex_cli.egg-info/entry_points.txt +0 -0
- {treex_cli-0.1.2 → treex_cli-0.1.4}/treex_cli.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: treex-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: List directory contents as a tree with file metadata
|
|
5
5
|
Author: Corey Goldberg
|
|
6
6
|
Maintainer: Corey Goldberg
|
|
@@ -39,10 +39,10 @@ Dynamic: license-file
|
|
|
39
39
|
`treex` is a command-line utility that recursively scans a directory and
|
|
40
40
|
displays its contents as a tree along with file metadata.
|
|
41
41
|
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
-
|
|
42
|
+
- Displays human-readable file sizes
|
|
43
|
+
- Shows line counts for text files
|
|
44
|
+
- Identifies binary and unreadable files by type
|
|
45
|
+
- Optionally displays modification timestamps
|
|
46
46
|
- Respects `.gitignore` rules when Git is installed
|
|
47
47
|
|
|
48
48
|
----
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
`treex` is a command-line utility that recursively scans a directory and
|
|
15
15
|
displays its contents as a tree along with file metadata.
|
|
16
16
|
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
17
|
+
- Displays human-readable file sizes
|
|
18
|
+
- Shows line counts for text files
|
|
19
|
+
- Identifies binary and unreadable files by type
|
|
20
|
+
- Optionally displays modification timestamps
|
|
21
21
|
- Respects `.gitignore` rules when Git is installed
|
|
22
22
|
|
|
23
23
|
----
|
|
@@ -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,12 +173,20 @@ 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)))
|
|
180
180
|
|
|
181
181
|
|
|
182
|
+
def print_summary(stats):
|
|
183
|
+
print(
|
|
184
|
+
f"{stats['directories']:,} directories • "
|
|
185
|
+
f"{stats['files']:,} files • "
|
|
186
|
+
f"{_format_size(stats['total_size'])}"
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
|
|
182
190
|
def print_tree(
|
|
183
191
|
directory,
|
|
184
192
|
prefix="",
|
|
@@ -263,11 +271,7 @@ def main():
|
|
|
263
271
|
)
|
|
264
272
|
if show_tree:
|
|
265
273
|
print()
|
|
266
|
-
|
|
267
|
-
f"{stats['directories']} directories • "
|
|
268
|
-
f"{stats['files']} files • "
|
|
269
|
-
f"{format_size(stats['total_size'])}"
|
|
270
|
-
)
|
|
274
|
+
print_summary(stats)
|
|
271
275
|
return 0
|
|
272
276
|
|
|
273
277
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: treex-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: List directory contents as a tree with file metadata
|
|
5
5
|
Author: Corey Goldberg
|
|
6
6
|
Maintainer: Corey Goldberg
|
|
@@ -39,10 +39,10 @@ Dynamic: license-file
|
|
|
39
39
|
`treex` is a command-line utility that recursively scans a directory and
|
|
40
40
|
displays its contents as a tree along with file metadata.
|
|
41
41
|
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
-
|
|
42
|
+
- Displays human-readable file sizes
|
|
43
|
+
- Shows line counts for text files
|
|
44
|
+
- Identifies binary and unreadable files by type
|
|
45
|
+
- Optionally displays modification timestamps
|
|
46
46
|
- Respects `.gitignore` rules when Git is installed
|
|
47
47
|
|
|
48
48
|
----
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|