File: PackageList.py

package info (click to toggle)
playonlinux 4.3.4-5
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 8,252 kB
  • sloc: sh: 5,390; python: 5,150; ansic: 72; makefile: 57; xml: 47
file content (61 lines) | stat: -rw-r--r-- 1,948 bytes parent folder | download | duplicates (3)
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
from lib import Variables


class PackageList:
    def __init__(self):
        self.available_packages = []
        self.loadList()

    def loadList(self):
        try:
            self.available_packages = open(Variables.playonlinux_rep + "/configurations/listes/POL_Functions",
                                           "r").read()
        except IOError as e:  # File does not exits  it will be created when pol is updated
            pass

    def getList(self):
        return self.available_packages

    def getCutList(self):
        clist = self.available_packages.split("\n")
        flist = []
        for key in clist:
            if ("POL_Install" in key):
                flist.append(key)
        return flist

    def getParsedList(self):
        clist = self.getCutList()
        flist = []
        for key in clist:
            flist.append(PackageList.getNameFromPackageLine(key))
        return flist

    def getNameFromId(self, id):
        return self.getParsedList()[id]

    def getPackageFromName(self, selectedPackage):
        broken = False
        for key in self.getCutList():
            key_split = key.split(":")
            try:
                if (key_split[1] == selectedPackage):  # We found it
                    selectedPackage = key_split[0]
                    broken = True
                    break

            except IndexError as e:  # Index error : There is no ':' in the line, so the content of the line is the package we want to install. No need to continue
                broken = True
                break

        if (broken == False):
            selectedPackage = "POL_Install_" + selectedPackage
        return selectedPackage

    @staticmethod
    def getNameFromPackageLine(package):
        try:
            realName = package.split(":")[1].replace("POL_Install_", "")
        except IndexError as e:
            realName = package.replace("POL_Install_", "")
        return realName