filepulse 0.1.0__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.
@@ -0,0 +1,241 @@
1
+ Metadata-Version: 2.4
2
+ Name: filepulse
3
+ Version: 0.1.0
4
+ Summary: 文件监控与归档同步工具 — 轮询检测文件变化并自动同步,支持 zip 归档自动解压处理
5
+ Author: songwupei
6
+ License: MIT
7
+ Project-URL: Homepage, https://codeberg.org/songwupei/filepulse
8
+ Project-URL: Repository, https://codeberg.org/songwupei/filepulse
9
+ Project-URL: Issues, https://codeberg.org/songwupei/filepulse/issues
10
+ Keywords: file-sync,monitor,polling,archive,zip,backup
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: System :: Archiving
23
+ Classifier: Topic :: System :: Filesystems
24
+ Classifier: Topic :: Utilities
25
+ Requires-Python: >=3.10
26
+ Description-Content-Type: text/markdown
27
+ Requires-Dist: tomli>=2.0
28
+ Requires-Dist: tomli-w>=1.0
29
+ Requires-Dist: click>=8.1
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=8.0; extra == "dev"
32
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
33
+
34
+ # filepulse — 文件监控与归档同步工具
35
+
36
+ 轮询检测源文件变化并自动同步到目标位置,支持 zip 归档自动解压处理。
37
+
38
+ ## 功能特性
39
+
40
+ - 📁 监控文件变化(时间戳、大小、哈希),自动同步到目标位置
41
+ - 📦 监控压缩包(zip),自动解压并分发到多个目标目录
42
+ - 🔀 支持扁平化复制(丢弃子目录,文件直达目标)
43
+ - 🪝 前后置钩子脚本(sync/archive 处理前后执行自定义逻辑)
44
+ - 💾 自动备份功能
45
+ - 🔄 可配置的检查间隔
46
+ - 📊 运行状态统计
47
+ - 🎯 支持简单和复杂映射配置
48
+
49
+ ## 系统要求
50
+
51
+ - Python ≥ 3.10
52
+ - pip install 自动安装依赖 (tomli, tomli-w, click)
53
+
54
+ ## 快速开始
55
+
56
+ ### 1. 安装
57
+
58
+ ```bash
59
+ pip install filepulse
60
+ ```
61
+
62
+ ### 2. 初始化
63
+
64
+ ```bash
65
+ filepulse init # 创建 config.toml, 日志和备份目录
66
+ ```
67
+
68
+ ### 3. 配置监控文件
69
+
70
+ 编辑 `config.toml`:
71
+
72
+ ```toml
73
+ [monitor]
74
+ interval = 2.0
75
+
76
+ [files]
77
+ "source/path/file.txt" = "target/path/file.txt"
78
+ ```
79
+
80
+ ### 4. 启动监控
81
+
82
+ ```bash
83
+ # 文件同步
84
+ filepulse sync run config.toml # 前台持续监控
85
+ filepulse sync run --daemon config.toml # 后台运行
86
+ filepulse sync once config.toml # 一次性同步
87
+
88
+ # 归档处理
89
+ filepulse archive run config.toml # 前台持续扫描
90
+ filepulse archive run --daemon config.toml # 后台运行
91
+ filepulse archive once config.toml # 一次性处理
92
+ filepulse archive check config.toml # 干跑:列出待处理 zip
93
+
94
+ # 守护进程管理
95
+ filepulse daemon status # 查看状态
96
+ filepulse daemon stop # 停止
97
+ filepulse daemon logs 50 # 查看日志
98
+ filepulse daemon reload # 重载配置
99
+ ```
100
+
101
+ ## 命令参考
102
+
103
+ ### 文件同步 (`filepulse sync`)
104
+
105
+ | 命令 | 说明 |
106
+ |---|---|
107
+ | `sync run <config>` | 前台持续监控 |
108
+ | `sync run --daemon <config>` | 后台持续监控 |
109
+ | `sync once <config>` | 一次性同步所有变更文件 |
110
+ | `sync check <FILE> <config>` | 检查单个文件状态 |
111
+ | `sync stats <config>` | 列出配置的文件映射 |
112
+
113
+ ### 归档处理 (`filepulse archive`)
114
+
115
+ | 命令 | 说明 |
116
+ |---|---|
117
+ | `archive run <config>` | 前台持续扫描 zip |
118
+ | `archive run --daemon <config>` | 后台持续扫描 |
119
+ | `archive once <config>` | 一次性处理待处理 zip |
120
+ | `archive check <config>` | 干跑:列出待处理 zip |
121
+
122
+ ### 守护进程 (`filepulse daemon`)
123
+
124
+ | 命令 | 说明 |
125
+ |---|---|
126
+ | `daemon status` | 查看所有后台进程 |
127
+ | `daemon stop` | 停止所有后台进程 |
128
+ | `daemon logs [N]` | 查看最近 N 行日志 |
129
+ | `daemon reload` | 停止后重新启动 |
130
+
131
+ ### 工具
132
+
133
+ ```bash
134
+ filepulse clean # 清理旧日志和备份
135
+ filepulse treasury-run # 运行司库日报流程
136
+ filepulse --version # 版本信息
137
+ ```
138
+
139
+ ### Just 别名(可选)
140
+
141
+ 如果安装了 [Just](https://just.systems),可使用快捷别名:
142
+
143
+ ```bash
144
+ just daemon # → filepulse sync run --daemon config.toml
145
+ just foreground # → filepulse sync run config.toml
146
+ just status # → filepulse daemon status
147
+ just stop # → filepulse daemon stop
148
+ just logs # → filepulse daemon logs 50
149
+ ```
150
+
151
+ ## 配置说明
152
+
153
+ ### 文件同步配置
154
+
155
+ **简单格式**:
156
+ ```toml
157
+ [files]
158
+ "源文件路径" = "目标文件路径"
159
+ ```
160
+
161
+ **详细格式(带钩子)**:
162
+ ```toml
163
+ [files.my_entry]
164
+ source = "/path/to/source.xlsx"
165
+ target = "/path/to/target.xlsx"
166
+ on_before_sync = "" # 前置钩子脚本
167
+ on_after_sync = "" # 后置钩子脚本
168
+ ```
169
+
170
+ **监控选项** (`[monitor]`):
171
+ - `interval`: 检查间隔(秒,默认 2.0)
172
+ - `check_size`: 检查文件大小变化(默认 true)
173
+ - `check_mtime`: 检查修改时间变化(默认 true)
174
+ - `check_hash`: 检查文件哈希变化(默认 false)
175
+ - `create_backup`: 同步前创建备份(默认 true)
176
+ - `backup_dir`: 备份文件目录(默认 "backup")
177
+
178
+ ### 归档处理配置
179
+
180
+ ```toml
181
+ [archive_monitor]
182
+ interval = 10.0 # 检查间隔(秒)
183
+ extract_temp = "/tmp/sync_extract" # 解压临时目录
184
+ base_dir = "/path/to/base" # 源文件扫描根目录
185
+
186
+ [[archives]]
187
+ name = "任务名"
188
+ source_pattern = "inbox/通道-*/data-*.zip" # glob 模式(相对于 base_dir)
189
+ target_dirs = ["/path/to/output1", "/path/to/output2"] # 多目标(推荐)
190
+ flatten_targets = ["/path/to/output2"] # 扁平化目标(丢弃子目录)
191
+ rename_to = "" # 解压后重命名顶层目录
192
+ archive_dir = "/path/to/processed" # 已处理 zip 归档位置
193
+ on_before_process = "" # 前置钩子脚本
194
+ on_after_process = "" # 后置钩子脚本
195
+ ```
196
+
197
+ ### 钩子环境变量
198
+
199
+ | 变量 | 文件同步 | 归档处理 |
200
+ |---|---|---|
201
+ | `MONITOR_TYPE` | `file_sync` | `archive` |
202
+ | `MONITOR_EVENT` | `before_sync` / `after_sync` | `before_process` / `after_process` |
203
+ | `MONITOR_SOURCE` | 源文件路径 | zip 文件路径 |
204
+ | `MONITOR_TARGET` | 目标文件路径 | 目标目录 |
205
+ | `MONITOR_TASK` | file_id | 任务名 |
206
+ | `MONITOR_EXTRACTED` | — | 目标目录(仅后置钩子) |
207
+
208
+ ### 状态文件与路径
209
+
210
+ filepulse 遵循 XDG 规范存储运行时数据:
211
+
212
+ - 状态文件: `~/.local/share/filepulse/` (或 `$XDG_DATA_HOME/filepulse/`)
213
+ - 日志文件: `~/.cache/filepulse/` (或 `$XDG_CACHE_HOME/filepulse/`)
214
+ - PID 文件: `~/.local/share/filepulse/`
215
+
216
+ 可通过环境变量覆盖:`FILEPULSE_DATA_DIR`, `FILEPULSE_CACHE_DIR`
217
+
218
+ ## 迁移指南
219
+
220
+ 从旧 `monitor.py` 迁移:
221
+
222
+ | 旧 | 新 |
223
+ |---|---|
224
+ | `python monitor.py config.toml --foreground` | `filepulse sync run config.toml` |
225
+ | `python monitor.py config.toml --daemon` | `filepulse sync run --daemon config.toml` |
226
+ | `python monitor.py config.toml --sync-all` | `filepulse sync once config.toml` |
227
+ | `python monitor.py config.toml --check <F>` | `filepulse sync check <F> config.toml` |
228
+ | `python monitor.py config.toml --stats` | `filepulse sync stats config.toml` |
229
+ | `python monitor.py config.toml --archive-foreground` | `filepulse archive run config.toml` |
230
+ | `python monitor.py config.toml --archive-daemon` | `filepulse archive run --daemon config.toml` |
231
+ | `python monitor.py config.toml --archive-sync` | `filepulse archive once config.toml` |
232
+ | `python monitor.py config.toml --archive-check` | `filepulse archive check config.toml` |
233
+
234
+ 配置文件 100% 向后兼容。
235
+
236
+ ## 故障排除
237
+
238
+ - **导入错误** → `pip install filepulse` 会自动安装依赖
239
+ - **文件未同步** → `filepulse daemon logs 50` 查看日志
240
+ - **归档 zip 未处理** → `filepulse archive check config.toml` 干跑
241
+ - **前台调试** → `filepulse archive run config.toml` 前台运行查看实时输出
@@ -0,0 +1,208 @@
1
+ # filepulse — 文件监控与归档同步工具
2
+
3
+ 轮询检测源文件变化并自动同步到目标位置,支持 zip 归档自动解压处理。
4
+
5
+ ## 功能特性
6
+
7
+ - 📁 监控文件变化(时间戳、大小、哈希),自动同步到目标位置
8
+ - 📦 监控压缩包(zip),自动解压并分发到多个目标目录
9
+ - 🔀 支持扁平化复制(丢弃子目录,文件直达目标)
10
+ - 🪝 前后置钩子脚本(sync/archive 处理前后执行自定义逻辑)
11
+ - 💾 自动备份功能
12
+ - 🔄 可配置的检查间隔
13
+ - 📊 运行状态统计
14
+ - 🎯 支持简单和复杂映射配置
15
+
16
+ ## 系统要求
17
+
18
+ - Python ≥ 3.10
19
+ - pip install 自动安装依赖 (tomli, tomli-w, click)
20
+
21
+ ## 快速开始
22
+
23
+ ### 1. 安装
24
+
25
+ ```bash
26
+ pip install filepulse
27
+ ```
28
+
29
+ ### 2. 初始化
30
+
31
+ ```bash
32
+ filepulse init # 创建 config.toml, 日志和备份目录
33
+ ```
34
+
35
+ ### 3. 配置监控文件
36
+
37
+ 编辑 `config.toml`:
38
+
39
+ ```toml
40
+ [monitor]
41
+ interval = 2.0
42
+
43
+ [files]
44
+ "source/path/file.txt" = "target/path/file.txt"
45
+ ```
46
+
47
+ ### 4. 启动监控
48
+
49
+ ```bash
50
+ # 文件同步
51
+ filepulse sync run config.toml # 前台持续监控
52
+ filepulse sync run --daemon config.toml # 后台运行
53
+ filepulse sync once config.toml # 一次性同步
54
+
55
+ # 归档处理
56
+ filepulse archive run config.toml # 前台持续扫描
57
+ filepulse archive run --daemon config.toml # 后台运行
58
+ filepulse archive once config.toml # 一次性处理
59
+ filepulse archive check config.toml # 干跑:列出待处理 zip
60
+
61
+ # 守护进程管理
62
+ filepulse daemon status # 查看状态
63
+ filepulse daemon stop # 停止
64
+ filepulse daemon logs 50 # 查看日志
65
+ filepulse daemon reload # 重载配置
66
+ ```
67
+
68
+ ## 命令参考
69
+
70
+ ### 文件同步 (`filepulse sync`)
71
+
72
+ | 命令 | 说明 |
73
+ |---|---|
74
+ | `sync run <config>` | 前台持续监控 |
75
+ | `sync run --daemon <config>` | 后台持续监控 |
76
+ | `sync once <config>` | 一次性同步所有变更文件 |
77
+ | `sync check <FILE> <config>` | 检查单个文件状态 |
78
+ | `sync stats <config>` | 列出配置的文件映射 |
79
+
80
+ ### 归档处理 (`filepulse archive`)
81
+
82
+ | 命令 | 说明 |
83
+ |---|---|
84
+ | `archive run <config>` | 前台持续扫描 zip |
85
+ | `archive run --daemon <config>` | 后台持续扫描 |
86
+ | `archive once <config>` | 一次性处理待处理 zip |
87
+ | `archive check <config>` | 干跑:列出待处理 zip |
88
+
89
+ ### 守护进程 (`filepulse daemon`)
90
+
91
+ | 命令 | 说明 |
92
+ |---|---|
93
+ | `daemon status` | 查看所有后台进程 |
94
+ | `daemon stop` | 停止所有后台进程 |
95
+ | `daemon logs [N]` | 查看最近 N 行日志 |
96
+ | `daemon reload` | 停止后重新启动 |
97
+
98
+ ### 工具
99
+
100
+ ```bash
101
+ filepulse clean # 清理旧日志和备份
102
+ filepulse treasury-run # 运行司库日报流程
103
+ filepulse --version # 版本信息
104
+ ```
105
+
106
+ ### Just 别名(可选)
107
+
108
+ 如果安装了 [Just](https://just.systems),可使用快捷别名:
109
+
110
+ ```bash
111
+ just daemon # → filepulse sync run --daemon config.toml
112
+ just foreground # → filepulse sync run config.toml
113
+ just status # → filepulse daemon status
114
+ just stop # → filepulse daemon stop
115
+ just logs # → filepulse daemon logs 50
116
+ ```
117
+
118
+ ## 配置说明
119
+
120
+ ### 文件同步配置
121
+
122
+ **简单格式**:
123
+ ```toml
124
+ [files]
125
+ "源文件路径" = "目标文件路径"
126
+ ```
127
+
128
+ **详细格式(带钩子)**:
129
+ ```toml
130
+ [files.my_entry]
131
+ source = "/path/to/source.xlsx"
132
+ target = "/path/to/target.xlsx"
133
+ on_before_sync = "" # 前置钩子脚本
134
+ on_after_sync = "" # 后置钩子脚本
135
+ ```
136
+
137
+ **监控选项** (`[monitor]`):
138
+ - `interval`: 检查间隔(秒,默认 2.0)
139
+ - `check_size`: 检查文件大小变化(默认 true)
140
+ - `check_mtime`: 检查修改时间变化(默认 true)
141
+ - `check_hash`: 检查文件哈希变化(默认 false)
142
+ - `create_backup`: 同步前创建备份(默认 true)
143
+ - `backup_dir`: 备份文件目录(默认 "backup")
144
+
145
+ ### 归档处理配置
146
+
147
+ ```toml
148
+ [archive_monitor]
149
+ interval = 10.0 # 检查间隔(秒)
150
+ extract_temp = "/tmp/sync_extract" # 解压临时目录
151
+ base_dir = "/path/to/base" # 源文件扫描根目录
152
+
153
+ [[archives]]
154
+ name = "任务名"
155
+ source_pattern = "inbox/通道-*/data-*.zip" # glob 模式(相对于 base_dir)
156
+ target_dirs = ["/path/to/output1", "/path/to/output2"] # 多目标(推荐)
157
+ flatten_targets = ["/path/to/output2"] # 扁平化目标(丢弃子目录)
158
+ rename_to = "" # 解压后重命名顶层目录
159
+ archive_dir = "/path/to/processed" # 已处理 zip 归档位置
160
+ on_before_process = "" # 前置钩子脚本
161
+ on_after_process = "" # 后置钩子脚本
162
+ ```
163
+
164
+ ### 钩子环境变量
165
+
166
+ | 变量 | 文件同步 | 归档处理 |
167
+ |---|---|---|
168
+ | `MONITOR_TYPE` | `file_sync` | `archive` |
169
+ | `MONITOR_EVENT` | `before_sync` / `after_sync` | `before_process` / `after_process` |
170
+ | `MONITOR_SOURCE` | 源文件路径 | zip 文件路径 |
171
+ | `MONITOR_TARGET` | 目标文件路径 | 目标目录 |
172
+ | `MONITOR_TASK` | file_id | 任务名 |
173
+ | `MONITOR_EXTRACTED` | — | 目标目录(仅后置钩子) |
174
+
175
+ ### 状态文件与路径
176
+
177
+ filepulse 遵循 XDG 规范存储运行时数据:
178
+
179
+ - 状态文件: `~/.local/share/filepulse/` (或 `$XDG_DATA_HOME/filepulse/`)
180
+ - 日志文件: `~/.cache/filepulse/` (或 `$XDG_CACHE_HOME/filepulse/`)
181
+ - PID 文件: `~/.local/share/filepulse/`
182
+
183
+ 可通过环境变量覆盖:`FILEPULSE_DATA_DIR`, `FILEPULSE_CACHE_DIR`
184
+
185
+ ## 迁移指南
186
+
187
+ 从旧 `monitor.py` 迁移:
188
+
189
+ | 旧 | 新 |
190
+ |---|---|
191
+ | `python monitor.py config.toml --foreground` | `filepulse sync run config.toml` |
192
+ | `python monitor.py config.toml --daemon` | `filepulse sync run --daemon config.toml` |
193
+ | `python monitor.py config.toml --sync-all` | `filepulse sync once config.toml` |
194
+ | `python monitor.py config.toml --check <F>` | `filepulse sync check <F> config.toml` |
195
+ | `python monitor.py config.toml --stats` | `filepulse sync stats config.toml` |
196
+ | `python monitor.py config.toml --archive-foreground` | `filepulse archive run config.toml` |
197
+ | `python monitor.py config.toml --archive-daemon` | `filepulse archive run --daemon config.toml` |
198
+ | `python monitor.py config.toml --archive-sync` | `filepulse archive once config.toml` |
199
+ | `python monitor.py config.toml --archive-check` | `filepulse archive check config.toml` |
200
+
201
+ 配置文件 100% 向后兼容。
202
+
203
+ ## 故障排除
204
+
205
+ - **导入错误** → `pip install filepulse` 会自动安装依赖
206
+ - **文件未同步** → `filepulse daemon logs 50` 查看日志
207
+ - **归档 zip 未处理** → `filepulse archive check config.toml` 干跑
208
+ - **前台调试** → `filepulse archive run config.toml` 前台运行查看实时输出
@@ -0,0 +1,53 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "filepulse"
7
+ version = "0.1.0"
8
+ description = "文件监控与归档同步工具 — 轮询检测文件变化并自动同步,支持 zip 归档自动解压处理"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ requires-python = ">=3.10"
12
+ authors = [
13
+ {name = "songwupei"},
14
+ ]
15
+ keywords = ["file-sync", "monitor", "polling", "archive", "zip", "backup"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Environment :: Console",
19
+ "Intended Audience :: Developers",
20
+ "Intended Audience :: System Administrators",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Operating System :: POSIX :: Linux",
23
+ "Programming Language :: Python :: 3 :: Only",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Programming Language :: Python :: 3.13",
28
+ "Topic :: System :: Archiving",
29
+ "Topic :: System :: Filesystems",
30
+ "Topic :: Utilities",
31
+ ]
32
+ dependencies = [
33
+ "tomli>=2.0",
34
+ "tomli-w>=1.0",
35
+ "click>=8.1",
36
+ ]
37
+
38
+ [project.scripts]
39
+ filepulse = "filepulse.cli:main"
40
+
41
+ [project.urls]
42
+ Homepage = "https://codeberg.org/songwupei/filepulse"
43
+ Repository = "https://codeberg.org/songwupei/filepulse"
44
+ Issues = "https://codeberg.org/songwupei/filepulse/issues"
45
+
46
+ [project.optional-dependencies]
47
+ dev = [
48
+ "pytest>=8.0",
49
+ "pytest-cov>=5.0",
50
+ ]
51
+
52
+ [tool.setuptools.packages.find]
53
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """filepulse — 文件监控与归档同步工具."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,5 @@
1
+ """Allow running as ``python -m filepulse``."""
2
+
3
+ from .cli import main
4
+
5
+ main()