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

import animation
import sys
import time
import sisyphus.cache
import sisyphus.binhost
import sisyphus.check
import sisyphus.database
import sisyphus.metadata
import sisyphus.sync

def syncAll():
    sisyphus.sync.portage()
    sisyphus.sync.overlay()
    sisyphus.sync.portageCfg()
    sisyphus.database.syncRemote()
    sisyphus.metadata.regenSilent()

def syncCfg():
    sisyphus.sync.portageCfg()

def doSync():
    sisyphus.cache.clean()

    needsPortage = sisyphus.check.portage()
    needsOverlay = sisyphus.check.overlay()

    if needsPortage == 1:
        if needsOverlay == 1:
            syncAll()
        elif not needsOverlay == 1:
            syncAll()
    elif not needsPortage == 1:
        if needsOverlay == 1:
            syncAll()
        elif not needsOverlay == 1:
            syncCfg()

@animation.wait('fetching updates')
def start():
    isBinhost = sisyphus.binhost.start()
    needsMatch,localBranch = sisyphus.check.match()

    if needsMatch == 0:
        doSync()
    else:
        if "packages-next" in isBinhost:
            print("\nCurrent branch: '" + localBranch.decode().strip()  + "' (stable)" + "\nCurrent binhost: '" + isBinhost + "' (testing)")
        else:
            print("\nCurrent branch: '" + localBranch.decode().strip()  + "' (testing)" + "\nCurrent binhost: '" + isBinhost + "' (stable)")
        sys.exit("\nInvalid branch - binhost pairing; Use 'sisyphus branch --help' for help; Quitting.")

def startqt():
    isBinhost = sisyphus.binhost.start()
    needsMatch,localBranch = sisyphus.check.match()

    if needsMatch == 0:
        doSync()
    else:
        if "packages-next" in isBinhost:
            print("\nCurrent branch: '" + localBranch.decode().strip()  + "' (stable)" + "\nCurrent binhost: '" + isBinhost + "' (testing)")
        else:
            print("\nCurrent branch: '" + localBranch.decode().strip()  + "' (testing)" + "\nCurrent binhost: '" + isBinhost + "' (stable)")
        print("\nInvalid branch - binhost pairing; Use 'sisyphus branch --help' for help; Quitting in 10 seconds.\n")
        t = int(10)
        while t:
            mins, secs = divmod(t, 60)
            timer = '{:02d}:{:02d}'.format(mins, secs)
            print(timer, end="\r")
            time.sleep(1)
            t -= 1

        sys.exit()