root/trunk/src/util/aptutil.py @ 43

Revision 43, 7.6 KB (checked in by pcabido, 5 years ago)
  • Property svn:executable set to *
Line 
1# -*- coding: utf-8 -*-
2import apt_inst
3import apt_pkg
4from progress import TextProgress
5
6#ver mais tarde
7apt_pkg.init()
8
9#le a cache e ve quais os pacotes que estão instalados
10def readAptInstalled():
11    progress = TextProgress()
12    cache = apt_pkg.GetCache(progress)
13    packages = cache.Packages
14   
15    systemDepends= ""
16    for package in packages:
17            if  package.CurrentVer != None:
18                    systemDepends += package.Name + ", "
19   
20    if len(systemDepends) > 2:
21        return systemDepends[:-2]
22    else:
23        return ""
24
25#obtem todos os pacotes disponiveis
26def getCachePackages(ignore=True):
27    progress = TextProgress()
28    cache = apt_pkg.GetCache(progress)
29    records = apt_pkg.GetPkgRecords(cache)
30    packages = cache.Packages
31       
32    pkgList = []
33   
34    for pkg in packages:
35        for pkgInfo in pkg.VersionList:
36            for packFile, index in pkgInfo.FileList:
37                records.Lookup((packFile,index))
38                if packFile.IndexType != 'Debian Package Index' and ignore:
39                    continue
40                pkgList.append([None, pkg.Name, pkgInfo.VerStr, records.ShortDesc])
41   
42    pkgList.sort()
43    return pkgList
44
45#o apt_pkg.ParseDepends devolve uma lista, de listas, com tuplos
46#ex:  [[('dep1', '', '')], [('dep2', '', '')], [('dep3', '', '')]]
47def stripDepends(depList):
48    depResult = ""
49    for L in depList:
50        for tuplo in L:
51                if tuplo[0] != "" and tuplo[1] == "":
52                    depResult += tuplo[0] + ", "
53                elif tuplo[0] != "" and tuplo[1] != "":
54                    depResult += tuplo[0] + " (" + tuplo[2] + " " + tuplo[1] + "), "
55   
56    if len(depResult) > 2:
57        return depResult[:-2]
58    else:
59        return ""
60
61#define a descrição para o control file
62def setDescription(SDesc, LDesc):
63    Desc = SDesc + "\n .\n"
64    tmpLDesc = LDesc.split("\n")
65    for e in tmpLDesc:
66        if e == "":
67            Desc += " .\n"
68        else:
69            Desc += " " + e + "\n"
70   
71    return Desc
72
73def getDependsFromDic(Dic):
74    depends = ""
75    for key, value in Dic.items():
76        depends += key + ", "
77       
78    if len(depends) > 2:
79        return depends[:-2]
80    else:
81        return ""
82
83def getShortDesc(desc):
84    if desc:
85        try:
86            tmpDesc = desc.split("\n")
87            if "Description: " in tmpDesc[0]:
88                finalDesc = tmpDesc[0].split("Description: ")
89            else:
90                return tmpDesc[0]
91            return finalDesc[1]
92        except:
93            return ""
94    else:
95        return ""
96   
97def getLongDesc(desc):
98    final = ""
99    if desc:
100        try:
101            tmpDesc = desc.split("\n")
102            if len(tmpDesc) > 1:
103                for i in range(len(tmpDesc) - 1):
104                    final += tmpDesc[i+1] + "\n"
105            return final
106        except:
107            pass
108    else:
109        return ""
110
111def shortDescFromDic(list, pkg, ver):
112    for dic in list:
113        if dic['Package'] == pkg and dic['Version'] == ver:
114            return dic['ShortDesc']
115       
116    return ""
117
118def longDescFromDic(list, pkg, ver):
119    for dic in list:
120        if dic['Package'] == pkg and dic['Version'] == ver:
121            return dic['LongDesc']
122   
123    return ""
124
125def getSectionPackages(section, list):
126    Packages = []
127    for dic in list:
128        if getSection(dic['Section']) == section:
129            Packages.append(dic)
130    return Packages
131
132def setSection(section):
133    if section == "Administration Utilities":
134        return "admin"
135    elif section == "Base Utilities":
136        return "base"
137    elif section == "Communication Programs":
138        return "comm"
139    elif section == "debian-installer udeb packages":
140        return "debian-installer"
141    elif section == "Development":
142        return "devel"
143    elif section == "Documentation":
144        return "doc"
145    elif section == "Editors":
146        return "editors"
147    elif section == "Electronics":
148        return "electronics"
149    elif section == "Embedded software":
150        return "embedded"
151    elif section == "Games":
152        return "games"
153    elif section == "Gnome":
154        return "gnome"
155    elif section == "Graphics":
156        return "graphics"
157    elif section == "Ham Radio":
158        return "hamradion"
159    elif section == "Interpreters":
160        return "interpreters"
161    elif section == "KDE":
162        return "kde"
163    elif section == "Library development":
164        return "libdevel"
165    elif section == "Libraries":
166        return "libs"
167    elif section == "Mail":
168        return "mail"
169    elif section == "Mathematics":
170        return "math"
171    elif section == "Miscellaneous":
172        return "misc"
173    elif section == "Network":
174        return "net"
175    elif section == "Newsgroups":
176        return "news"
177    elif section == "Old Libraries":
178        return "oldlibs"
179    elif section == "Other OS's and file systems":
180        return "otherosfs"
181    elif section == "Perl":
182        return "perl"
183    elif section == "Python":
184        return "python"
185    elif section == "Science":
186        return "science"
187    elif section == "Shells":
188        return "shells"
189    elif section == "Sound":
190        return "sound"
191    elif section == "TeX":
192        return "tex"
193    elif section == "Text Processing":
194        return "text"
195    elif section == "Utilities":
196        return "utils"
197    elif section == "Virtual packages":
198        return "virtual"
199    elif section == "Web Software":
200        return "web"
201    elif section == "X Window System software":
202        return "x11"
203    elif section == "All packages":
204        return "all"
205   
206    return ""
207
208def getSection(section):
209    if section == "admin":
210        return "Administration Utilities"
211    elif section == "base":
212        return "Base Utilities"
213    elif section == "comm":
214        return "Communication Programs"
215    elif section == "debian-installer":
216        return "debian-installer udeb packages"
217    elif section == "devel":
218        return "Development"
219    elif section == "doc":
220        return "Documentation"
221    elif section == "editors":
222        return "Editors"
223    elif section == "electronics":
224        return "Electronics"
225    elif section == "embedded":
226        return "Embedded software"
227    elif section == "games":
228        return "Games"
229    elif section == "gnome":
230        return "Gnome"
231    elif section == "graphics":
232        return "Graphics"
233    elif section == "hamradion":
234        return "Ham Radio"
235    elif section == "interpreters":
236        return "Interpreters"
237    elif section == "kde":
238        return "KDE"
239    elif section == "libdevel":
240        return "Library development"
241    elif section == "libs":
242        return "Libraries"
243    elif section == "mail":
244        return "Mail"
245    elif section == "math":
246        return "Mathematics"
247    elif section == "misc":
248        return "Miscellaneous"
249    elif section == "net":
250        return "Network"
251    elif section == "news":
252        return "Newsgroups"
253    elif section == "oldlibs":
254        return "Old Libraries"
255    elif section == "otherosfs":
256        return "Other OS's and file systems"
257    elif section == "perl":
258        return "Perl"
259    elif section == "python":
260        return "Python"
261    elif section == "science":
262        return "Science"
263    elif section == "shells":
264        return "Shells"
265    elif section == "sound":
266        return "Sound"
267    elif section == "tex":
268        return "TeX"
269    elif section == "text":
270        return "Text Processing"
271    elif section == "utils":
272        return "Utilities"
273    elif section == "virtual":
274        return "Virtual packages"
275    elif section == "web":
276        return "Web Software"
277    elif section == "x11":
278        return "X Window System software"
279    elif section == "all":
280        return "All packages"
281   
282    return ""
Note: See TracBrowser for help on using the browser.