blob: 7b2ff7c63e8bb5b52adb02d3cf2db0a2c3e26fb9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import functools
import os
from pathlib import Path
from .download import Download
from .extract import Extract
from .remove import Remove
from .runnermulti import MultiSequencialRunnerBase
class Install(MultiSequencialRunnerBase):
def __init__(self, source, dest):
tmpdest = Path(dest) / 'archive.rsynctmp'
runners = [
functools.partial(Download, source, tmpdest),
functools.partial(Extract, tmpdest, dest),
functools.partial(Remove, tmpdest),
]
super().__init__(runners)
if __name__ == '__main__':
import contextlib
import selectors
import sys
import time
print('main test')
with contextlib.ExitStack() as stack:
stack.enter_context(contextlib.suppress(KeyboardInterrupt))
runner = stack.enter_context(Install(sys.argv[1], sys.argv[2]))
selector = stack.enter_context(selectors.DefaultSelector())
selector.register(runner.get_read_fd(), selectors.EVENT_READ)
last_progress = None
while (rc := runner.poll()) is None:
if selector.select():
progress = runner.progress_read()
if progress != last_progress:
print(progress)
last_progress = progress
print('ended with code:', rc)
print('test main ended')
|