summaryrefslogtreecommitdiff
path: root/src/backend/checkenv.py
blob: 4f540e9445468c23d20db90df40519286a2308e2 (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
#!/usr/bin/python3

import os
import subprocess
import sisyphus.getenv
import sisyphus.getnews
import urllib.request


def connectivity():
    is_online = int()

    try:
        urllib.request.urlopen("http://www.google.com", timeout=5)
        is_online = int(1)
    except urllib.error.URLError:
        is_online = int(0)

    return is_online


def root():
    return True if os.getuid() == 0 else False


def news():
    n_news = sisyphus.getnews.ld_n_news()
    r_news_index = sisyphus.getnews.ld_r_news()

    unread_count = len(n_news) - len(r_news_index)

    return unread_count


def sanity():
    actv_brch = sisyphus.getenv.sys_brch()
    bhst_addr = sisyphus.getenv.bhst_addr()
    is_sane = int()

    if "packages-next" in bhst_addr:
        if actv_brch == "next":
            is_sane = int(1)
        else:
            is_sane = int(0)
    else:
        if actv_brch == "master":
            is_sane = int(1)
        else:
            is_sane = int(0)

    return is_sane