diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..986103133785d894b0ceeeb3152d7ceba4cbce1c --- /dev/null +++ b/README.en.md @@ -0,0 +1,86 @@ +# File Synchronization Toolset + +This project provides a set of tools for folder synchronization, Git operations, and remote file transfer. + +## Feature Overview + +| File | Description | +|------|-------------| +| `1.py` | Core tool for synchronizing local folders with Git repositories | +| `cmd1.py` | Command execution and logging tool | +| `user.py` | Remote server file synchronization client | +| `start.sh` | Environment variable configuration script | + +## Core Features + +### 1. Git Repository Synchronization (1.py) + +- **build_auth_url** - Construct a Git repository URL with authentication credentials +- **clone_repo** - Clone a Git repository from a specified branch +- **get_latest_commit_time** - Retrieve the latest commit time of the repository +- **get_local_folder_latest_mtime** - Get the latest modification time of the local folder +- **commit_and_push** - Commit changes and push to the remote repository +- **sync_mode1/2/3** - Three different synchronization modes + +### 2. Command Execution Tool (cmd1.py) + +- **run_command_and_save_log** - Execute a command and save logs, with support for appending logs and displaying trailing lines + +### 3. Remote Synchronization Client (user.py) + +- **Progress** - File transfer progress display class with speed calculation support +- **SyncClient** - Remote server file synchronization client + - Upload/download files + - Delete remote/local files + - Scan local files and synchronize + +## Quick Start + +### Environment Configuration + +Edit `start.sh` to set Git authentication credentials: + +```bash +export GIT_USERNAME="your_username" +export GIT_PASSWORD="your_password" +``` + +### Synchronize Local Folder to Git Repository + +```python +from 1 import sync_mode1, sync_mode2, sync_mode3 + +# Mode 1: Basic synchronization +sync_mode1("/path/to/local/folder", "https://gitee.com/user/repo.git", "main") + +# Mode 2: Incremental synchronization +sync_mode2("/path/to/local/folder", "https://gitee.com/user/repo.git", "main") + +# Mode 3: Force synchronization +sync_mode3("/path/to/local/folder", "https://gitee.com/user/repo.git", "main") +``` + +### Use Remote Synchronization Client + +```python +from user import SyncClient + +# Initialize client +client = SyncClient(server_ip="192.168.1.100", server_port=8080, local_folder="/local/path") + +# Synchronize files (upload mode) +client.sync(mode="upload") + +# Synchronize files (download mode) +client.sync(mode="download") +``` + +## Dependencies + +- Python 3.x +- Git +- requests library (for HTTP communication) + +## License + +This project is for learning and communication purposes only. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..35e398d3f4f30ed0d323855d8928b3cdc8f6abe0 --- /dev/null +++ b/README.md @@ -0,0 +1,88 @@ + + +# 文件同步工具集 + +本项目提供了一套用于文件夹同步、Git 操作和远程文件传输的工具集。 + +## 功能概述 + +| 文件 | 功能说明 | +|------|----------| +| `1.py` | 本地文件夹与 Git 仓库同步核心工具 | +| `cmd1.py` | 命令执行与日志记录工具 | +| `user.py` | 远程服务器文件同步客户端 | +| `start.sh` | 环境变量配置脚本 | + +## 核心功能 + +### 1. Git 仓库同步 (1.py) + +- **build_auth_url** - 构建带认证信息的 Git 仓库 URL +- **clone_repo** - 克隆指定分支的 Git 仓库 +- **get_latest_commit_time** - 获取仓库最新提交时间 +- **get_local_folder_latest_mtime** - 获取本地文件夹最新修改时间 +- **commit_and_push** - 提交更改并推送到远程仓库 +- **sync_mode1/2/3** - 三种不同的同步模式 + +### 2. 命令执行工具 (cmd1.py) + +- **run_command_and_save_log** - 执行命令并保存日志,支持日志追加和尾行显示 + +### 3. 远程同步客户端 (user.py) + +- **Progress** - 文件传输进度显示类,支持速度计算 +- **SyncClient** - 远程服务器文件同步客户端 + - 上传/下载文件 + - 删除远程/本地文件 + - 扫描本地文件并同步 + +## 快速开始 + +### 环境配置 + +编辑 `start.sh` 设置 Git 认证信息: + +```bash +export GIT_USERNAME="your_username" +export GIT_PASSWORD="your_password" +``` + +### 同步本地文件夹到 Git 仓库 + +```python +from 1 import sync_mode1, sync_mode2, sync_mode3 + +# 模式1: 基础同步 +sync_mode1("/path/to/local/folder", "https://gitee.com/user/repo.git", "main") + +# 模式2: 增量同步 +sync_mode2("/path/to/local/folder", "https://gitee.com/user/repo.git", "main") + +# 模式3: 强制同步 +sync_mode3("/path/to/local/folder", "https://gitee.com/user/repo.git", "main") +``` + +### 使用远程同步客户端 + +```python +from user import SyncClient + +# 初始化客户端 +client = SyncClient(server_ip="192.168.1.100", server_port=8080, local_folder="/local/path") + +# 同步文件(上传模式) +client.sync(mode="upload") + +# 同步文件(下载模式) +client.sync(mode="download") +``` + +## 依赖 + +- Python 3.x +- Git +- requests 库(用于 HTTP 通信) + +## 许可证 + +本项目仅供学习交流使用。 \ No newline at end of file