myspace-cli 1.5.0__py3-none-any.whl → 1.6.1__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.
@@ -1,6 +0,0 @@
1
- space_cli.py,sha256=smLtarqGtTKHcIMi7usckw8M9IcM2hlQDXXY8zvM3x4,9487
2
- myspace_cli-1.5.0.dist-info/METADATA,sha256=QCG4_N2rvebz_sC2ui4RFCG6hRhY1I9j_AvKd38lVLc,12665
3
- myspace_cli-1.5.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
4
- myspace_cli-1.5.0.dist-info/entry_points.txt,sha256=sIVEmPf6W8aNa7KiqOwAI6JrsgHlQciO5xH2G29tKPQ,45
5
- myspace_cli-1.5.0.dist-info/top_level.txt,sha256=lnUfbQX9h-9ZjecMVCOWucS2kx69FwTndlrb48S20Sc,10
6
- myspace_cli-1.5.0.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- space-cli = space_cli:main
space_cli.py DELETED
@@ -1,293 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- SpaceCli - macOS 磁盘空间分析工具
5
- 模块化版本的主入口文件
6
- """
7
-
8
- import os
9
- import sys
10
- import argparse
11
- from pathlib import Path
12
-
13
- # 添加 src 目录到 Python 路径
14
- sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
15
-
16
- from space_cli import SpaceAnalyzer, SpaceCli, IndexStore
17
-
18
-
19
- def main():
20
- """主函数"""
21
- parser = argparse.ArgumentParser(
22
- description="SpaceCli - Mac OS 磁盘空间分析工具",
23
- formatter_class=argparse.RawDescriptionHelpFormatter,
24
- epilog="""
25
- 示例用法:
26
- python space_cli.py # 分析根目录
27
- python space_cli.py -p /Users # 分析用户目录
28
- python space_cli.py -n 10 # 显示前10个最大目录
29
- python space_cli.py --export report.json # 导出报告
30
- python space_cli.py --health-only # 只显示健康状态
31
- """
32
- )
33
-
34
- parser.add_argument(
35
- '-p', '--path',
36
- default='/',
37
- help='要分析的路径 (默认: /)'
38
- )
39
-
40
- # 快捷:分析当前用户目录
41
- parser.add_argument(
42
- '--home',
43
- action='store_true',
44
- help='将分析路径设置为当前用户目录($HOME)'
45
- )
46
-
47
- parser.add_argument(
48
- '-n', '--top-n',
49
- type=int,
50
- default=20,
51
- help='显示前N个最大的目录 (默认: 20)'
52
- )
53
-
54
- parser.add_argument(
55
- '--health-only',
56
- action='store_true',
57
- help='只显示磁盘健康状态'
58
- )
59
-
60
- parser.add_argument(
61
- '--directories-only',
62
- action='store_true',
63
- help='只显示目录分析'
64
- )
65
-
66
- # 索引相关
67
- parser.add_argument(
68
- '--use-index',
69
- dest='use_index',
70
- action='store_true',
71
- help='使用已存在的索引缓存(若存在)'
72
- )
73
- parser.add_argument(
74
- '--no-index',
75
- dest='use_index',
76
- action='store_false',
77
- help='不使用索引缓存'
78
- )
79
- parser.set_defaults(use_index=True)
80
- parser.add_argument(
81
- '--reindex',
82
- action='store_true',
83
- help='强制重建索引'
84
- )
85
- parser.add_argument(
86
- '--index-ttl',
87
- type=int,
88
- default=24,
89
- help='索引缓存有效期(小时),默认24小时'
90
- )
91
- parser.add_argument(
92
- '--no-prompt',
93
- action='store_true',
94
- help='非交互模式:不提示是否使用缓存'
95
- )
96
-
97
- # 应用分析
98
- parser.add_argument(
99
- '--apps',
100
- action='store_true',
101
- help='显示应用目录空间分析与卸载建议'
102
- )
103
-
104
- # 大文件分析
105
- parser.add_argument(
106
- '--big-files',
107
- action='store_true',
108
- help='显示大文件分析结果'
109
- )
110
- parser.add_argument(
111
- '--big-files-top',
112
- type=int,
113
- default=20,
114
- help='大文件分析显示前N个(默认20)'
115
- )
116
- parser.add_argument(
117
- '--big-files-min',
118
- type=str,
119
- default='0',
120
- help='只显示大于该阈值的文件,支持K/M/G/T,如 500M、2G,默认0'
121
- )
122
-
123
- parser.add_argument(
124
- '--export',
125
- metavar='FILE',
126
- help='导出分析报告到JSON文件'
127
- )
128
-
129
- parser.add_argument(
130
- '--version',
131
- action='version',
132
- version='SpaceCli 1.5.0'
133
- )
134
-
135
- args = parser.parse_args()
136
-
137
- # 解析 --big-files-min 阈值字符串到字节
138
- def parse_size(s: str) -> int:
139
- s = (s or '0').strip().upper()
140
- if s.endswith('K'):
141
- return int(float(s[:-1]) * 1024)
142
- if s.endswith('M'):
143
- return int(float(s[:-1]) * 1024**2)
144
- if s.endswith('G'):
145
- return int(float(s[:-1]) * 1024**3)
146
- if s.endswith('T'):
147
- return int(float(s[:-1]) * 1024**4)
148
- try:
149
- return int(float(s))
150
- except ValueError:
151
- return 0
152
- args.big_files_min_bytes = parse_size(getattr(args, 'big_files_min', '0'))
153
-
154
- # 将主要执行流程提取为函数,便于交互模式复用
155
- def run_once(run_args, interactive: bool = False):
156
- # --home 优先设置路径
157
- if getattr(run_args, 'home', False):
158
- run_args.path = str(Path.home())
159
-
160
- # 检查路径是否存在
161
- if not os.path.exists(run_args.path):
162
- print(f"❌ 错误: 路径 '{run_args.path}' 不存在")
163
- if interactive:
164
- return
165
- sys.exit(1)
166
-
167
- # 创建SpaceCli实例
168
- space_cli = SpaceCli()
169
- # 让 SpaceCli 实例可访问参数(用于索引与提示控制)
170
- space_cli.args = run_args
171
-
172
- try:
173
- # 显示系统信息
174
- space_cli.print_system_info()
175
-
176
- # 显示磁盘健康状态
177
- if run_args.health_only:
178
- space_cli.print_disk_health(run_args.path)
179
-
180
- # 显示目录分析
181
- if run_args.directories_only or run_args.path !='/':
182
- space_cli.print_largest_directories(run_args.path, run_args.top_n)
183
- # 若分析路径为当前用户目录,做深度分析
184
- if os.path.abspath(run_args.path) == os.path.abspath(str(Path.home())):
185
- space_cli.print_home_deep_analysis(run_args.top_n)
186
-
187
- # 应用目录分析
188
- if run_args.apps:
189
- space_cli.print_app_analysis(run_args.top_n)
190
-
191
- # 大文件分析
192
- if run_args.big_files:
193
- space_cli.print_big_files(run_args.path, top_n=run_args.big_files_top, min_size_bytes=run_args.big_files_min_bytes)
194
-
195
- # 内存释放优化
196
- if getattr(run_args, 'memory_cleanup', False):
197
- space_cli.print_memory_cleanup()
198
-
199
- # 导出报告
200
- if run_args.export:
201
- space_cli.export_report(run_args.export, run_args.path)
202
-
203
- print("=" * 60)
204
- print("✅ 分析完成!")
205
- print("=" * 60)
206
-
207
- except KeyboardInterrupt:
208
- print("\n\n❌ 用户中断操作")
209
- if interactive:
210
- return
211
- sys.exit(1)
212
- except Exception as e:
213
- print(f"\n❌ 发生错误: {e}")
214
- if interactive:
215
- return
216
- sys.exit(1)
217
-
218
- # 交互式菜单:当未传入任何参数时触发(默认执行全部),执行完后返回菜单
219
- if len(sys.argv) == 1:
220
- while True:
221
- print("=" * 60)
222
- print("🧭 SpaceCli 菜单(直接回车 = 执行全部项目)")
223
- print("=" * 60)
224
- home_path = str(Path.home())
225
- # 动态获取磁盘与内存占用率
226
- try:
227
- analyzer_for_menu = SpaceAnalyzer()
228
- disk_info = analyzer_for_menu.get_disk_usage('/')
229
- disk_usage_display = f"{disk_info['usage_percent']:.1f}%" if disk_info else "未知"
230
- sysinfo = analyzer_for_menu.get_system_info()
231
- mem_usage_display = sysinfo.get("内存使用率", "未知")
232
- except Exception:
233
- disk_usage_display = "未知"
234
- mem_usage_display = "未知"
235
-
236
- print("1) \033[36m执行主要项目(系统信息 + 健康 + 应用)\033[0m")
237
- print(f"2) \033[36m当前用户目录分析(路径: {home_path})\033[0m")
238
- print("3) \033[36m仅显示系统信息\033[0m")
239
- print(f"4) \033[36m仅显示磁盘健康状态\033[0m — 当前磁盘占用: \033[33m{disk_usage_display}\033[0m")
240
- print("5) \033[36m交互式目录空间分析\033[0m")
241
- print("6) \033[36m仅分析程序应用目录空间\033[0m")
242
- print("7) \033[36m仅进行大文件分析(比较耗时,可随时终止)\033[0m")
243
- print(f"8) \033[36m内存释放优化\033[0m — 当前内存使用率: \033[33m{mem_usage_display}\033[0m")
244
- print("0) \033[36m退出\033[0m")
245
- try:
246
- choice = input("请选择 [回车=1]: ").strip()
247
- except EOFError:
248
- choice = ""
249
-
250
- # 重置
251
- args.health_only = False
252
- args.directories_only = False
253
- args.apps = False
254
- args.big_files = False
255
- args.memory_cleanup = False
256
- args.path = '/'
257
-
258
- if choice == "0":
259
- sys.exit(0)
260
- elif choice == "2":
261
- args.path = home_path
262
- args.directories_only = True
263
- elif choice == "3":
264
- pass
265
- elif choice == "4":
266
- args.health_only = True
267
- elif choice == "5":
268
- args.directories_only = True
269
- elif choice == "6":
270
- args.apps = True
271
- elif choice == "7":
272
- args.big_files = True
273
- elif choice == "8":
274
- args.memory_cleanup = True
275
- else:
276
- args.health_only = True
277
- args.apps = True
278
-
279
- run_once(args, interactive=True)
280
-
281
- try:
282
- back = input("按回车返回菜单,输入 q 退出: ").strip().lower()
283
- except EOFError:
284
- back = ""
285
- if back == 'q':
286
- sys.exit(0)
287
- else:
288
- # 非交互:按参数执行一次
289
- run_once(args, interactive=False)
290
-
291
-
292
- if __name__ == "__main__":
293
- main()