summaryrefslogtreecommitdiffstats
path: root/gamechestcli/gamechest/runners/install.py
blob: 36b01538f4f15851eb7740173f82e98174da0f39 (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 .download import Download
from .extract import Extract
from .remove import Remove
from .runnermulti import MultiSequencialRunnerBase


class Install(MultiSequencialRunnerBase):

    def __init__(self, source, dest):
        filename = os.path.split(source)[1]
        tmpdest = os.path.join(dest, f'{filename}.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')