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

import os
import pickle
import shutil
import wget
import sisyphus.getcolor
import sisyphus.getenv
import sisyphus.getfs


def pkg(pkgname):
    binhostURL = sisyphus.getenv.binhostURL()
    areBinaries, areSources, needsConfig = pickle.load(open(os.path.join(
        sisyphus.getfs.portageMetadataDir, "sisyphus_pkgdeps.pickle"), "rb"))

    for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1):
        print(">>> Downloading binary" + "(" + sisyphus.getcolor.bright_yellow + "{}".format(index) + sisyphus.getcolor.reset + " " + "of" + " " + sisyphus.getcolor.bright_yellow +
              str(len(areBinaries)) + sisyphus.getcolor.reset + ")" + " " + sisyphus.getcolor.magenta + binary.replace('.tbz2', ' ') + sisyphus.getcolor.reset)
        wget.download(binhostURL + binary)
        print("")

        if os.path.isdir(os.path.join(sisyphus.getfs.portageCacheDir, binary.rstrip().split("/")[0])):
            shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(
                sisyphus.getfs.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1])))
        else:
            os.makedirs(os.path.join(sisyphus.getfs.portageCacheDir,
                        binary.rstrip().split("/")[0]))
            shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(
                sisyphus.getfs.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1])))

        if os.path.exists(binary.rstrip().split("/")[1]):
            os.remove(binary.rstrip().split("/")[1])


def world():
    binhostURL = sisyphus.getenv.binhostURL()
    areBinaries, areSources, needsConfig = pickle.load(open(os.path.join(
        sisyphus.getfs.portageMetadataDir, "sisyphus_worlddeps.pickle"), "rb"))

    for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1):
        print(">>> Downloading binary" + "(" + sisyphus.getcolor.bright_yellow + "{}".format(index) + sisyphus.getcolor.reset + " " + "of" + " " + sisyphus.getcolor.bright_yellow +
              str(len(areBinaries)) + sisyphus.getcolor.reset + ")" + " " + sisyphus.getcolor.magenta + binary.replace('.tbz2', ' ') + sisyphus.getcolor.reset)
        wget.download(binhostURL + binary)
        print("")

        if os.path.isdir(os.path.join(sisyphus.getfs.portageCacheDir, binary.rstrip().split("/")[0])):
            shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(
                sisyphus.getfs.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1])))
        else:
            os.makedirs(os.path.join(sisyphus.getfs.portageCacheDir,
                        binary.rstrip().split("/")[0]))
            shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(
                sisyphus.getfs.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1])))

        if os.path.exists(binary.rstrip().split("/")[1]):
            os.remove(binary.rstrip().split("/")[1])