py-jsync 0.2.31__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.
Potentially problematic release.
This version of py-jsync might be problematic. Click here for more details.
- py_jsync-0.2.31/.github/workflows/ci.yml +44 -0
- py_jsync-0.2.31/.github/workflows/publish.yml +73 -0
- py_jsync-0.2.31/.gitignore +2 -0
- py_jsync-0.2.31/LICENSE +21 -0
- py_jsync-0.2.31/PKG-INFO +104 -0
- py_jsync-0.2.31/README.md +91 -0
- py_jsync-0.2.31/jsync/__init__.py +20 -0
- py_jsync-0.2.31/jsync/columns.py +42 -0
- py_jsync-0.2.31/jsync/job.py +196 -0
- py_jsync-0.2.31/jsync/jsync.py +82 -0
- py_jsync-0.2.31/jsync/rsync.py +265 -0
- py_jsync-0.2.31/jsync/syncer.py +210 -0
- py_jsync-0.2.31/jsync/utils.py +70 -0
- py_jsync-0.2.31/pyproject.toml +58 -0
- py_jsync-0.2.31/tests/__init__.py +0 -0
- py_jsync-0.2.31/uv.lock +121 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["master"]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: ["master"]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint-build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
16
|
+
env:
|
|
17
|
+
UV_PROJECT_ENVIRONMENT: .venv
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout
|
|
20
|
+
uses: actions/checkout@v4
|
|
21
|
+
with:
|
|
22
|
+
fetch-depth: 0 # needed for hatch-vcs versioning
|
|
23
|
+
|
|
24
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
25
|
+
uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: ${{ matrix.python-version }}
|
|
28
|
+
|
|
29
|
+
- name: Set up uv
|
|
30
|
+
uses: astral-sh/setup-uv@v5
|
|
31
|
+
with:
|
|
32
|
+
enable-cache: true
|
|
33
|
+
|
|
34
|
+
- name: Create venv
|
|
35
|
+
run: uv venv --python ${{ matrix.python-version }}
|
|
36
|
+
|
|
37
|
+
- name: Install dependencies
|
|
38
|
+
run: uv pip install --python .venv/bin/python -e ".[dev]"
|
|
39
|
+
|
|
40
|
+
- name: Ruff
|
|
41
|
+
run: uv run ruff check .
|
|
42
|
+
|
|
43
|
+
- name: Build
|
|
44
|
+
run: uv build
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_run:
|
|
5
|
+
workflows: ["CI"]
|
|
6
|
+
types: [completed]
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: pypi-publish
|
|
11
|
+
cancel-in-progress: false
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
build:
|
|
15
|
+
if: >-
|
|
16
|
+
${{
|
|
17
|
+
github.event_name == 'workflow_dispatch' ||
|
|
18
|
+
(github.event.workflow_run.conclusion == 'success' &&
|
|
19
|
+
github.event.workflow_run.head_branch == 'master')
|
|
20
|
+
}}
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
steps:
|
|
23
|
+
- name: Checkout
|
|
24
|
+
uses: actions/checkout@v4
|
|
25
|
+
with:
|
|
26
|
+
ref: ${{ github.event.workflow_run.head_sha }}
|
|
27
|
+
fetch-depth: 0 # needed for hatch-vcs versioning
|
|
28
|
+
|
|
29
|
+
- name: Set up Python
|
|
30
|
+
uses: actions/setup-python@v5
|
|
31
|
+
with:
|
|
32
|
+
python-version: "3.12"
|
|
33
|
+
|
|
34
|
+
- name: Set up uv
|
|
35
|
+
uses: astral-sh/setup-uv@v5
|
|
36
|
+
with:
|
|
37
|
+
enable-cache: true
|
|
38
|
+
|
|
39
|
+
- name: Build dists
|
|
40
|
+
run: uv build
|
|
41
|
+
|
|
42
|
+
- name: Upload dists
|
|
43
|
+
uses: actions/upload-artifact@v4
|
|
44
|
+
with:
|
|
45
|
+
name: dist
|
|
46
|
+
path: dist/*
|
|
47
|
+
|
|
48
|
+
publish:
|
|
49
|
+
needs: build
|
|
50
|
+
runs-on: ubuntu-latest
|
|
51
|
+
permissions:
|
|
52
|
+
id-token: write
|
|
53
|
+
contents: read
|
|
54
|
+
attestations: write
|
|
55
|
+
steps:
|
|
56
|
+
- name: Checkout
|
|
57
|
+
uses: actions/checkout@v4
|
|
58
|
+
with:
|
|
59
|
+
ref: ${{ github.event.workflow_run.head_sha }}
|
|
60
|
+
fetch-depth: 0
|
|
61
|
+
|
|
62
|
+
- name: Download dists
|
|
63
|
+
uses: actions/download-artifact@v4
|
|
64
|
+
with:
|
|
65
|
+
name: dist
|
|
66
|
+
path: dist
|
|
67
|
+
|
|
68
|
+
- name: Publish to PyPI
|
|
69
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
70
|
+
with:
|
|
71
|
+
packages-dir: dist
|
|
72
|
+
attestations: "false"
|
|
73
|
+
skip-existing: "true"
|
py_jsync-0.2.31/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 vgrebenschikov
|
|
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.
|
py_jsync-0.2.31/PKG-INFO
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: py-jsync
|
|
3
|
+
Version: 0.2.31
|
|
4
|
+
Summary: Tool to run rsync utility in parallel
|
|
5
|
+
Author-email: Vladimir Grebenshchikov <vova@zote.me>
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: humanize<5,>=4.9
|
|
9
|
+
Requires-Dist: rich<15,>=14.0
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: ruff>=0.9.9; extra == 'dev'
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# JSync - Parallel Rsync Tool
|
|
15
|
+
|
|
16
|
+
The Parallel Rsync Tool is a powerful utility designed to significantly enhance the performance of synchronizing large file trees between remote hosts using the popular rsync tool. By harnessing parallel execution and leveraging multiple TCP streams, this tool offers substantial improvements in speed and efficiency compared to traditional rsync operations.
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
### Parallel Execution
|
|
21
|
+
|
|
22
|
+
The tool splits the file synchronization process into multiple parts and runs multiple rsync processes concurrently, maximizing resource utilization and reducing overall synchronization time.
|
|
23
|
+
|
|
24
|
+
### Optimized for Large File Trees
|
|
25
|
+
|
|
26
|
+
Whether dealing with massive file repositories or extensive directory structures, the tool efficiently handles synchronization tasks of any scale.
|
|
27
|
+
|
|
28
|
+
### Multiple TCP Streams
|
|
29
|
+
|
|
30
|
+
By utilizing multiple TCP streams for remote transfer, the tool maximizes network bandwidth usage over multipath networks, further enhancing synchronization speed and performance.
|
|
31
|
+
|
|
32
|
+
### Progress Reporting
|
|
33
|
+
|
|
34
|
+
Detailed progress reports provide real-time visibility into the synchronization process, allowing users to monitor the status of each file transfer and overall progress.
|
|
35
|
+
|
|
36
|
+
## How It Works
|
|
37
|
+
|
|
38
|
+
### FileList Calculation
|
|
39
|
+
|
|
40
|
+
The tool first calculates the list of files to be synchronized between the remote hosts, ensuring accuracy and completeness.
|
|
41
|
+
It does it running rsync in dry run (-n) mode and gathering output.
|
|
42
|
+
|
|
43
|
+
## Partitioning
|
|
44
|
+
|
|
45
|
+
The file list is partitioned into equal chunks, optimizing the workload distribution for parallel execution.
|
|
46
|
+
|
|
47
|
+
## Parallel Rsync Execution
|
|
48
|
+
|
|
49
|
+
Multiple rsync processes are initiated simultaneously, each tasked with synchronizing a specific partition of the file list.
|
|
50
|
+
Orchestration: The tool orchestrates the execution of rsync processes, ensuring proper synchronization sequence and resource management.
|
|
51
|
+
Progress Reporting: Throughout the synchronization process, detailed progress reports are generated and displayed, keeping users informed about the status of individual transfers and overall progress.
|
|
52
|
+
Getting Started
|
|
53
|
+
|
|
54
|
+
### Installation
|
|
55
|
+
|
|
56
|
+
Clone the repository, build and install package
|
|
57
|
+
|
|
58
|
+
```shell
|
|
59
|
+
git clone https://github.com/vgrebenschikov/fsync.git
|
|
60
|
+
$ cd fsync
|
|
61
|
+
$ uv venv
|
|
62
|
+
$ uv sync
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Install from PyPI:
|
|
66
|
+
|
|
67
|
+
```shell
|
|
68
|
+
$ uv pip install py-jsync
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
For development (linting, etc):
|
|
72
|
+
|
|
73
|
+
```shell
|
|
74
|
+
$ uv sync --extra dev
|
|
75
|
+
$ uv run ruff check .
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Alternative (without using `uv.lock`):
|
|
79
|
+
|
|
80
|
+
```shell
|
|
81
|
+
$ uv pip install -e ".[dev]"
|
|
82
|
+
$ uv run ruff check .
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Execute the tool
|
|
86
|
+
|
|
87
|
+
```shell
|
|
88
|
+
$ jsync --help
|
|
89
|
+
... to get help ...
|
|
90
|
+
|
|
91
|
+
$ jsync -j 8 <rsync-options>
|
|
92
|
+
... to execute rsync in 8 jobs parallel
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Monitor the progress using total progress-bar and rsync progress-bar to track the synchronization process in real-time.
|
|
96
|
+
|
|
97
|
+
## Contributions and Support
|
|
98
|
+
|
|
99
|
+
Contributions to the Parallel Rsync Tool are welcome!
|
|
100
|
+
Feel free to submit bug reports, feature requests, or pull requests via GitHub.
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
This project is licensed under the [MIT License](https://en.wikipedia.org/wiki/MIT_License).
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# JSync - Parallel Rsync Tool
|
|
2
|
+
|
|
3
|
+
The Parallel Rsync Tool is a powerful utility designed to significantly enhance the performance of synchronizing large file trees between remote hosts using the popular rsync tool. By harnessing parallel execution and leveraging multiple TCP streams, this tool offers substantial improvements in speed and efficiency compared to traditional rsync operations.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### Parallel Execution
|
|
8
|
+
|
|
9
|
+
The tool splits the file synchronization process into multiple parts and runs multiple rsync processes concurrently, maximizing resource utilization and reducing overall synchronization time.
|
|
10
|
+
|
|
11
|
+
### Optimized for Large File Trees
|
|
12
|
+
|
|
13
|
+
Whether dealing with massive file repositories or extensive directory structures, the tool efficiently handles synchronization tasks of any scale.
|
|
14
|
+
|
|
15
|
+
### Multiple TCP Streams
|
|
16
|
+
|
|
17
|
+
By utilizing multiple TCP streams for remote transfer, the tool maximizes network bandwidth usage over multipath networks, further enhancing synchronization speed and performance.
|
|
18
|
+
|
|
19
|
+
### Progress Reporting
|
|
20
|
+
|
|
21
|
+
Detailed progress reports provide real-time visibility into the synchronization process, allowing users to monitor the status of each file transfer and overall progress.
|
|
22
|
+
|
|
23
|
+
## How It Works
|
|
24
|
+
|
|
25
|
+
### FileList Calculation
|
|
26
|
+
|
|
27
|
+
The tool first calculates the list of files to be synchronized between the remote hosts, ensuring accuracy and completeness.
|
|
28
|
+
It does it running rsync in dry run (-n) mode and gathering output.
|
|
29
|
+
|
|
30
|
+
## Partitioning
|
|
31
|
+
|
|
32
|
+
The file list is partitioned into equal chunks, optimizing the workload distribution for parallel execution.
|
|
33
|
+
|
|
34
|
+
## Parallel Rsync Execution
|
|
35
|
+
|
|
36
|
+
Multiple rsync processes are initiated simultaneously, each tasked with synchronizing a specific partition of the file list.
|
|
37
|
+
Orchestration: The tool orchestrates the execution of rsync processes, ensuring proper synchronization sequence and resource management.
|
|
38
|
+
Progress Reporting: Throughout the synchronization process, detailed progress reports are generated and displayed, keeping users informed about the status of individual transfers and overall progress.
|
|
39
|
+
Getting Started
|
|
40
|
+
|
|
41
|
+
### Installation
|
|
42
|
+
|
|
43
|
+
Clone the repository, build and install package
|
|
44
|
+
|
|
45
|
+
```shell
|
|
46
|
+
git clone https://github.com/vgrebenschikov/fsync.git
|
|
47
|
+
$ cd fsync
|
|
48
|
+
$ uv venv
|
|
49
|
+
$ uv sync
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Install from PyPI:
|
|
53
|
+
|
|
54
|
+
```shell
|
|
55
|
+
$ uv pip install py-jsync
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
For development (linting, etc):
|
|
59
|
+
|
|
60
|
+
```shell
|
|
61
|
+
$ uv sync --extra dev
|
|
62
|
+
$ uv run ruff check .
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Alternative (without using `uv.lock`):
|
|
66
|
+
|
|
67
|
+
```shell
|
|
68
|
+
$ uv pip install -e ".[dev]"
|
|
69
|
+
$ uv run ruff check .
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Execute the tool
|
|
73
|
+
|
|
74
|
+
```shell
|
|
75
|
+
$ jsync --help
|
|
76
|
+
... to get help ...
|
|
77
|
+
|
|
78
|
+
$ jsync -j 8 <rsync-options>
|
|
79
|
+
... to execute rsync in 8 jobs parallel
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Monitor the progress using total progress-bar and rsync progress-bar to track the synchronization process in real-time.
|
|
83
|
+
|
|
84
|
+
## Contributions and Support
|
|
85
|
+
|
|
86
|
+
Contributions to the Parallel Rsync Tool are welcome!
|
|
87
|
+
Feel free to submit bug reports, feature requests, or pull requests via GitHub.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
This project is licensed under the [MIT License](https://en.wikipedia.org/wiki/MIT_License).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import importlib.metadata as importlib_metadata
|
|
2
|
+
|
|
3
|
+
from jsync.jsync import synchronize
|
|
4
|
+
from jsync.rsync import RSync
|
|
5
|
+
from jsync.syncer import Syncer
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _get_version() -> str:
|
|
9
|
+
# Distribution name can differ from import package name (e.g. "py-jsync" vs "jsync").
|
|
10
|
+
for dist in ("py-jsync", "jsync"):
|
|
11
|
+
try:
|
|
12
|
+
return importlib_metadata.version(dist)
|
|
13
|
+
except importlib_metadata.PackageNotFoundError:
|
|
14
|
+
continue
|
|
15
|
+
return "0.0.0"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
__version__ = _get_version()
|
|
19
|
+
|
|
20
|
+
__all__ = ["RSync", "Syncer", "synchronize"]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from rich.progress import (
|
|
2
|
+
Column,
|
|
3
|
+
Highlighter,
|
|
4
|
+
JustifyMethod,
|
|
5
|
+
ProgressColumn,
|
|
6
|
+
StyleType,
|
|
7
|
+
Task,
|
|
8
|
+
Text,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class FlexiColumn(ProgressColumn):
|
|
13
|
+
"""A column containing Download Rate"""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
func: callable,
|
|
18
|
+
style: StyleType = "none",
|
|
19
|
+
justify: JustifyMethod = "left",
|
|
20
|
+
markup: bool = True,
|
|
21
|
+
highlighter: Highlighter | None = None,
|
|
22
|
+
table_column: Column | None = None,
|
|
23
|
+
) -> None:
|
|
24
|
+
self.func = func
|
|
25
|
+
self.justify: JustifyMethod = justify
|
|
26
|
+
self.style = style
|
|
27
|
+
self.markup = markup
|
|
28
|
+
self.highlighter = highlighter
|
|
29
|
+
super().__init__()
|
|
30
|
+
|
|
31
|
+
def render(self, task: "Task") -> Text:
|
|
32
|
+
_text = self.func(task)
|
|
33
|
+
|
|
34
|
+
if self.markup:
|
|
35
|
+
text = Text.from_markup(_text, style=self.style, justify=self.justify)
|
|
36
|
+
else:
|
|
37
|
+
text = Text(_text, style=self.style, justify=self.justify)
|
|
38
|
+
|
|
39
|
+
if self.highlighter:
|
|
40
|
+
self.highlighter.highlight(text)
|
|
41
|
+
|
|
42
|
+
return text
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import random
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
from humanize import naturalsize
|
|
5
|
+
from rich.progress import Progress, TaskID
|
|
6
|
+
|
|
7
|
+
from .rsync import RSync
|
|
8
|
+
from .utils import dehumanize_rate, elapsed_time, parse_bytes_token
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Job:
|
|
12
|
+
id: int
|
|
13
|
+
files: list
|
|
14
|
+
progress: Progress
|
|
15
|
+
task: TaskID
|
|
16
|
+
color: int
|
|
17
|
+
running: bool
|
|
18
|
+
rsync: RSync
|
|
19
|
+
file: str
|
|
20
|
+
size: int
|
|
21
|
+
total: int
|
|
22
|
+
total_size: int
|
|
23
|
+
percent: float
|
|
24
|
+
rate: float
|
|
25
|
+
callback: callable
|
|
26
|
+
error_buf: str
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
id: int,
|
|
31
|
+
files: list,
|
|
32
|
+
progress: Progress,
|
|
33
|
+
rsync: RSync,
|
|
34
|
+
callback: callable,
|
|
35
|
+
total_size: int = 0,
|
|
36
|
+
) -> None:
|
|
37
|
+
self.id = id
|
|
38
|
+
self.files = files
|
|
39
|
+
self.progress = progress
|
|
40
|
+
self.rsync = rsync
|
|
41
|
+
self.running = False
|
|
42
|
+
self.color = random.randint(20, 230)
|
|
43
|
+
self.rate = 0
|
|
44
|
+
self.file = ''
|
|
45
|
+
self.percent = 0
|
|
46
|
+
self.size = 0
|
|
47
|
+
self.total = 0
|
|
48
|
+
self.total_size = total_size
|
|
49
|
+
self.callback = callback
|
|
50
|
+
self.error_buf = ''
|
|
51
|
+
self.task = progress.add_task(
|
|
52
|
+
f"rsync [bold yellow]#{id}",
|
|
53
|
+
rate=0,
|
|
54
|
+
filename='',
|
|
55
|
+
percent='',
|
|
56
|
+
eta='',
|
|
57
|
+
total=0,
|
|
58
|
+
style=f'[color({self.color})]',
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def start(self):
|
|
62
|
+
self.progress.start_task(self.task)
|
|
63
|
+
cmd = ' '.join(self.rsync.transfer_command())
|
|
64
|
+
num_files = len(self.files)
|
|
65
|
+
total_size_str = naturalsize(self.total_size, gnu=True)
|
|
66
|
+
self.progress.console.print(
|
|
67
|
+
f"[bright_cyan]Starting job #{self.id}:[/bright_cyan] {cmd} "
|
|
68
|
+
f"({total_size_str} in {num_files:,} files)",
|
|
69
|
+
highlight=False,
|
|
70
|
+
)
|
|
71
|
+
# Set an initial total immediately (from itemize), so progress UI does not stay 0B/0B
|
|
72
|
+
# until the first progress2 line arrives.
|
|
73
|
+
if self.total_size:
|
|
74
|
+
self.total = self.total_size
|
|
75
|
+
self.progress.update(
|
|
76
|
+
self.task,
|
|
77
|
+
total=self.total_size,
|
|
78
|
+
completed=0,
|
|
79
|
+
rate=0,
|
|
80
|
+
)
|
|
81
|
+
# Kick master progress to include this job's total right away.
|
|
82
|
+
self.callback(0, self)
|
|
83
|
+
self.running = True
|
|
84
|
+
|
|
85
|
+
def active(self):
|
|
86
|
+
return self.running
|
|
87
|
+
|
|
88
|
+
def process_progress(self, line):
|
|
89
|
+
# file transferred:
|
|
90
|
+
# folder1/folder2/IMG_7440.xmp
|
|
91
|
+
# progress reported:
|
|
92
|
+
# 123455332 0% 263.33MB/s 0:00:00 (xfr#2, to-chk=22854/22861)
|
|
93
|
+
# 123345 0% 4.73MB/s 1:05:31
|
|
94
|
+
# 4538368 100% 136.61kB/s 0:00:32 (xfr#554, to-chk=0/557)
|
|
95
|
+
percent = 0
|
|
96
|
+
delta = None
|
|
97
|
+
s = line.lstrip()
|
|
98
|
+
if s and s[0].isdigit() and '%' in line:
|
|
99
|
+
try:
|
|
100
|
+
ndone = ntotal = None
|
|
101
|
+
if m := re.search(r'\(xfr#(\d+), to-chk=(\d+)/(\d+)\)', line):
|
|
102
|
+
ndone = int(m.group(1))
|
|
103
|
+
ntotal = int(m.group(3))
|
|
104
|
+
|
|
105
|
+
parts = line.split()
|
|
106
|
+
if len(parts) < 4:
|
|
107
|
+
return
|
|
108
|
+
size, percent, rate, eta = parts[:4]
|
|
109
|
+
|
|
110
|
+
size = parse_bytes_token(size)
|
|
111
|
+
percent = int(percent.replace('%', ''))
|
|
112
|
+
self.rate = dehumanize_rate(rate)
|
|
113
|
+
except Exception:
|
|
114
|
+
# Don't crash the whole transfer due to an unexpected rsync progress format.
|
|
115
|
+
return
|
|
116
|
+
|
|
117
|
+
if percent < 10 and ntotal:
|
|
118
|
+
# within 10% - use number of files to estimate progress
|
|
119
|
+
size_percent = 100 * ndone / ntotal
|
|
120
|
+
else:
|
|
121
|
+
size_percent = percent
|
|
122
|
+
|
|
123
|
+
if size_percent > 0:
|
|
124
|
+
self.percent = percent
|
|
125
|
+
delta = size - self.size
|
|
126
|
+
else:
|
|
127
|
+
percent = total = 0
|
|
128
|
+
|
|
129
|
+
self.size = size
|
|
130
|
+
# Prefer byte-accurate total computed from itemize stage.
|
|
131
|
+
if self.total_size:
|
|
132
|
+
total = self.total_size
|
|
133
|
+
self.total = total
|
|
134
|
+
elif size_percent > 0:
|
|
135
|
+
total = int(size * 100 / size_percent)
|
|
136
|
+
else:
|
|
137
|
+
total = self.total
|
|
138
|
+
|
|
139
|
+
# print(
|
|
140
|
+
# f'({self.id}) {line} total={total} size={size} '
|
|
141
|
+
# f'percent={percent}%({size_percent:4.2f}%) '
|
|
142
|
+
# f'delta={delta} scan={ndone}/{ntotal}'
|
|
143
|
+
# )
|
|
144
|
+
|
|
145
|
+
self.progress.update(
|
|
146
|
+
self.task,
|
|
147
|
+
total=total,
|
|
148
|
+
completed=size,
|
|
149
|
+
rate=self.rate,
|
|
150
|
+
eta=elapsed_time(total, size, self.rate),
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
# Update progress on current file
|
|
154
|
+
self.callback(delta, self)
|
|
155
|
+
else:
|
|
156
|
+
self.file = line
|
|
157
|
+
self.progress.console.print(
|
|
158
|
+
f"[color({self.color})]{line}",
|
|
159
|
+
highlight=False,
|
|
160
|
+
)
|
|
161
|
+
self.progress.update(self.task, filename=self.file)
|
|
162
|
+
|
|
163
|
+
def process_error(self, err):
|
|
164
|
+
self.error_buf += err
|
|
165
|
+
|
|
166
|
+
errors = self.error_buf.split('\n')
|
|
167
|
+
self.error_buf = errors.pop() # last part - not finished line, keep it
|
|
168
|
+
|
|
169
|
+
for e in errors:
|
|
170
|
+
self.progress.console.print(f"[red][bold]{self.id}[/bold][/red] Error: {e}")
|
|
171
|
+
|
|
172
|
+
async def transfer(self):
|
|
173
|
+
if not self.files:
|
|
174
|
+
self.progress.console.print(
|
|
175
|
+
f"[bright_red]Job {self.id}: Nothing to do - no files",
|
|
176
|
+
highlight=False,
|
|
177
|
+
)
|
|
178
|
+
return
|
|
179
|
+
|
|
180
|
+
try:
|
|
181
|
+
await self.rsync.transfer(
|
|
182
|
+
self.files,
|
|
183
|
+
progress_callback=self.process_progress,
|
|
184
|
+
error_callback=self.process_error,
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
self.progress.update(self.task, filename='done', rate=None, eta='')
|
|
188
|
+
|
|
189
|
+
except Exception as e:
|
|
190
|
+
self.progress.update(
|
|
191
|
+
self.task,
|
|
192
|
+
filename=f'rsync error: {e}',
|
|
193
|
+
rate=None,
|
|
194
|
+
eta='-failed-',
|
|
195
|
+
)
|
|
196
|
+
raise
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import sys
|
|
3
|
+
import traceback
|
|
4
|
+
|
|
5
|
+
from .rsync import RSync
|
|
6
|
+
from .syncer import Syncer
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def usage(e=''):
|
|
10
|
+
print(
|
|
11
|
+
f"""{e}
|
|
12
|
+
|
|
13
|
+
USAGE:
|
|
14
|
+
|
|
15
|
+
--job=<num-jobs> -j<n> - Parallelize rsync run in number of jobs
|
|
16
|
+
--debug - Print raw rsync output lines as seen by jsync (or set JSYNC_DEBUG=1)
|
|
17
|
+
... rsync options ...
|
|
18
|
+
|
|
19
|
+
""",
|
|
20
|
+
file=sys.stderr,
|
|
21
|
+
)
|
|
22
|
+
sys.exit(1)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
async def main(argv):
|
|
26
|
+
jobs_num = 6
|
|
27
|
+
verbose = False
|
|
28
|
+
debug = False
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
cut = None
|
|
32
|
+
for i in range(len(argv)):
|
|
33
|
+
a = argv[i]
|
|
34
|
+
if a == '-j' or a == '--jobs':
|
|
35
|
+
jobs_num = int(argv[i + 1])
|
|
36
|
+
cut = (i, i + 2)
|
|
37
|
+
break
|
|
38
|
+
elif a.startswith('-j'):
|
|
39
|
+
jobs_num = int(argv[i][2:])
|
|
40
|
+
cut = (i, i + 1)
|
|
41
|
+
elif a.startswith('--jobs='):
|
|
42
|
+
jobs_num = int(argv[i][7:])
|
|
43
|
+
cut = (i, i + 1)
|
|
44
|
+
elif a == '--help' or a == '-h':
|
|
45
|
+
usage()
|
|
46
|
+
elif a == '--debug':
|
|
47
|
+
debug = True
|
|
48
|
+
cut = (i, i + 1)
|
|
49
|
+
break
|
|
50
|
+
|
|
51
|
+
if len(a) > 1 and a[0] == '-' and a[1] != '-' and 'v' in a:
|
|
52
|
+
verbose = True
|
|
53
|
+
|
|
54
|
+
if cut:
|
|
55
|
+
argv = argv[0 : cut[0]] + argv[cut[1] :]
|
|
56
|
+
|
|
57
|
+
if len(argv) < 2:
|
|
58
|
+
raise Exception("Not enough rsync options provided")
|
|
59
|
+
|
|
60
|
+
except Exception as e:
|
|
61
|
+
usage(e)
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
with Syncer(jobs_num, RSync(*argv, debug=debug)) as s:
|
|
65
|
+
await s.itemize()
|
|
66
|
+
await s.transfer()
|
|
67
|
+
|
|
68
|
+
except Exception as e:
|
|
69
|
+
print(f'Error: {e}', file=sys.stderr)
|
|
70
|
+
if verbose:
|
|
71
|
+
print(*traceback.format_exception(e), file=sys.stderr)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def synchronize(*argv):
|
|
75
|
+
try:
|
|
76
|
+
asyncio.run(main(argv or sys.argv[1:]))
|
|
77
|
+
except KeyboardInterrupt:
|
|
78
|
+
print("Interrupted", file=sys.stderr)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
if __name__ == '__main__':
|
|
82
|
+
synchronize()
|