1
# UpdateManager/Backend/__init__.py
3
# Copyright (c) 2009 Canonical
5
# Author: Stephan Peijnik <debian@sp.or.at>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation; either version 2 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22
""" Newt/snack text interface """
29
log = logging.getLogger('UpdateManager.Frontend.Newt')
31
from gettext import gettext as _
34
from UpdateManager.Backend import RELOAD_CACHE_STATUS
35
from UpdateManager.Frontend import FrontendBase
38
def __init__(self, frontend, options):
39
self._frontend = frontend
40
self.screen = SnackScreen()
41
self.options = options
44
self.button_bar = ButtonBar(self.screen,
45
( (_("Cancel"), "cancel"),
46
(_("Install"), "ok")),
48
self.textview_changes = Textbox(72, 8, "Changelog", True, True)
49
self.checkbox_tree_updates = CheckboxTree(height=8, width=72, scroll=1)
50
self.checkbox_tree_updates.setCallback(self.checkbox_changed)
51
self.layout = GridForm(self.screen, "Updates", 1, 5)
52
self.layout.add(self.checkbox_tree_updates, 0, 0)
53
# empty line to make it look less crowded
54
self.layout.add(Textbox(60, 1," ",False, False), 0, 1)
55
self.layout.add(self.textview_changes, 0, 2)
56
# empty line to make it look less crowded
57
self.layout.add(Textbox(60, 1," ",False, False), 0, 3)
58
self.layout.add(self.button_bar, 0, 4)
59
# FIXME: better progress than the current suspend/resume screen thing
62
def cache_reload_callback(self, percent, operation):
63
if percent == RELOAD_CACHE_STATUS.DONE:
64
sys.stdout.write(_('Finished loading package cache.') + '\n')
65
elif percent == RELOAD_CACHE_STATUS.BEGIN:
66
sys.stdout.write(_('Loading package cache.') + '\n')
68
sys.stdout.write('[%2d] %s\r' % (percent, operation))
70
def main(self, application):
71
self._app = application
73
print _("Building Updates List")
75
packages = application.get_available_updates()
80
catid = pkg.get_update_category()
81
if not catid in categories.keys():
82
categories[catid] = [pkg,]
84
categories[catid].append(pkg)
86
for (i, cat_id) in enumerate(categories.keys()):
87
cat_name = application.get_update_category_name(cat_id)
88
self.checkbox_tree_updates.append(cat_name, selected=True)
89
for pkg in categories[cat_id]:
90
self.checkbox_tree_updates.addItem(pkg.get_package_name(),
91
(i, snackArgs['append']),
95
res = self.layout.runOnce()
97
button = self.button_bar.buttonPressed(res)
100
log.debug('TODO: commit')
104
self.screen.refresh()
106
def checkbox_changed(self):
107
pkg = self.checkbox_tree_updates.getCurrent()
110
if hasattr(pkg, "get_description"):
111
if self.options.show_description:
112
descr = pkg.get_description()
114
descr = "TODO: changelog handling"
116
self.textview_changes.setText(descr)
119
class NewtFrontend(FrontendBase):
120
""" Newt/Snack text frontend """
121
def init_frontend(self, options):
122
self._ui = NewtUI(self, options)
124
self.cache_reload_callback = self._ui.cache_reload_callback
126
def init_options(self, option_parser):
127
option_parser.add_option("--show-description", "--show-description",
128
action="store_true", dest="show_description",
130
help=_("Show description of the package "
131
"instead of the changelog"))
133
def main(self, application):
134
return self._ui.main(application)
136
def handle_unprivileged_invocation(self):
137
""" Newt unprivileged user handler. """
138
cmd = ' '.join(sys.argv)
139
if os.path.exists('/usr/bin/sudo'):
140
log.debug('Spwaning new update-manager process via sudo.')
141
return subprocess.call(['/usr/bin/sudo', cmd])
144
log.debug('Spawning new update-manager process via su.')
145
return subprocess.call(['/bin/su', '-c', cmd])