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

import apt
import sys, os
import copy
import time

from apt.progress import InstallProgress

class TextInstallProgress(InstallProgress):
	def __init__(self):
		apt.progress.InstallProgress.__init__(self)
		self.last = 0.0
	def updateInterface(self):
		InstallProgress.updateInterface(self)
		if self.last >= self.percent:
			return
		sys.stdout.write("\r[%s] %s\n" %(self.percent, self.status))
		sys.stdout.flush()
		self.last = self.percent
	def conffile(self,current,new):
		print "conffile prompt: %s %s" % (current,new)
	def error(self, errorstr):
		print "got dpkg error: '%s'" % errorstr

cache = apt.Cache(apt.progress.OpTextProgress())

fprogress = apt.progress.TextFetchProgress()
iprogress = TextInstallProgress()

pkg = cache["test-package"]
pkg.markUpgrade()
cache.commit(fprogress,iprogress)
sys.exit(1)

# install or remove, the importend thing is to keep us busy :)
if pkg.isInstalled:
	print "Going to delete %s" % pkg.name
	pkg.markDelete()
else:
	print "Going to install %s" % pkg.name
	pkg.markInstall()
res = cache.commit(fprogress, iprogress)
print res

sys.exit(0)