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

Revision 39, 7.4 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 setSection(section):
126    if section == "Administration Utilities":
127        return "admin"
128    elif section == "Base Utilities":
129        return "base"
130    elif section == "Communication Programs":
131        return "comm"
132    elif section == "debian-installer udeb packages":
133        return "debian-installer"
134    elif section == "Development":
135        return "devel"
136    elif section == "Documentation":
137        return "doc"
138    elif section == "Editors":
139        return "editors"
140    elif section == "Electronics":
141        return "electronics"
142    elif section == "Embedded software":
143        return "embedded"
144    elif section == "Games":
145        return "games"
146    elif section == "Gnome":
147        return "gnome"
148    elif section == "Graphics":
149        return "graphics"
150    elif section == "Ham Radio":
151        return "hamradion"
152    elif section == "Interpreters":
153        return "interpreters"
154    elif section == "KDE":
155        return "kde"
156    elif section == "Library development":
157        return "libdevel"
158    elif section == "Libraries":
159        return "libs"
160    elif section == "Mail":
161        return "mail"
162    elif section == "Mathematics":
163        return "math"
164    elif section == "Miscellaneous":
165        return "misc"
166    elif section == "Network":
167        return "net"
168    elif section == "Newsgroups":
169        return "news"
170    elif section == "Old Libraries":
171        return "oldlibs"
172    elif section == "Other OS's and file systems":
173        return "otherosfs"
174    elif section == "Perl":
175        return "perl"
176    elif section == "Python":
177        return "python"
178    elif section == "Science":
179        return "science"
180    elif section == "Shells":
181        return "shells"
182    elif section == "Sound":
183        return "sound"
184    elif section == "TeX":
185        return "tex"
186    elif section == "Text Processing":
187        return "text"
188    elif section == "Utilities":
189        return "utils"
190    elif section == "Virtual packages":
191        return "virtual"
192    elif section == "Web Software":
193        return "web"
194    elif section == "X Window System software":
195        return "x11"
196   
197    return ""
198
199def getSection(section):
200    if section == "admin":
201        return "Administration Utilities"
202    elif section == "base":
203        return "Base Utilities"
204    elif section == "comm":
205        return "Communication Programs"
206    elif section == "debian-installer":
207        return "debian-installer udeb packages"
208    elif section == "devel":
209        return "Development"
210    elif section == "doc":
211        return "Documentation"
212    elif section == "editors":
213        return "Editors"
214    elif section == "electronics":
215        return "Electronics"
216    elif section == "embedded":
217        return "Embedded software"
218    elif section == "games":
219        return "Games"
220    elif section == "gnome":
221        return "Gnome"
222    elif section == "graphics":
223        return "Graphics"
224    elif section == "hamradion":
225        return "Ham Radio"
226    elif section == "interpreters":
227        return "Interpreters"
228    elif section == "kde":
229        return "KDE"
230    elif section == "libdevel":
231        return "Library development"
232    elif section == "libs":
233        return "Libraries"
234    elif section == "mail":
235        return "Mail"
236    elif section == "math":
237        return "Mathematics"
238    elif section == "misc":
239        return "Miscellaneous"
240    elif section == "net":
241        return "Network"
242    elif section == "news":
243        return "Newsgroups"
244    elif section == "oldlibs":
245        return "Old Libraries"
246    elif section == "otherosfs":
247        return "Other OS's and file systems"
248    elif section == "perl":
249        return "Perl"
250    elif section == "python":
251        return "Python"
252    elif section == "science":
253        return "Science"
254    elif section == "shells":
255        return "Shells"
256    elif section == "sound":
257        return "Sound"
258    elif section == "tex":
259        return "TeX"
260    elif section == "text":
261        return "Text Processing"
262    elif section == "utils":
263        return "Utilities"
264    elif section == "virtual":
265        return "Virtual packages"
266    elif section == "web":
267        return "Web Software"
268    elif section == "x11":
269        return "X Window System software"
270    elif section == "all":
271        return "All packages"
272   
273    return ""
Note: See TracBrowser for help on using the browser.