summaryrefslogtreecommitdiff
path: root/src/backend/setbranch.py
blob: 0527ad4ee1b222ecdff234049cd41df5b9b16f04 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/python3

import animation
import git
import os
import sys
import sisyphus.checkenv
import sisyphus.getcolor
import sisyphus.getfs
import sisyphus.purgeenv
import sisyphus.setjobs
import sisyphus.setprofile


def getBranchRemote(branch, remote):
    gentooRemote = []
    redcoreRemote = []
    portageConfigRemote = []
    if "master" in branch:
        if "gitlab" in remote:
            remote = sisyphus.getfs.remoteGitlab
        elif "pagure" in remote:
            remote = sisyphus.getfs.remotePagure
    elif "next" in branch:
        if "gitlab" in remote:
            remote = sisyphus.getfs.remoteGitlab
        elif "pagure" in remote:
            remote = sisyphus.getfs.remotePagure

    gentooRemote = [remote, sisyphus.getfs.gentooRepo]
    redcoreRemote = [remote, sisyphus.getfs.redcoreRepo]
    portageConfigRemote = [remote, sisyphus.getfs.portageConfigRepo]

    return gentooRemote, redcoreRemote, portageConfigRemote


@animation.wait('injecting Gentoo Linux portage tree')
def injectGentooRepo(branch, remote):
    gentooRemote, redcoreRemote, portageConfigRemote = getBranchRemote(
        branch, remote)

    if not os.path.isdir(os.path.join(sisyphus.getfs.gentooRepoDir, '.git')):
        git.Repo.clone_from("/".join(gentooRemote),
                            sisyphus.getfs.gentooRepoDir, depth=1, branch=branch)


@animation.wait('injecting Redcore Linux ebuild overlay')
def injectRedcoreRepo(branch, remote):
    gentooRemote, redcoreRemote, portageConfigRemote = getBranchRemote(
        branch, remote)

    if not os.path.isdir(os.path.join(sisyphus.getfs.redcoreRepoDir, '.git')):
        git.Repo.clone_from("/".join(redcoreRemote),
                            sisyphus.getfs.redcoreRepoDir, depth=1, branch=branch)


@animation.wait('injecting Redcore Linux portage config')
def injectPortageConfigRepo(branch, remote):
    gentooRemote, redcoreRemote, portageConfigRemote = getBranchRemote(
        branch, remote)

    if not os.path.isdir(os.path.join(sisyphus.getfs.portageConfigDir, '.git')):
        git.Repo.clone_from("/".join(portageConfigRemote),
                            sisyphus.getfs.portageConfigDir, depth=1, branch=branch)


def giveWarning(branch, remote):
    if "master" in branch:
        print(sisyphus.getcolor.green + "\nActive branch switched:" +
              " " + sisyphus.getcolor.reset + "'" + branch + "'")
        print(sisyphus.getcolor.green + "Active remote switched:" +
              " " + sisyphus.getcolor.reset + "'" + remote + "'")
        print(sisyphus.getcolor.bright_yellow + "\nUse" + sisyphus.getcolor.reset + " " + "'" + "sisyphus mirror set 3" + "'" + " " + sisyphus.getcolor.bright_yellow + "or" +
              sisyphus.getcolor.reset + " " + "'" + "sisyphus mirror set 7" + "'" + " " + sisyphus.getcolor.bright_yellow + "to pair the binhost" + sisyphus.getcolor.reset)
        print(sisyphus.getcolor.bright_yellow +
              "Use" + sisyphus.getcolor.reset + " " + "'" + "sisyphus branch --help" + "'" + " " + sisyphus.getcolor.bright_yellow + "for help" + sisyphus.getcolor.reset)
    elif "next" in branch:
        print(sisyphus.getcolor.green + "\nActive branch switched:" +
              " " + sisyphus.getcolor.reset + "'" + branch + "'")
        print(sisyphus.getcolor.green + "Active remote switched:" +
              " " + sisyphus.getcolor.reset + "'" + remote + "'")
        print(sisyphus.getcolor.bright_yellow + "\nUse" + sisyphus.getcolor.reset + " " + "'" + "sisyphus mirror set 4" + "'" + " " + sisyphus.getcolor.bright_yellow + "or" +
              sisyphus.getcolor.reset + " " + "'" + "sisyphus mirror set 8" + "'" + " " + sisyphus.getcolor.bright_yellow + "to pair the binhost" + sisyphus.getcolor.reset)
        print(sisyphus.getcolor.bright_yellow +
              "Use" + sisyphus.getcolor.reset + " " + "'" + "sisyphus branch --help" + "'" + " " + sisyphus.getcolor.bright_yellow + "for help" + sisyphus.getcolor.reset)


def start(branch, remote):
    if sisyphus.checkenv.root():
        sisyphus.purgeenv.branch()
        sisyphus.purgeenv.metadata()
        injectGentooRepo(branch, remote)
        injectRedcoreRepo(branch, remote)
        injectPortageConfigRepo(branch, remote)
        sisyphus.setjobs.start()
        sisyphus.setprofile.start()
        giveWarning(branch, remote)
    else:
        print(sisyphus.getcolor.bright_red +
              "\nYou need root permissions to do this!\n" + sisyphus.getcolor.reset)
        sys.exit()