git-analytics-cli 0.1.0__py3-none-any.whl
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.
- generate_report.py +2967 -0
- git_analytics.py +843 -0
- git_analytics_cli-0.1.0.data/data/share/git-analytics/share-card.html +528 -0
- git_analytics_cli-0.1.0.dist-info/METADATA +175 -0
- git_analytics_cli-0.1.0.dist-info/RECORD +10 -0
- git_analytics_cli-0.1.0.dist-info/WHEEL +5 -0
- git_analytics_cli-0.1.0.dist-info/entry_points.txt +2 -0
- git_analytics_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
- git_analytics_cli-0.1.0.dist-info/top_level.txt +3 -0
- run.py +224 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
generate_report.py,sha256=cQaCZXbVVbDrMvMf7c3w26LddsOFodgRp8-DGh5OxXI,166339
|
|
2
|
+
git_analytics.py,sha256=etv5y4cqwikNeaBX4QCzfPqD8KwiFmjSfz5KZVzkuqM,33741
|
|
3
|
+
run.py,sha256=kwc2VBJIw4pNFybSyr2SvhiI4373HpBF_5XvgcMR1PE,7282
|
|
4
|
+
git_analytics_cli-0.1.0.data/data/share/git-analytics/share-card.html,sha256=xYU2n1r4EkY2xcv90t0qavv_En60_0TLkSQZvQjAdYc,20859
|
|
5
|
+
git_analytics_cli-0.1.0.dist-info/licenses/LICENSE,sha256=PS3gb5dI6e0m95AlGnPHh31jaxNJNO6X4DEe0t0N7zA,1083
|
|
6
|
+
git_analytics_cli-0.1.0.dist-info/METADATA,sha256=LmxwEbv_rVri2QOhWh6N1MNOBLrD-HIWuCU09mhCH8w,5211
|
|
7
|
+
git_analytics_cli-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
8
|
+
git_analytics_cli-0.1.0.dist-info/entry_points.txt,sha256=eKrTy__YQQhuFD6e81Oq81fq9Mukf2wePMGJLjBokH8,43
|
|
9
|
+
git_analytics_cli-0.1.0.dist-info/top_level.txt,sha256=RuaVtkHZQEzllkZ8uw81gcU9ZalC1ubn-J-hrlOBZ-I,34
|
|
10
|
+
git_analytics_cli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Git Analytics Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
run.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Git Analytics - 一键运行
|
|
4
|
+
扫描本地 Git 仓库,生成个人代码习惯体检报告
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import os
|
|
9
|
+
import shutil
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from generate_report import main as generate_report
|
|
15
|
+
from git_analytics import OUTPUT_DATA, OUTPUT_REPORT, main as collect_data
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _open_file(path):
|
|
19
|
+
if sys.platform == 'darwin':
|
|
20
|
+
subprocess.run(['open', path], check=False)
|
|
21
|
+
elif os.name == 'nt':
|
|
22
|
+
os.startfile(path) # type: ignore[attr-defined]
|
|
23
|
+
else:
|
|
24
|
+
subprocess.run(['xdg-open', path], check=False)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _find_share_card_template():
|
|
28
|
+
candidates = [
|
|
29
|
+
Path(__file__).resolve().with_name('share-card.html'),
|
|
30
|
+
Path(sys.prefix) / 'share' / 'git-analytics' / 'share-card.html',
|
|
31
|
+
]
|
|
32
|
+
for candidate in candidates:
|
|
33
|
+
if candidate.exists():
|
|
34
|
+
return candidate
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _is_interactive():
|
|
39
|
+
return sys.stdin.isatty() and sys.stdout.isatty()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _button_choice(title, options, default=1):
|
|
43
|
+
print(title)
|
|
44
|
+
for idx, (label, desc) in enumerate(options, 1):
|
|
45
|
+
suffix = " ← 默认" if idx == default else ""
|
|
46
|
+
print(f" [{idx}] {label}{suffix}")
|
|
47
|
+
if desc:
|
|
48
|
+
print(f" {desc}")
|
|
49
|
+
raw = input(f"选择 [{default}]: ").strip()
|
|
50
|
+
if not raw:
|
|
51
|
+
return default
|
|
52
|
+
try:
|
|
53
|
+
value = int(raw)
|
|
54
|
+
except ValueError:
|
|
55
|
+
return default
|
|
56
|
+
if 1 <= value <= len(options):
|
|
57
|
+
return value
|
|
58
|
+
return default
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _confirm(title, default=True):
|
|
62
|
+
default_text = "Y/n" if default else "y/N"
|
|
63
|
+
raw = input(f"{title} [{default_text}]: ").strip().lower()
|
|
64
|
+
if not raw:
|
|
65
|
+
return default
|
|
66
|
+
return raw in {"y", "yes", "1", "true"}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _path_label(path):
|
|
70
|
+
return os.path.abspath(os.path.expanduser(path))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _existing_path(path):
|
|
74
|
+
expanded = os.path.abspath(os.path.expanduser(path))
|
|
75
|
+
return expanded if os.path.isdir(expanded) else None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _run_wizard(args):
|
|
79
|
+
home = os.path.expanduser("~")
|
|
80
|
+
current = os.getcwd()
|
|
81
|
+
candidates = [
|
|
82
|
+
("当前目录", current),
|
|
83
|
+
("Desktop", os.path.join(home, "Desktop")),
|
|
84
|
+
("Projects", os.path.join(home, "Projects")),
|
|
85
|
+
("Code", os.path.join(home, "Code")),
|
|
86
|
+
("自定义路径", None),
|
|
87
|
+
]
|
|
88
|
+
options = []
|
|
89
|
+
values = []
|
|
90
|
+
for label, path in candidates:
|
|
91
|
+
if path is None:
|
|
92
|
+
options.append((label, "输入一个或多个目录,用逗号分隔"))
|
|
93
|
+
values.append(None)
|
|
94
|
+
continue
|
|
95
|
+
existing = _existing_path(path)
|
|
96
|
+
if existing:
|
|
97
|
+
options.append((label, existing))
|
|
98
|
+
values.append(existing)
|
|
99
|
+
|
|
100
|
+
print()
|
|
101
|
+
print("Git Analytics Setup")
|
|
102
|
+
print("像选开关一样跑一次,不用记命令参数。")
|
|
103
|
+
print()
|
|
104
|
+
|
|
105
|
+
choice = _button_choice("扫描哪里?", options, default=1)
|
|
106
|
+
selected = values[choice - 1]
|
|
107
|
+
if selected is None:
|
|
108
|
+
raw = input("输入扫描目录(多个目录用逗号分隔): ").strip()
|
|
109
|
+
scan_dirs = [p.strip() for p in raw.split(",") if p.strip()]
|
|
110
|
+
if not scan_dirs:
|
|
111
|
+
scan_dirs = [current]
|
|
112
|
+
else:
|
|
113
|
+
scan_dirs = [selected]
|
|
114
|
+
|
|
115
|
+
depth_choice = _button_choice(
|
|
116
|
+
"扫描深度?",
|
|
117
|
+
[
|
|
118
|
+
("标准", "max-depth = 3,适合大多数项目目录"),
|
|
119
|
+
("更深", "max-depth = 5,适合 repo 放得更散的目录"),
|
|
120
|
+
("自定义", "手动输入深度"),
|
|
121
|
+
],
|
|
122
|
+
default=1,
|
|
123
|
+
)
|
|
124
|
+
if depth_choice == 1:
|
|
125
|
+
max_depth = 3
|
|
126
|
+
elif depth_choice == 2:
|
|
127
|
+
max_depth = 5
|
|
128
|
+
else:
|
|
129
|
+
raw = input("输入 max-depth [3]: ").strip()
|
|
130
|
+
try:
|
|
131
|
+
max_depth = int(raw) if raw else 3
|
|
132
|
+
except ValueError:
|
|
133
|
+
max_depth = 3
|
|
134
|
+
|
|
135
|
+
output_raw = input(f"输出目录 [{os.getcwd()}]: ").strip()
|
|
136
|
+
output_dir = output_raw or os.getcwd()
|
|
137
|
+
|
|
138
|
+
args.scan_dir = scan_dirs
|
|
139
|
+
args.max_depth = max_depth
|
|
140
|
+
args.output_dir = output_dir
|
|
141
|
+
args.open = _confirm("生成后自动打开报告?", default=True)
|
|
142
|
+
args.share_card = _confirm("同时生成分享卡片设计器?", default=True)
|
|
143
|
+
print()
|
|
144
|
+
return args
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def main():
|
|
148
|
+
parser = argparse.ArgumentParser(description='Git Analytics - 个人代码习惯体检工具')
|
|
149
|
+
parser.add_argument('scan_dir', nargs='*',
|
|
150
|
+
help='扫描目录,可传多个;默认扫描当前目录')
|
|
151
|
+
parser.add_argument('--since', help='起始日期,如 2024-01-01')
|
|
152
|
+
parser.add_argument('--until', help='截止日期,如 2024-12-31')
|
|
153
|
+
parser.add_argument('--project', help='只分析指定项目(支持模糊匹配)')
|
|
154
|
+
parser.add_argument('--output-dir', default=os.getcwd(), help='输出目录(默认当前目录)')
|
|
155
|
+
parser.add_argument('--max-depth', type=int, default=3, help='扫描目录深度(默认 3)')
|
|
156
|
+
parser.add_argument('--open', action='store_true', help='生成后自动打开报告')
|
|
157
|
+
parser.add_argument('--share-card', action='store_true', help='同时输出 PNG 分享卡片设计器')
|
|
158
|
+
parser.add_argument('--no-wizard', action='store_true', help='关闭交互式向导,直接使用默认参数')
|
|
159
|
+
args = parser.parse_args()
|
|
160
|
+
|
|
161
|
+
if not args.scan_dir and not args.no_wizard and _is_interactive():
|
|
162
|
+
args = _run_wizard(args)
|
|
163
|
+
|
|
164
|
+
scan_dirs = args.scan_dir or [os.getcwd()]
|
|
165
|
+
output_dir = os.path.abspath(os.path.expanduser(args.output_dir))
|
|
166
|
+
data_path = os.path.join(output_dir, OUTPUT_DATA)
|
|
167
|
+
report_path = os.path.join(output_dir, OUTPUT_REPORT)
|
|
168
|
+
share_card_path = os.path.join(output_dir, 'share-card.html')
|
|
169
|
+
|
|
170
|
+
print("=" * 60)
|
|
171
|
+
print("🔍 Git Analytics - 个人代码习惯体检工具")
|
|
172
|
+
print("=" * 60)
|
|
173
|
+
print("扫描目录:")
|
|
174
|
+
for item in scan_dirs:
|
|
175
|
+
print(f" - {os.path.abspath(os.path.expanduser(item))}")
|
|
176
|
+
print(f"扫描深度: {args.max_depth}")
|
|
177
|
+
print(f"输出目录: {output_dir}")
|
|
178
|
+
if args.since or args.until:
|
|
179
|
+
print(f"时间范围: {args.since or '起始'} ~ {args.until or '至今'}")
|
|
180
|
+
if args.project:
|
|
181
|
+
print(f"指定项目: {args.project}")
|
|
182
|
+
print()
|
|
183
|
+
|
|
184
|
+
# 1. 收集数据
|
|
185
|
+
print("📊 第一步:收集 Git 仓库数据...")
|
|
186
|
+
analysis = collect_data(
|
|
187
|
+
scan_dir=scan_dirs,
|
|
188
|
+
since=args.since,
|
|
189
|
+
until=args.until,
|
|
190
|
+
project=args.project,
|
|
191
|
+
output_dir=output_dir,
|
|
192
|
+
max_depth=args.max_depth,
|
|
193
|
+
)
|
|
194
|
+
if analysis is None:
|
|
195
|
+
raise SystemExit(1)
|
|
196
|
+
|
|
197
|
+
print()
|
|
198
|
+
print("📝 第二步:生成体检报告...")
|
|
199
|
+
generate_report(data_path=data_path, output_path=report_path)
|
|
200
|
+
|
|
201
|
+
if args.share_card:
|
|
202
|
+
template = _find_share_card_template()
|
|
203
|
+
if template:
|
|
204
|
+
shutil.copyfile(template, share_card_path)
|
|
205
|
+
else:
|
|
206
|
+
print("⚠️ 未找到 share-card.html 模板,跳过分享器输出")
|
|
207
|
+
|
|
208
|
+
if args.open:
|
|
209
|
+
_open_file(report_path)
|
|
210
|
+
|
|
211
|
+
print()
|
|
212
|
+
print("=" * 60)
|
|
213
|
+
print("✅ 完成!")
|
|
214
|
+
print(f"📄 报告文件: {report_path}")
|
|
215
|
+
print(f"📊 数据文件: {data_path}")
|
|
216
|
+
if args.share_card and os.path.exists(share_card_path):
|
|
217
|
+
print(f"🖼️ 分享器: {share_card_path}")
|
|
218
|
+
print()
|
|
219
|
+
print("用浏览器打开 report.html 查看你的代码习惯体检报告")
|
|
220
|
+
print("=" * 60)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
if __name__ == '__main__':
|
|
224
|
+
main()
|