2
# -*- coding: utf-8 -*-
5
# Copyright (C) 2013 National University of Defense Technology(NUDT) & Kylin Ltd
6
# This program is free software: you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License version 3, as published
8
# by the Free Software Foundation.
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranties of
12
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13
# PURPOSE. See the GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License along
16
# with this program. If not, see <http://www.gnu.org/licenses/>.
22
import apt.progress.base as apb
24
class FetchProcess(apb.AcquireProgress):
27
apb.AcquireProgress.__init__(self)
30
print 'done la done la !!!'
33
print 'fail la fail la !!!'
35
def fetch(self, item):
36
print 'fetch la fetch la !!!'
38
def ims_hit(self, item):
39
print 'ims_hit la !!!'
41
def media_change(self, media, drive):
42
print 'media change la !!!'
44
def pulse(self, owner):
45
# print 'pulse pulse pluse ...', owner
46
print 'current_bytes: ', self.current_bytes
47
print 'current_cps: ', self.current_cps
48
print 'current_items: ', self.current_items
49
print 'elapsed_time: ', self.elapsed_time
50
print 'fetched_bytes: ', self.fetched_bytes
51
print 'last_bytes: ', self.last_bytes
52
print 'total_bytes: ', self.total_bytes
53
print 'total_items: ', self.total_items
56
print 'fetch progress is start ...'
59
print 'fetch progress is stop ...'
62
class AptProcess(apb.InstallProgress):
63
'''Install progress'''
65
apb.InstallProgress.__init__(self)
67
def conffile(self, current, new):
68
# global_event.emit("action-conffile", (current, new))
70
# log("conffile: %s %s" % (current, new))
71
print 'conffile wo ca!'
73
def error(self, errorstr):
74
# global_event.emit("action-error", (self.pkg_name, errorstr))
75
# log("error: %s" % errorstr)
76
print 'ERROR :' + errorstr
78
def start_update(self):
80
# log("start action...")
81
print 'kai shi le kaishile !!!'
83
def status_change(self, pkg, percent, status):
84
'''Progress status change.'''
85
# global_event.emit("action-update", (self.pkg_name, self.action_type, int(percent), status))
86
# log((self.pkg_name, self.action_type, int(percent), status))
87
print '\n' + str(int(percent)) + "% zhuangtai: " + status
97
self.pkgList.append(pkg)
98
self.pkgNameList.append(pkg.name)
100
def get_pkg_by_name(self, pkgname):
101
return self.ca[pkgname]
103
def install_pkg(self, pkgname):
105
pkg = self.get_pkg_by_name(pkgname)
109
self.ca.commit(FetchProcess(), AptProcess())
114
def uninstall_pkg(self, pkgname):
116
pkg = self.get_pkg_by_name(pkgname)
120
self.ca.commit(None, AptProcess())
123
print "uninstall err"
125
def update_pkg(self, pkgname):
127
pkg = self.get_pkg_by_name(pkgname)
131
self.ca.commit(FetchProcess(), AptProcess())
136
def get_pkgs_name_list(self):
137
return self.pkgNameList
139
def search_pkgs_name(self, pkgname):
140
if pkgname in self.pkgNameList:
144
for name in self.pkgNameList:
145
if name.find(pkgname) >= 0:
149
if __name__ == "__main__":
152
print "\ninput your command: "
155
for name in ad.pkgNameList:
158
print "input pkgName to install: "
159
pkgName = raw_input()
160
ad.install_pkg(pkgName)
162
print "input pkgName to uninstall: "
163
pkgName = raw_input()
164
ad.uninstall_pkg(pkgName)
166
print "input pkgName to update: "
167
pkgName = raw_input()
168
ad.update_pkg(pkgName)
172
print ad.get_pkg_by_name('gedit')
173
# pnl = ad.getpkglist()
175
# name1 = ad.search_pkgs_name('wesnoth-1.10-core')
177
# print 'aaa' + str(1)
178
# ad.install_pkg(name1)
179
# ad.uninstall_pkg(name1)
180
# p = ad.get_pkg_by_name(name1)
190
# pkgs.append(a.name)
195
# nanop.mark_install()
b'\\ No newline at end of file'