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

import animation
import git
import os
import sys
import sisyphus.checkEnvironment
import sisyphus.getFilesystem
import sisyphus.purgeEnvironment
import sisyphus.setJobs
import sisyphus.setProfile

def getBranchRemote(branch,remote):
    portageRemote = []
    redcoreRemote = []
    portageConfigRemote = []
    if "master" in branch:
        if "gitlab" in remote:
            remote = sisyphus.getFilesystem.remoteGitlab
        elif "pagure" in remote:
            remote = sisyphus.getFilesystem.remotePagure
        else:
            sys.exit("Usage: sisyphus-cli.py branch [OPTIONS] BRANCH" + "\n" +
                    "Try 'sisyphus-cli.py branch --help' for help." + "\n\n" +
                    "Error: Invalid remote" + " " + "'" + str(remote) + "'" + " " +  "(options : gitlab, pagure)"
                    )
    elif "next" in branch:
        if "gitlab" in remote:
            remote = sisyphus.getFilesystem.remoteGitlab
        elif "pagure" in remote:
            remote = sisyphus.getFilesystem.remotePagure
        else:
            sys.exit("Usage: sisyphus-cli.py branch [OPTIONS] BRANCH" + "\n" +
                    "Try 'sisyphus-cli.py branch --help' for help." + "\n\n" +
                    "Error: Invalid remote" + " " + "'" + str(remote) + "'" + " " +  "(options : gitlab, pagure)"
                    )
    else:
        sys.exit("Usage: sisyphus-cli.py branch [OPTIONS] BRANCH" + "\n" +
                "Try 'sisyphus-cli.py branch --help' for help." + "\n\n" +
                "Error: Invalid branch" + " " + "'" + str(branch) + "'" +" " +  "(options : master, next)"
                )

    portageRemote = [remote, sisyphus.getFilesystem.portageRepo]
    redcoreRemote = [remote, sisyphus.getFilesystem.redcoreRepo]
    portageConfigRemote = [remote, sisyphus.getFilesystem.portageConfigRepo]

    return portageRemote,redcoreRemote,portageConfigRemote

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

    if not os.path.isdir(os.path.join(sisyphus.getFilesystem.portageRepoDir, '.git')):
        git.Repo.clone_from("/".join(portageRemote), sisyphus.getFilesystem.portageRepoDir, depth=1, branch=branch)

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

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

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

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

def giveWarning(branch,remote):
    if "master" in branch:
        print("\nThe switch to branch" + " " + "'" + branch + "'" +  " " + "from remote" + " " + "'" + remote + "'" + " " + "is now complete")
        print("You must pair this branch with the stable binhost (binary repository)")
        print("Hint : Use the odd numbers (1,3,5,7) from 'sisyphus mirror list'")
        print("Examples : 'sisyphus mirror set 1' or 'sisyphus mirror set 5'\n")
    elif "next" in branch:
        print("\nThe switch to branch" + " " + "'" + branch + "'" +  " " + "from remote" + " " + "'" + remote + "'" + " " + "is now complete")
        print("You must pair this branch with the testing binhost (binary repository)")
        print("Hint : Use the even numbers (2,4,6,8) from 'sisyphus mirror list'")
        print("Examples : 'sisyphus mirror set 4' or 'sisyphus mirror set 8'\n")


def start(branch,remote):
    if sisyphus.checkEnvironment.root():
        sisyphus.purgeEnvironment.branch()
        sisyphus.purgeEnvironment.metadata()
        injectStage1(branch,remote)
        injectStage2(branch,remote)
        injectStage3(branch,remote)
        sisyphus.setJobs.start()
        sisyphus.setProfile.start()
        giveWarning(branch,remote)
    else:
        sys.exit("\nYou need root permissions to do this, exiting!\n")