1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-19 12:28:08 +01:00

curses/configscript_curses.py: ADDED. Script configurator. More or less done.

curses/wicd-curses.py:
  Added suport for the script configurator
curses/README, in/man=wicd-curses.8.in:
  Script configurator now active
setup.py: Install configscript_curses.py with the rest of the stuff
This commit is contained in:
Andrew Psaltis
2009-01-17 20:10:10 -05:00
parent f01f10d33f
commit ce64ce0aa2
6 changed files with 195 additions and 3 deletions

View File

@@ -26,6 +26,8 @@ C : Display network configuration for selected network
A : Display "About" dialog
I : Raise the "Scan for hidden networks" dialog
H : Raise help dialog
S : Configure scripts (calls an external program, requires superuser
privileges
delete : Delete selected wired network profile (from the wired ComboBox)
IN DIALOGS (Meta usually is "Alt"):

139
curses/configscript_curses.py Executable file
View File

@@ -0,0 +1,139 @@
#!/usr/bin/env python
"""configscript_curses.py
Kind of like configscript.py, except writtwn using urwid.
Also recycles a lot of configscript.py, too. :-)
"""
# Copyright (C) 2009 Andrew Psaltis
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
from wicd import misc
import configscript
from configscript import write_scripts,get_script_info,get_val,none_to_blank,blank_to_none
import urwid
import urwid.curses_display
import sys
import os
_ = misc.get_gettext()
language = {}
language['configure_scripts'] = _("Configure Scripts")
language['before_script'] = _("Pre-connection Script")
language['after_script'] = _("Post-connection Script")
language['disconnect_script'] = _("Disconnection Script")
def main(argv):
global ui,frame
if len(argv) < 2:
print 'Network id to configure is missing, aborting.'
sys.exit(1)
ui = urwid.curses_display.Screen()
ui.register_palette( [
('body','default','default'),
('focus','dark magenta','light gray'),
('editcp', 'default', 'default', 'standout'),
('editbx', 'light gray', 'dark blue'),
('editfc', 'white','dark blue', 'bold')] )
network = argv[1]
network_type = argv[2]
script_info = get_script_info(network, network_type)
blank = urwid.Text('')
pre_entry_t = ('body',language['before_script']+': ')
post_entry_t = ('body',language['after_script']+': ')
disconnect_entry_t = ('body',language['disconnect_script']+': ')
global pre_entry,post_entry,disconnect_entry
pre_entry = urwid.AttrWrap(urwid.Edit(pre_entry_t,
none_to_blank(script_info.get('pre_entry'))),'editbx','editfc' )
post_entry = urwid.AttrWrap(urwid.Edit(post_entry_t,
none_to_blank(script_info.get('post_entry'))),'editbx','editfc' )
disconnect_entry = urwid.AttrWrap(urwid.Edit(disconnect_entry_t,
none_to_blank(script_info.get('disconnect_entry'))),'editbx','editfc' )
# The buttons
ok_button = urwid.AttrWrap(urwid.Button('OK',ok_callback),'body','focus')
cancel_button = urwid.AttrWrap(urwid.Button('Cancel',cancel_callback),'body','focus')
button_cols = urwid.Columns([ok_button,cancel_button],dividechars=1)
lbox = urwid.Pile([('fixed',2,urwid.Filler(pre_entry)),
#('fixed',urwid.Filler(blank),1),
('fixed',2,urwid.Filler(post_entry)),
('fixed',2,urwid.Filler(disconnect_entry)),
#blank,blank,blank,blank,blank,
urwid.Filler(button_cols,'bottom')
])
frame = urwid.Frame(lbox)
result = ui.run_wrapper(run)
if result == True:
script_info["pre_entry"] = blank_to_none(pre_entry.get_edit_text())
script_info["post_entry"] = blank_to_none(post_entry.get_edit_text())
script_info["disconnect_entry"] = blank_to_none(disconnect_entry.get_edit_text())
write_scripts(network, network_type, script_info)
OK_PRESSED = False
CANCEL_PRESSED = False
def ok_callback(button_object,user_data=None):
global OK_PRESSED
OK_PRESSED = True
def cancel_callback(button_object,user_data=None):
global CANCEL_PRESSED
CANCEL_PRESSED = True
def run():
dim = ui.get_cols_rows()
ui.set_mouse_tracking()
keys = True
while True:
if keys:
ui.draw_screen(dim, frame.render(dim, True))
keys = ui.get_input()
if "window resize" in keys:
dim = ui.get_cols_rows()
if "esc" in keys or 'Q' in keys:
return False
for k in keys:
#Send key to underlying widget:
if urwid.is_mouse_event(k):
event, button, col, row = k
frame.mouse_event( dim,
event, button, col, row,
focus=True)
else:
frame.keypress(dim, k)
# Check if buttons are pressed.
if CANCEL_PRESSED:
return False
if OK_PRESSED or 'meta enter' in keys:
return True
if __name__ == '__main__':
if os.getuid() != 0:
print "Root privileges are required to configure scripts. Exiting."
sys.exit(0)
main(sys.argv)

View File

@@ -483,3 +483,8 @@ class InputDialog(Dialog2):
def on_exit(self, exitcode):
return exitcode, self.edit.get_edit_text()
# Pile that has an edit and a label saying that the file at the path specified
# does not exist
#class FileGuessEdit(urwid.WidgetWrap):
# def __init__(self,caption='',

View File

@@ -45,7 +45,8 @@ from dbus import version as dbus_version
import gobject
# Other important wicd-related stuff
import wicd.misc as misc
from wicd import wpath
from wicd import misc
from wicd import dbusmanager
# Internal Python stuff
@@ -58,6 +59,10 @@ from prefs_curses import PrefsDialog
import netentry_curses
from netentry_curses import WirelessSettingsDialog, WiredSettingsDialog,error
# Stuff about getting the script configurer running
from grp import getgrgid
from os import getgroups,system
language = misc.get_language_list_gui()
########################################
@@ -245,6 +250,36 @@ def help_dialog(body):
help = TextDialog(theText,15,62,header=('header',"Wicd-Curses Help"))
help.run(ui,body)
def run_configscript(netname,nettype):
loop.quit()
ui.stop()
argv = netname + ' ' +nettype
#cmd = '/usr/lib/configscript_curses.py '+argv
cmd = wpath.lib+'configscript_curses.py '+argv
# Check whether we can sudo. Hopefully this is complete
glist = []
for i in getgroups():
glist.append(getgrgid(i)[0])
if 'root' in glist:
precmd = ''
precmdargv = ''
postcmd = ''
elif 'admin' in glist or 'wheel' in glist:
precmd = 'sudo'
precmdargv = ''
postcmd = ''
else:
precmd = 'su'
precmdargv = ' -c "'
postcmd = '"'
print "Calling command: " + precmd + precmdargv + cmd + postcmd
sys.stdout.flush()
system(precmd+precmdargv+cmd+postcmd)
raw_input("Press enter!")
main()
########################################
##### URWID SUPPORT CLASSES
########################################
@@ -698,6 +733,16 @@ class appGUI():
self.raise_hidden_network_dialog()
if "H" in keys:
help_dialog(self.frame)
if "S" in keys:
focus = self.thePile.get_focus()
if focus == self.wiredCB:
nettype = 'wired'
netname = self.wiredCB.get_body().get_selected_profile()
else:
nettype = 'wireless'
netname = str(self.wiredLB.get_focus()[1])
run_configscript(netname,nettype)
for k in keys:
if urwid.is_mouse_event(k):
event, button, col, row = k

View File

@@ -48,8 +48,8 @@ Bring up network configuration controller for the selected network
.TP
.BR delete
Delete the selected wired network profile (from the wired combo box at the top)
.PP
The following are not implemented yet:
.\".PP
.\"The following are not implemented yet:
.TP
.BR S
Bring up the script selector for the selected network (requires superuser privileges)

View File

@@ -409,6 +409,7 @@ try:
data.append(( wpath.lib, ['curses/prefs_curses.py']))
data.append(( wpath.lib, ['curses/wicd-curses.py']))
data.append(( wpath.lib, ['curses/netentry_curses.py']))
data.append(( wpath.lib, ['curses/configscript_curses.py']))
data.append(( wpath.bin, ['scripts/wicd-curses']))
if not wpath.no_install_man:
data.append(( wpath.mandir + 'man8/', ['man/wicd-curses.8']))