diff options
author | Kali Kaneko <kali@leap.se> | 2018-01-02 17:09:02 +0100 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2018-01-06 19:57:36 +0100 |
commit | eb431c28a9e7df0cc8c2a701b9d0f053739dcbb4 (patch) | |
tree | 6df42e361ed0a5227115bc35c5b223d7419aafb8 /src/leap/bitmask/gui/housekeeping.py | |
parent | 1184768281a00aece92591b37fb7d89f198bdfca (diff) |
[refactor] factor out common functions
used from both entrypoints for linux and mac apps.
Diffstat (limited to 'src/leap/bitmask/gui/housekeeping.py')
-rw-r--r-- | src/leap/bitmask/gui/housekeeping.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/leap/bitmask/gui/housekeeping.py b/src/leap/bitmask/gui/housekeeping.py new file mode 100644 index 00000000..3202f5e6 --- /dev/null +++ b/src/leap/bitmask/gui/housekeeping.py @@ -0,0 +1,44 @@ +import os + +from leap.common.config import get_path_prefix + +def get_authenticated_url(): + url = "http://localhost:7070" + path = os.path.join(get_path_prefix(), 'leap', 'authtoken') + waiting = 20 + while not os.path.isfile(path): + if waiting == 0: + # If we arrive here, something really messed up happened, + # because touching the token file is one of the first + # things the backend does, and this BrowserWindow + # should be called *right after* launching the backend. + raise NoAuthToken( + 'No authentication token found!') + time.sleep(0.1) + waiting -= 1 + token = open(path).read().strip() + url += '#' + token + return url + +def terminate(pid): + if os.path.isfile(pid): + with open(pid) as f: + pidno = int(f.read()) + print('[bitmask] terminating bitmaskd...') + os.kill(pidno, signal.SIGTERM) + +def reset_authtoken(): + prev_auth = os.path.join(get_path_prefix(), 'leap', 'authtoken') + try: + os.remove(prev_auth) + except OSError: + pass + +def cleanup(): + print('[bitmask] cleaning up files') + base = os.path.join(get_path_prefix(), 'leap') + token = os.path.join(base, 'authtoken') + pid = os.path.join(base, 'bitmaskd.pid') + for _f in [token, pid]: + if os.path.isfile(_f): + os.unlink(_f) |