summaryrefslogtreecommitdiff
path: root/src/backend/getenv.py
blob: 108a90c71f0e5d1e4cd0763f52dab622514acb3e (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
64
65
66
67
68
69
70
71
#!/usr/bin/python3

import io
import os
import signal
import subprocess
import sisyphus.getfs


def sigint_handler(signal, frame):
    sys.exit(0)


signal.signal(signal.SIGINT, sigint_handler)


def bhst_addr():
    bhst_addr = []
    p_exe = subprocess.Popen(
        ['emerge', '--info', '--verbose'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    for p_out in io.TextIOWrapper(p_exe.stdout, encoding="utf-8"):
        if "PORTAGE_BINHOST" in p_out:
            bhst_addr = p_out.rstrip().split("=")[1].strip('\"')
    try:
        p_exe.wait()
    except KeyboardInterrupt:
        p_exe.terminate()
        try:
            p_exe.wait(1)
        except subprocess.TimeoutExpired:
            p_exe.kill()
        sys.exit()

    return bhst_addr


def csv_addr():
    csv_addr = bhst_addr()
    pcsv_addr = []
    dcsv_addr = []

    if "packages-next" in csv_addr:
        pcsv_addr = csv_addr.replace(
            'packages-next', 'csv-next') + 'remotePackagesPre.csv'
        dcsv_addr = csv_addr.replace(
            'packages-next', 'csv-next') + 'remoteDescriptionsPre.csv'
    else:
        pcsv_addr = csv_addr.replace(
            'packages', 'csv') + 'remotePackagesPre.csv'
        dcsv_addr = csv_addr.replace(
            'packages', 'csv') + 'remoteDescriptionsPre.csv'

    return pcsv_addr, dcsv_addr


def sys_brch():
    actv_brch = None

    if os.path.isdir(os.path.join(sisyphus.getfs.g_src_dir, '.git')):
        os.chdir(sisyphus.getfs.g_src_dir)
        lcl_brch = subprocess.check_output(
            ['git', 'rev-parse', '--abbrev-ref', 'HEAD'])

        if lcl_brch.decode().strip() == 'master':
            actv_brch = str('master')

        if lcl_brch.decode().strip() == 'next':
            actv_brch = str('next')

    return actv_brch