File: test-configlets

package info (click to toggle)
configlet 1.8
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,044 kB
  • ctags: 211
  • sloc: python: 1,417; xml: 709; makefile: 139; sh: 44
file content (167 lines) | stat: -rw-r--r-- 5,023 bytes parent folder | download
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
#!/usr/bin/python

# test-configlets -- Simple notebook frontend, for testing

# $Progeny: test-configlets,v 1.18 2002/01/18 06:19:43 dsp 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

import sys
import os
import string
from gtk import *
from gnome.ui import *
from libglade import *
import configlet

notebook = None
notebook_page_list = []
save_settings = None

def debug(message):
    configlet.debug("test-configlets", message)

def closing(*args):
    global cfggroup
    global save_settings

    result = args[-1]
    if result == "save":
        debug("Save!")
        save_settings = "yes"
        for cfglet in cfggroup:
            if not cfglet.validate():
                debug("Configlet named \"%s\" did not validate." \
                      % cfglet.get_display_title())

        cfggroup.on_gnome_close()

    mainquit()

    return TRUE

def validate_tab(*args):
    (configlet_name, page_name) = string.split(notebook_page_list[notebook.get_current_page()], "|")

    for cfglet in cfggroup:
        if cfglet.get_display_title() == configlet_name:
            if not cfglet.validate_page(page_name):
                debug("page %s of configlet %s did not validate" % \
                      (page_name, configlet_name))

    return TRUE

class ConfigGroup(configlet.BasicConfigGroup):
    def show(self):
        global notebook

        ok_button = GtkButton("OK")
        ok_button.connect("clicked", closing, "save")
        ok_button.show()

        cancel_button = GtkButton("Cancel")
        cancel_button.connect("clicked", closing)
        cancel_button.show()
        
        bbar = GtkHButtonBox()
        bbar.set_usize(550, -1)
        bbar.set_layout(BUTTONBOX_SPREAD)
        bbar.set_border_width(10)
        bbar.add(ok_button)
        bbar.add(cancel_button)
        bbar.show()

        notebook = GtkNotebook()
        notebook.set_tab_pos(POS_TOP)
        notebook.connect("switch-page", validate_tab)
        notebook.show()

        for cfglet in self:
            debug("showing configlet %s" % cfglet.get_name())
            pagenum = 1
            num_pages = len(cfglet.get_page_names())
            for page in cfglet.get_page_names():
                notebook_page_list.append("%s|%s" % (cfglet.get_display_title(), page))
                if num_pages == 1:
                    labelstr = cfglet.get_display_title()
                else:
                    pagename = cfglet.get_page_display_title(page)
                    if pagename:
                        labelstr = "%s (%s)" % (cfglet.get_display_title(),
                                                pagename)
                    else:
                        labelstr = "%s (%d)" % (cfglet.get_display_title(),
                                                pagenum)
                configlet_label = GtkLabel(labelstr)
                configlet_label.show()
                pagewidget = cfglet.get_widget(page)
                pagewidget.unparent()
                notebook.append_page(pagewidget, configlet_label)
                pagewidget.show()
                pagenum = pagenum + 1

        top_vbox = GtkVBox()
        top_vbox.set_border_width(10)
        top_vbox.add(notebook)
        top_vbox.add(bbar)
        top_vbox.show_all()

        window = GtkWindow()
        window.connect("delete_event", closing)
        window.set_title("Configuration")
        window.add(top_vbox)
        window.show()

        mainloop()

        self.shown = 1

# Main program.

os.environ["DEBUG"] = "on"

configlet_dir = "."
if len(sys.argv) > 1:
    configlet_dir = sys.argv[1]

configlet.set_privileged_runner(configlet.GnomeSudoPrivilegedRunner())

cfggroup = ConfigGroup(configlet_dir)
cfggroup.gnome_setup()

if os.path.exists("test.in"):
    default_debconf = []
    readfile = open("test.in")
    for line in readfile.readlines():
        if line[-1] == "\n":
            line = line[:-1]
        default_debconf.append(line)
    readfile.close()
    cfggroup.load_debconf(default_debconf)
else:
    cfggroup.load_all_debconf()

cfggroup.show()

if save_settings:
    if os.path.exists("test.in"):
        savefile = open("test.out", "w")
        for line in cfggroup.report_debconf():
            savefile.write(line + "\n")
        savefile.close()
    else:
        cfggroup.save_and_commit_all_debconf()