filepulse — 文件监控与归档同步工具
轮询检测源文件变化并自动同步到目标位置,支持 zip 归档自动解压处理。
近期更新 / Recent Changes
v0.1.2(2026-09-03)
- 司库日报钩子修复:
hooks/treasury_daily.sh的mailops改用myetl环境(与 mailops 实际安装位置一致),修复发信mailops: not found; - 将
filepulse本地数据目录符号链接纳入版本管理。
v0.1.1(2026-09-03)
- 配置类型护栏:
sync/archive命令启动时校验配置类型,拿错配置会直接报错并提示正确的子命令; - 穿透监管工作手册自动化:
config_treasury.toml新增modelmanual_workbook归档任务——监控坚果云收件箱/司库数据报送通道-*/穿透监管*手册-*.zip,解压归位 SQL/decisions 后触发hooks/modelmanual_workbook.sh:kedro run → 校验三份 PDF → mailops 发送(主题「穿透监管规则手册 <日期>」),同名同内容自动去重; - 路径刷新:modelmanual 相关配置与司库钩子路径统一指向
projects/布局。
功能特性
- 📁 监控文件变化(时间戳、大小、哈希),自动同步到目标位置
- 📦 监控压缩包(zip),自动解压并分发到多个目标目录
- 🔀 支持扁平化复制(丢弃子目录,文件直达目标)
- 🪝 前后置钩子脚本(sync/archive 处理前后执行自定义逻辑)
- 💾 自动备份功能
- 🔄 可配置的检查间隔
- 📊 运行状态统计
- 🎯 支持简单和复杂映射配置
系统要求
- Python ≥ 3.10
- pip install 自动安装依赖 (tomli, tomli-w, click)
快速开始
1. 安装
pip install filepulse
2. 初始化
filepulse init # 创建 config.toml, 日志和备份目录
3. 配置监控文件
编辑 config.toml:
[monitor]
interval = 2.0
[files]
"source/path/file.txt" = "target/path/file.txt"
4. 启动监控
# 文件同步
filepulse sync run config.toml # 前台持续监控
filepulse sync run --daemon config.toml # 后台运行
filepulse sync once config.toml # 一次性同步
# 归档处理
filepulse archive run config.toml # 前台持续扫描
filepulse archive run --daemon config.toml # 后台运行
filepulse archive once config.toml # 一次性处理
filepulse archive check config.toml # 干跑:列出待处理 zip
# 守护进程管理
filepulse daemon status # 查看状态
filepulse daemon stop # 停止
filepulse daemon logs 50 # 查看日志
filepulse daemon reload # 重载配置
命令参考
文件同步 (filepulse sync)
| 命令 | 说明 |
|---|---|
sync run <config> |
前台持续监控 |
sync run --daemon <config> |
后台持续监控 |
sync once <config> |
一次性同步所有变更文件 |
sync check <FILE> <config> |
检查单个文件状态 |
sync stats <config> |
列出配置的文件映射 |
归档处理 (filepulse archive)
| 命令 | 说明 |
|---|---|
archive run <config> |
前台持续扫描 zip |
archive run --daemon <config> |
后台持续扫描 |
archive once <config> |
一次性处理待处理 zip |
archive check <config> |
干跑:列出待处理 zip |
守护进程 (filepulse daemon)
| 命令 | 说明 |
|---|---|
daemon status |
查看所有后台进程 |
daemon stop |
停止所有后台进程 |
daemon logs [N] |
查看最近 N 行日志 |
daemon reload |
停止后重新启动 |
工具
filepulse clean # 清理旧日志和备份
filepulse treasury-run # 运行司库日报流程
filepulse --version # 版本信息
Just 别名(可选)
如果安装了 Just,可使用快捷别名:
just daemon # → filepulse sync run --daemon config.toml
just foreground # → filepulse sync run config.toml
just status # → filepulse daemon status
just stop # → filepulse daemon stop
just logs # → filepulse daemon logs 50
配置说明
文件同步配置
简单格式:
[files]
"源文件路径" = "目标文件路径"
详细格式(带钩子):
[files.my_entry]
source = "/path/to/source.xlsx"
target = "/path/to/target.xlsx"
on_before_sync = "" # 前置钩子脚本
on_after_sync = "" # 后置钩子脚本
监控选项 ([monitor]):
interval: 检查间隔(秒,默认 2.0)check_size: 检查文件大小变化(默认 true)check_mtime: 检查修改时间变化(默认 true)check_hash: 检查文件哈希变化(默认 false)create_backup: 同步前创建备份(默认 true)backup_dir: 备份文件目录(默认 "backup")
归档处理配置
[archive_monitor]
interval = 10.0 # 检查间隔(秒)
extract_temp = "/tmp/sync_extract" # 解压临时目录
base_dir = "/path/to/base" # 源文件扫描根目录
[[archives]]
name = "任务名"
source_pattern = "inbox/通道-*/data-*.zip" # glob 模式(相对于 base_dir)
target_dirs = ["/path/to/output1", "/path/to/output2"] # 多目标(推荐)
flatten_targets = ["/path/to/output2"] # 扁平化目标(丢弃子目录)
rename_to = "" # 解压后重命名顶层目录
archive_dir = "/path/to/processed" # 已处理 zip 归档位置
on_before_process = "" # 前置钩子脚本
on_after_process = "" # 后置钩子脚本
钩子环境变量
| 变量 | 文件同步 | 归档处理 |
|---|---|---|
MONITOR_TYPE |
file_sync |
archive |
MONITOR_EVENT |
before_sync / after_sync |
before_process / after_process |
MONITOR_SOURCE |
源文件路径 | zip 文件路径 |
MONITOR_TARGET |
目标文件路径 | 目标目录 |
MONITOR_TASK |
file_id | 任务名 |
MONITOR_EXTRACTED |
— | 目标目录(仅后置钩子) |
状态文件与路径
filepulse 遵循 XDG 规范存储运行时数据:
- 状态文件:
~/.local/share/filepulse/(或$XDG_DATA_HOME/filepulse/) - 日志文件:
~/.cache/filepulse/(或$XDG_CACHE_HOME/filepulse/) - PID 文件:
~/.local/share/filepulse/
可通过环境变量覆盖:FILEPULSE_DATA_DIR, FILEPULSE_CACHE_DIR
迁移指南
从旧 monitor.py 迁移:
| 旧 | 新 |
|---|---|
python monitor.py config.toml --foreground |
filepulse sync run config.toml |
python monitor.py config.toml --daemon |
filepulse sync run --daemon config.toml |
python monitor.py config.toml --sync-all |
filepulse sync once config.toml |
python monitor.py config.toml --check <F> |
filepulse sync check <F> config.toml |
python monitor.py config.toml --stats |
filepulse sync stats config.toml |
python monitor.py config.toml --archive-foreground |
filepulse archive run config.toml |
python monitor.py config.toml --archive-daemon |
filepulse archive run --daemon config.toml |
python monitor.py config.toml --archive-sync |
filepulse archive once config.toml |
python monitor.py config.toml --archive-check |
filepulse archive check config.toml |
配置文件 100% 向后兼容。
故障排除
- 导入错误 →
pip install filepulse会自动安装依赖 - 文件未同步 →
filepulse daemon logs 50查看日志 - 归档 zip 未处理 →
filepulse archive check config.toml干跑 - 前台调试 →
filepulse archive run config.toml前台运行查看实时输出
Metadata
Release files for filepulse 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| filepulse-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for filepulse-0.1.2-py3-none-any.whl |
Release files / filepulse-0.1.2-py3-none-any.whl
| Download URL | filepulse-0.1.2-py3-none-any.whl |
|---|---|
| Size | 19.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a1a20eb080367a33dd3f50c0d38b991714e100f50eaa86e938f2bc9633521485
|
|
BLAKE2b-256 checksum How to use checksums |
752eaa6b55b510a14b4c4426f6ba884e51dde27a3ab5511962f72cf16505031a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Security for filepulse 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.