summaryrefslogtreecommitdiff
path: root/client/helper.py
blob: 2c90a52affee1b3a1dff4c7b290c676d07d37591 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'''
    General helper functions to improve order
    & flow of the client program.

    Verified: 2020 December 30 & 2021 February 6
    * Follows PEP8
    * Tested Platforms
        * Windows 10
'''

from client.state import ClientStatic
from shared.helper import Helper
from shared.state import Static

import sys

if Static.EXE:
    if Static.WINDOWS:
        from client.autostart import (AutoShell,
                                      AutoRegistry,
                                      AutoSchedule)

    from shared.error import Error

    import os


class ClientHelper:

    @staticmethod
    def secure(callback):
        try:
            result = callback()
            assert type(result) is str
            return result
        except Exception:
            return ClientStatic.DEFAULT

    @staticmethod
    def plural_int(number):
        if number == 1:
            return ''
        else:
            return 's'

    @staticmethod
    def restart():
        try:
            sys.exit()
        finally:
            Helper.start(Static.ROOT)

    @staticmethod
    def uninstall():
        if Static.EXE:
            if Static.WINDOWS:
                AutoShell.uninstall()
                Error.quiet(AutoRegistry.uninstall)()
                Error.quiet(AutoSchedule.uninstall)()

            Error.quiet(os.remove)(Static.ROOT)

        sys.exit()