Repository navigation
Expand file tree
/
Copy pathreport.py
More file actions
158 lines (119 loc) · 3.06 KB
/
Copy pathreport.py
File metadata and controls
158 lines (119 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# file: report.py
"""Core models, constants, and enums used across the app."""
from __future__ import annotations
import datetime
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
# Exclusions and file-type hints
EXCLUDED_DIRS: set[str] = {"__pycache__", ".git", ".svn", ".hg"}
CODE_EXTENSIONS: set[str] = {
# Python
".py", ".pyw", ".spec",
".ipynb",
# Go
".go", ".mod", ".sum",
# C / C++
".c", ".h", ".cpp", ".hpp", ".cc", ".cxx", ".hh", ".hxx",
# C#
".cs",
# Java
".java",
# Kotlin
".kt", ".kts",
# Scala
".scala", ".sc",
# Rust
".rs",
# Swift
".swift",
# Objective-C
".m", ".mm",
# Dart / Flutter
".dart",
# JavaScript / TypeScript
".js", ".mjs", ".cjs",
".ts", ".tsx", ".jsx",
# PHP
".php", ".phtml",
# Ruby
".rb", ".erb",
# Perl
".pl", ".pm", ".t",
# R
".r", ".R", ".Rmd",
# Julia
".jl",
# Shell / Batch
".sh", ".bash", ".zsh", ".ksh", ".csh", ".bat", ".cmd",
# PowerShell
".ps1", ".psm1", ".psd1",
# SQL & DB
".sql", ".psql",
# Haskell
".hs", ".lhs",
# Erlang / Elixir
".erl", ".hrl",
".ex", ".exs",
# OCaml / F#
".ml", ".mli", ".fs", ".fsi", ".fsx",
# Lisp / Scheme / Clojure
".lisp", ".lsp", ".cl", ".el", ".scm", ".clj", ".cljs", ".cljc",
# Lua
".lua",
# YAML / JSON / TOML / INI / ENV
".yml", ".yaml", ".json", ".toml", ".ini", ".env",
# XML / HTML / Templates
".xml", ".xsd", ".xslt", ".html", ".htm", ".xhtml",
".jsp", ".asp", ".aspx",
".mustache", ".hbs", ".ejs", ".twig", ".jinja", ".jinja2",
".tmpl", ".tpl",
# CSS & Preprocessors
".css", ".scss", ".sass", ".less",
# Markdown / Docs
".md", ".markdown", ".rst", ".txt", ".tex",
# Config / Misc
".cfg", ".conf", ".properties", ".gradle", ".groovy",
".make", ".mk", "Makefile", "CMakeLists.txt",
".dockerfile", "Dockerfile",
".gitignore", ".gitattributes",
".editorconfig",
".bazel", ".bzl",
# Protocols
".proto", ".thrift", ".avdl",
# Assembly
".s", ".asm",
}
MAX_THREADS_FALLBACK = 4
def now_stamp() -> str:
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
def format_size(size_bytes: int) -> str:
return f"{max(size_bytes, 0) // 1024} KB"
@dataclass
class FileInfo:
path: str
size_bytes: int
mtime_iso: str
lines: int | str
words: int | str
content: str | None
@dataclass
class ProjectReport:
root: str
generated_at: str
files: list[FileInfo]
class OutputFormat(Enum):
MARKDOWN = "Markdown (.md)"
PLAINTEXT = "Plain text (.txt)"
HTML = "HTML (.html)"
JSON = "JSON (.json)"
ZIP = "Zip (.zip)"
DEEP_MARKDOWN = "Deep analysis (.md)"
DEEP_JSON = "Deep analysis (.json)"
LRC = "LLM Capsule (.lrc.json)"
@staticmethod
def from_label(label: str) -> "OutputFormat":
for fmt in OutputFormat:
if fmt.value == label:
return fmt
raise ValueError(f"Unknown format: {label}")