summaryrefslogtreecommitdiff
path: root/doc/examples/inst.py
blob: fe5ec8e3e4dc45ddd2b4b8b2f418094ff2b7109e (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
#!/usr/bin/python
# example how to deal with the depcache

import apt
import apt_pkg
import sys, os
import copy

from progress import TextFetchProgress, TextInstallProgress
from apt.progress import OpTextProgress

class TextInstallProgress(InstallProgress):
	def __init__(self):
		InstallProgress.__init__(self)
		self.status = None
	def StartUpdate(self):
		print "StartUpdate: %s" % self.statusfd
		self.status = os.fdopen(self.statusfd, "r")
		print self.status
	def UpdateInterface(self):
		if self.status != None:
			s = self.status.readline()
			if s:
				print s
	def FinishUpdate(self):
		self.status.close()

# init
apt_pkg.init()

progress = OpTextProgress()
cache = apt_pkg.GetCache(progress)
print "Available packages: %s " % cache.PackageCount

# get depcache
depcache = apt_pkg.GetDepCache(cache)
depcache.ReadPinFile()
depcache.Init(progress)

# do something
fprogress = TextFetchProgress()
iprogress = TextInstallProgress()

# can be used to set a custom fork method (like vte.Terminal.forkpty)
#iprogress.fork = os.fork

iter = cache["base-config"]
print "\n%s"%iter

# install or remove, the importend thing is to keep us busy :)
if iter.CurrentVer == None:
	depcache.MarkInstall(iter)
else:
	depcache.MarkDelete(iter)
res = depcache.Commit(fprogress, iprogress)
print res

print "Exiting"
sys.exit(0)