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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
|
#!/usr/bin/python
# configlets-druid -- GNOME Druid ("wizard") frontend
# $Progeny: configlets-druid,v 1.87 2002/04/15 18:04:48 jlicquia Exp $
# Copyright (C) 2001 Progeny Linux Systems, Inc.
# AUTHORS: Jeff Licquia <jlicquia@progeny.com>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
###############################################################################
# Parse command line options
# We do this here because pygtk provides no way to hook into GNOME's
# popt mechanism.
import getopt
import sys
ask_only = 0
commit_only = 0
try:
(opts, args) = getopt.getopt(sys.argv[1:], None,
["ask-only", "commit-only"])
except getopt.GetoptError:
pass
for i in opts:
if i[0] == "--ask-only":
ask_only = 1
elif i[0] == "--commit-only":
commit_only = 1
sys.argv = [sys.argv[0],"--sm-disable"]
###############################################################################
import gtk
import GDK
import os
import string
import getopt
from gtk import *
from gnome.ui import *
from libglade import *
import GdkImlib
import configlet
def set_page(page_id, is_forward):
global druid
global picked_configlets
global druid_pages
global druid_page_end
global druid_select_page
global cancel_button_state
configlet.debug("configlets-druid", "current page id: %s" % (page_id,))
if not page_id:
if is_forward:
page_index = -1
else:
page_index = len(druid_pages)
else:
for page_index in range(0, len(druid_pages)):
if druid_pages[page_index][0] == page_id:
break
configlet_name = ""
while configlet_name not in picked_configlets:
if is_forward:
page_index = page_index + 1
else:
page_index = page_index - 1
if page_index < 0 or page_index >= len(druid_pages):
configlet_name = ""
configlet.debug("configlets-druid", "off the edge...")
break
found_page_id = druid_pages[page_index][0]
configlet.debug("configlets-druid",
"considering page id %s" % found_page_id)
configlet_name = found_page_id
if not configlet_name:
if is_forward:
druid.set_page(druid_page_end)
druid.set_buttons_sensitive(TRUE, TRUE, cancel_button_state)
else:
druid.set_page(druid_select_page)
druid.set_buttons_sensitive(FALSE, TRUE, cancel_button_state)
else:
configlet.debug("configlets-druid",
"setting page to %s" % found_page_id)
druid.set_page(druid_pages[page_index][1])
druid.set_buttons_sensitive(TRUE, TRUE, cancel_button_state)
def toggle_configlet(widget, page_id):
global picked_configlets
if widget.get_active():
if page_id not in picked_configlets:
picked_configlets.append(page_id)
else:
while page_id in picked_configlets:
picked_configlets.remove(page_id)
configlet.debug("configlets-druid",
"picked: %s" % string.join(picked_configlets, ", "))
return FALSE
def next_from_start(*args):
global druid
global druid_select_page
global cancel_button_state
druid.set_page(druid_select_page)
druid.set_buttons_sensitive(FALSE, TRUE, cancel_button_state)
return TRUE
def finished(*args):
global cfggroup
global completed
completed = TRUE
cfggroup.on_gnome_close()
mainquit()
return TRUE
def canceled(*args):
mainquit()
return TRUE
def back_page(*args):
set_page(args[-1], FALSE)
return TRUE
def next_page(*args):
set_page(args[-1], TRUE)
return TRUE
def configlet_done(druid, druidpage, page_id):
global not_validated
global cfggroup
configlet.debug("configlets-druid",
"entering configlet_done for %s" % (page_id,))
for cfglet in cfggroup:
if cfglet.get_name() == page_id:
configlet.debug("configlets-druid", "found page")
try:
validation_result = cfglet.validate()
except:
validation_result = FALSE
if not validation_result:
configlet.debug("configlets-druid", "oops - bad validation")
button = GnomeMessageBox("""
The \"%s\" configuration screen failed to validate. If you continue,
the configuration information you entered may be lost. Do you want
to continue?
""" % (cfglet.get_display_title(),), "warning",
STOCK_BUTTON_YES,
STOCK_BUTTON_NO).run_and_close()
if button == 0:
configlet.debug("configlets-druid", "going ahead anyway")
not_validated[page_id] = FALSE
else:
configlet.debug("configlets-druid", "user wants to try again")
return TRUE
else:
configlet.debug("configlets-druid", "validation ok")
if not_validated.has_key(page_id):
del not_validated[page_id]
set_page(page_id, TRUE)
return TRUE
raise RuntimeError, "configlet %s not found for validation" % (page_id,)
start_title = "System Configuration"
start_text = """
You can now configure important aspects of the system.
Click Next to cycle through the following configuration screens. Each
screen provides context-sensitive help for the controls it uses. Simply
let the cursor of your mouse or other pointing device "hover" over the
control you need help with.
If problems occur with the information you provide, the system will ask for
clarification or will point out the problem.
"""
end_title = "Finish System Configuration"
end_text = """
Congratulations! You've completed the steps to configure your system.
Click Finish to complete the configuration stage. The system will be set
up according to your specifications. This could take a few minutes, so
please be patient.
"""
default_rc = "/usr/share/themes/Raleigh/gtk/gtkrc"
config_filename = "/etc/configlets-druid.cfg"
not_validated = {}
completed = FALSE
cancel_button_state = FALSE
picked_configlets = []
druid_pages = []
config = {}
required_configlet_names = []
recommended_configlet_names = []
optional_configlet_names = []
omitted_configlet_names = []
class DruidConfigGroup(configlet.BasicConfigGroup):
def debug(self, message):
configlet.debug("DruidConfigGroup", message)
def warn(self, message):
configlet.warn("DruidConfigGroup", message)
def error(self, message):
configlet.error("DruidConfigGroup", message)
def show(self):
global required_configlet_names
global recommended_configlet_names
global optional_configlet_names
global omitted_configlet_names
global picked_configlets
global druid
global druid_pages
global druid_page_end
global druid_select_page
global cancel_button_state
global config
self.no_logos = 0
image_path = "/usr/share/pixmaps/debian-logo.xpm"
if config.has_key("logo"):
image_path = config["logo"]
try:
image = GdkImlib.Image(image_path)
except:
self.no_logos = 1
if not image:
self.no_logos = 1
watermark = None
if config.has_key("watermark") and not self.no_logos:
try:
watermark = GdkImlib.Image(config["watermark"])
except:
self.no_logos = 1
if not watermark:
self.no_logos = 1
druid = GnomeDruid()
druid.connect("cancel", canceled)
druid_page = GnomeDruidPageStart()
druid_page.connect("next", next_from_start, "")
druid_page.set_title(start_title)
druid_page.set_text(start_text)
if not self.no_logos:
try:
druid_page.set_logo(image)
if watermark:
druid_page.set_watermark(watermark)
except:
self.no_logos = 1
druid_page.show()
druid.append_page(druid_page)
# First page - allow the user to select config.
druid_select_page = GnomeDruidPageStandard("Select Options to Configure")
if not self.no_logos:
druid_select_page.set_logo(image)
druid_select_page.connect("next", next_page, "")
label = GtkLabel("Please select the options you want to configure:")
label.set_alignment(0.0, 0.5)
label.show()
druid_select_page.vbox.pack_start(label)
configlet_table = GtkTable(1, 2, FALSE)
configlet_table.set_row_spacings(10)
configlet_table.set_col_spacings(20)
configlet_table.show()
rows = 1
configlets = 0
for cfglet in self:
if cfglet.get_name() in omitted_configlet_names:
continue
elif config.has_key("dont_show_required_configlets") and \
cfglet.get_name() in required_configlet_names:
continue
elif config.has_key("show_only_listed_configlets") and \
cfglet.get_name() not in required_configlet_names and \
cfglet.get_name() not in recommended_configlet_names and \
cfglet.get_name() not in optional_configlet_names:
continue
configlets = configlets + 1
if configlets > rows:
rows = rows + 1
configlet_table.resize(rows, 2)
#hbox = GtkHBox(FALSE, 0)
checkbox = GtkCheckButton()
checkbox.connect_after("toggled", toggle_configlet,
cfglet.get_name())
checkbox.show()
#hbox.pack_start(checkbox, FALSE, FALSE, 0)
# keep the label width from raging out of control
label_str = cfglet.get_display_title()
if cfglet.get_name() in required_configlet_names:
label_str = label_str + " (mandatory)"
label = GtkLabel(label_str)
# XXX: having to do this GtkWidget.set is a bug in the Python GTK+
# bindings -- FILE A BUG REPORT XXX
GtkWidget.set(label, {"width" : 200})
label.set_justify(JUSTIFY_LEFT)
label.set_line_wrap(TRUE)
label.set_alignment(0.0, -1)
label.show()
checkbox.add(label)
#hbox.pack_start(label, TRUE, TRUE, 0)
#hbox.show()
if not cfglet.get_name() in optional_configlet_names:
checkbox.set_active(TRUE)
picked_configlets.append(cfglet.get_name())
if cfglet.get_name() in required_configlet_names:
checkbox.set_sensitive(FALSE)
label.set_sensitive(FALSE)
configlet_table.attach(checkbox, 0, 1, rows - 1, rows,
FILL, 0, 0, 10)
configlet_desc = GtkLabel(cfglet.get_description())
configlet_desc.set_usize(450, -1)
configlet_desc.set_line_wrap(TRUE)
configlet_desc.set_alignment(0.0, 0.0)
configlet_desc.show()
configlet_table.attach(configlet_desc, 1, 2, rows - 1, rows,
FILL, 0, 0, 10)
druid_select_page.vbox.pack_start(configlet_table, TRUE, TRUE, 0)
druid_select_page.show()
druid.append_page(druid_select_page)
for cfglet in self:
pages = cfglet.get_page_names()
if len(pages) > 1:
notebook = GtkNotebook()
for page in pages:
pagetitle = cfglet.get_page_display_title(page)
pagewidget = cfglet.get_widget(page)
pagewidget.unparent()
pagewidget.show()
notebook.append_page(pagewidget,
GtkLabel(pagetitle))
widget = notebook
else:
widget = cfglet.get_widget()
widget.unparent()
widget.show()
druid_page = GnomeDruidPageStandard(cfglet.get_display_title())
if not self.no_logos:
try:
druid_page.set_logo(image)
if watermark:
druid_page.set_watermark(watermark)
except:
self.no_logos = 1
druid_page.vbox.pack_start(widget, TRUE, TRUE)
druid_page.show()
page_id = cfglet.get_name()
druid_page.connect("next", configlet_done, page_id)
druid_page.connect("back", back_page, page_id)
druid_pages.append((page_id, druid_page))
druid.append_page(druid_page)
druid_page_end = GnomeDruidPageFinish()
druid_page_end.set_title(end_title)
druid_page_end.set_text(end_text)
if not self.no_logos:
try:
druid_page_end.set_logo(image)
if watermark:
druid_page_end.set_watermark(watermark)
except:
pass
druid_page_end.connect("back", back_page, "")
druid_page_end.connect("finish", finished)
druid_page_end.show()
druid.append_page(druid_page_end)
druid.set_buttons_sensitive(FALSE, TRUE, cancel_button_state)
druid.show()
window = GtkWindow()
window.set_title("System Configuration")
window.add(druid)
window.connect("delete_event", canceled)
window.set_position(WIN_POS_CENTER)
window.show()
mainloop()
self.shown = TRUE
def debconf(self):
global not_validated
results = []
for cfglet in self.configlets:
try:
if not not_validated.has_key(cfglet.get_name()):
results = results + cfglet.report_debconf()
except:
debug("configlet %s failed to report debconf info"
% (cfglet.get_name(),))
if os.environ.has_key("DEBUG"):
configlet.print_traceback()
return results
# Main program.
# Load configuration file, if it exists.
if os.path.exists(config_filename):
config_file = open(config_filename)
for line in config_file.readlines():
line_strip = string.strip(line)
if len(line_strip) < 1:
continue
if line_strip[0] == "#":
continue
config_items = string.split(line_strip, None, 1)
if len(config_items) == 1:
config[config_items[0]] = None
elif len(config_items) == 2:
config[config_items[0]] = config_items[1]
config_file.close()
# Apply some of the configuration information.
if config.has_key("debug"):
os.environ["DEBUG"] = "true"
if config.has_key("cancelable"):
cancel_button_state = TRUE
if config.has_key("required_configlets"):
required_configlet_names = string.split(config["required_configlets"])
if config.has_key("standard_configlets"):
recommended_configlet_names = string.split(config["standard_configlets"])
if config.has_key("unchecked_configlets"):
optional_configlet_names = string.split(config["unchecked_configlets"])
if config.has_key("omit_configlets"):
omitted_configlet_names = string.split(config["omit_configlets"])
# Load gtkrc. If no gtkrc is given in the config file, load GTK2
# default engine so checkbuttons and other widgets actually make
# sense visually.
if config.has_key("gtkrc"):
if os.path.exists(config["gtkrc"]):
gtk.rc_parse(config["gtkrc"])
elif os.path.exists(default_rc):
gtk.rc_parse(default_rc)
# I'm not in a mood to hook this up with getopt likeshould have been
# done long ago, so i'm just bumping the index to 2 to account for
# --sm-disable.
configlet_dir = "/usr/share/configlets"
if len(sys.argv) > 2:
configlet_dir = sys.argv[2]
cfggroup = DruidConfigGroup(configlet_dir)
cfggroup.gnome_setup()
cfggroup.load_all_debconf()
if commit_only:
completed = TRUE
else:
cfggroup.show()
if ask_only:
sys.exit(0)
if completed:
# Get list of packages to configure.
finished_configlets = []
finished_configlet_data = {}
for cfglet in cfggroup:
configlet_name = cfglet.get_name()
if configlet_name in picked_configlets:
finished_configlets.append(configlet_name)
finished_configlet_data[configlet_name] = cfglet.report_debconf()
# Set up configure status window.
status_win_vbox = GtkVBox(FALSE, 5)
status_win_vbox.show()
status_label = GtkLabel("Configuring package: ")
status_label.set_justify(JUSTIFY_LEFT)
status_label.show()
status_win_vbox.pack_start(status_label)
status_bar = GtkProgressBar()
status_bar_adj = GtkAdjustment(0, 0, len(finished_configlets) + 1, 1, 1, 1)
status_bar.set_adjustment(status_bar_adj)
status_bar.show()
status_win_vbox.pack_start(status_bar)
gtk._root_window().set_cursor(gtk.cursor_new(GDK.WATCH))
status_win = GtkWindow(gtk.WINDOW_TOPLEVEL, "Configuring Packages")
status_win.add(status_win_vbox)
status_win.set_position(WIN_POS_CENTER)
status_win.show()
while events_pending():
mainiteration()
# Configure each package, reporting on status.
for configlet_name in finished_configlets:
status_label.set_text("Configuring: %s" % configlet_name)
while events_pending():
mainiteration()
cfggroup.get_debconf().set(finished_configlet_data[configlet_name])
status_bar_adj.set_value(status_bar_adj.value + 1)
while events_pending():
mainiteration()
status_label.set_text("Committing changes...")
while events_pending():
mainiteration()
cfggroup.get_debconf().commit()
status_bar_adj.set_value(status_bar_adj.value + 1)
while events_pending():
mainiteration()
# Done - get rid of status window.
gtk._root_window().set_cursor(gtk.cursor_new(GDK.LEFT_PTR))
status_win.hide()
while events_pending():
mainiteration()
# vim:ai:et:sts=4:sw=4:tw=0:
|