[Frugalware-git] fw-interfaces: fw-interfaces.py *initial import
bouleetbil
bouleetbil at frogdev.info
Thu Apr 8 14:19:22 CEST 2010
Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fw-interfaces.git;a=commitdiff;h=080fca76c06ced7a1989ec608f5bb442460b0c56
commit 080fca76c06ced7a1989ec608f5bb442460b0c56
Author: bouleetbil <bouleetbil at frogdev.info>
Date: Thu Apr 8 14:09:48 2010 +0000
fw-interfaces.py
*initial import
diff --git a/fw-interfaces.py b/fw-interfaces.py
new file mode 100644
index 0000000..ec06ec5
--- /dev/null
+++ b/fw-interfaces.py
@@ -0,0 +1,297 @@
+#!/usr/bin/env python
+
+#/*
+# * Copyright (c) 2010 gaetan gourdin
+# *
+# * Permission is hereby granted, free of charge, to any person obtaining a copy
+# * of this software and associated documentation files (the "Software"), to deal
+# * in the Software without restriction, including without limitation the rights
+# * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# * copies of the Software, and to permit persons to whom the Software is
+# * furnished to do so, subject to the following conditions:
+# *
+# * The above copyright notice and this permission notice shall be included in
+# * all copies or substantial portions of the Software.
+# *
+# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# * THE SOFTWARE.
+# */
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+import pacman
+import sys
+import os
+
+ConfigFile = "fw-interfaces.config"
+USE_NM = 0
+USE_WICD = 0
+USE_FWUTILS = 1
+#by default use frugalware
+
+
+def analyseLine(Line):
+ global USE_NM
+ global USE_WICD
+ global USE_FWUTILS
+ try:
+ result=Line.split("=")
+
+ key=result[0].split(" ")[0]
+ value=result[1].split(" ")[0]
+
+ if key == "USE_FWUTILS":
+ if value == "1":
+ USE_FWUTILS = 1
+ if key == "USE_NM":
+ if value == "1":
+ USE_NM = 1
+ if key == "USE_WICD":
+ if value == "1":
+ USE_WICD = 1
+
+ except:
+ print "Read file error"
+
+
+
+def find_pkg(packagename):
+ if pacman.initialize("/") == -1:
+ print "initialize() failed"
+ local = pacman.db_register("local")
+ i = pacman.db_getpkgcache(local)
+ found = False
+ while i:
+ pkg = pacman.void_to_PM_PKG(pacman.list_getdata(i))
+ pkgname = pacman.void_to_char(pacman.pkg_getinfo(pkg, pacman.PKG_NAME))
+ if pkgname == packagename:
+ found = True
+ i = pacman.list_next(i)
+ pacman.release()
+ print found
+ return found
+
+
+#now read config file
+fs = open(ConfigFile, 'r')
+while 1:
+ txt = fs.readline().rstrip('\n\r')
+ if txt =='':
+ break
+ analyseLine(txt)
+fs.close()
+
+class MessageBox(gtk.Dialog):
+ def __init__(self, message="", buttons=(), pixmap=None,
+ modal= True):
+ gtk.Dialog.__init__(self)
+ self.connect("destroy", self.quit)
+ self.connect("delete_event", self.quit)
+ if modal:
+ self.set_modal(True)
+ hbox = gtk.HBox(spacing=5)
+ hbox.set_border_width(5)
+ self.vbox.pack_start(hbox)
+ hbox.show()
+ if pixmap:
+ self.realize()
+ pixmap = Pixmap(self, pixmap)
+ hbox.pack_start(pixmap, expand=gtk.FALSE)
+ pixmap.show()
+ label = gtk.Label(message)
+ hbox.pack_start(label)
+ label.show()
+ for text in buttons:
+ b = gtk.Button(text)
+ b.set_flags(gtk.CAN_DEFAULT)
+ b.set_data("user_data", text)
+ b.connect("clicked", self.click)
+ self.action_area.pack_start(b)
+ b.show()
+ self.ret = None
+ def quit(self, *args):
+ self.hide()
+ self.destroy()
+ gtk.main_quit()
+ def click(self, button):
+ self.ret = button.get_data("user_data")
+ self.quit()
+
+# create a message box, and return which button was pressed
+def message_box(title="Message Box", message="", buttons=(), pixmap=None,
+ modal= True):
+ win = MessageBox(message, buttons, pixmap=pixmap, modal=modal)
+ win.set_title(title)
+ win.show()
+ gtk.main()
+ return win.ret
+
+MessageOk=False
+#should be launch as root
+if (os.environ["USER"] != "root"):
+ message_box(title='Error',
+ message='Only root can use fw-interfaces',
+ buttons=('Ok',))
+ sys.exit(0)
+
+
+class Start:
+
+ def fct_rappel(self, widget, donnees=None):
+ global USE_NM
+ global USE_WICD
+ global USE_FWUTILS
+ global MessageOk
+ USE_NM = 0
+ USE_WICD = 0
+ USE_FWUTILS =0
+ if MessageOk:
+ if donnees == "2":
+ print "Use NetworkManager"
+ #ask to pacman-g2
+ if find_pkg("networkmanager"):
+ USE_NM = 1
+ else:
+ message_box(title='Missing package',
+ message='You should install networkmanager : pacman-g2 -S networkmanager',
+ buttons=('Ok',))
+ #bouton.set_active(True)
+ elif donnees == "3":
+ print "Use Wicd"
+ #ask to pacman-g2
+ if find_pkg("wicd"):
+ USE_WICD = 1
+ else:
+ message_box(title='Missing package',
+ message='You should install wicd : pacman-g2 -S wicd',
+ buttons=('Ok',))
+ #bouton.set_active(True)
+ else:
+ print "Use Frugalware netconfig"
+ USE_FWUTILS = 1
+ MessageOk=False
+ else:
+ MessageOk=True
+
+ def clic_about(self, widget, data=None):
+ message_box(title='About',
+ message='Frugalware Rocks :)',
+ buttons=('Ok',))
+
+
+ def quitter_pgm(self, widget, evenement, donnees=None):
+ gtk.main_quit()
+ return False
+
+
+ def apply_pgm(self, widget, evenement, donnees=None):
+ global USE_NM
+ global USE_WICD
+ global USE_FWUTILS
+ #save
+ print "Save configuration"
+ #Fix me : for now erase source
+ f = open(ConfigFile, "w")
+ f.write("USE_WICD="+str(USE_WICD)+"\n")
+ f.write("USE_NM="+str(USE_NM)+"\n")
+ f.write("USE_FWUTILS="+str(USE_FWUTILS)+"\n")
+ f.close()
+
+ gtk.main_quit()
+ return False
+
+ def read_config():
+ return True
+
+ def __init__(self):
+
+ self.fenetre = gtk.Window(gtk.WINDOW_TOPLEVEL)
+
+ self.fenetre.connect("delete_event", self.quitter_pgm)
+
+ self.fenetre.set_title("fw-interfaces")
+ self.fenetre.set_border_width(0)
+
+ boite1 = gtk.VBox(False, 0)
+ self.fenetre.add(boite1)
+ boite1.show()
+
+ animpixbuf = gtk.gdk.PixbufAnimation("fw.png")
+ image = gtk.Image()
+ image.set_from_animation(animpixbuf)
+ image.show()
+
+ bouton = gtk.Button()
+ bouton.add(image)
+ bouton.show()
+ boite1.pack_start(bouton)
+ bouton.connect("clicked", self.clic_about, "1")
+
+ boite2 = gtk.VBox(False, 10)
+ boite2.set_border_width(10)
+ boite1.pack_start(boite2, True, True, 0)
+ boite2.show()
+
+ bouton = gtk.RadioButton(None, "Frugalware Interface")
+ bouton.connect("toggled", self.fct_rappel, "1")
+ if USE_FWUTILS == 1:
+ bouton.set_active(True)
+ boite2.pack_start(bouton, True, True, 0)
+ bouton.show()
+
+ bouton = gtk.RadioButton(bouton, "NetworkManager")
+ bouton.connect("toggled", self.fct_rappel, "2")
+ if USE_NM == 1:
+ bouton.set_active(True)
+ boite2.pack_start(bouton, True, True, 0)
+ bouton.show()
+
+ bouton = gtk.RadioButton(bouton, "Wicd")
+ bouton.connect("toggled", self.fct_rappel, "3")
+ if USE_WICD == 1:
+ bouton.set_active(True)
+ boite2.pack_start(bouton, True, True, 0)
+ bouton.show()
+
+ separateur = gtk.HSeparator()
+ boite1.pack_start(separateur, False, True, 0)
+ separateur.show()
+
+ boite2 = gtk.VBox(False, 10)
+ boite2.set_border_width(10)
+ boite1.pack_start(boite2, False, True, 0)
+ boite2.show()
+
+ boutonApply = gtk.Button("Apply")
+ boutonApply.connect_object("clicked", self.apply_pgm,
+ self.fenetre, None)
+ boite2.pack_start(boutonApply, True, True, 0)
+ boutonApply.show()
+
+ boutonClose = gtk.Button("Closed")
+ boutonClose.connect_object("clicked", self.quitter_pgm,
+ self.fenetre, None)
+ boite2.pack_start(boutonClose, True, True, 0)
+ boutonClose.set_flags(gtk.CAN_DEFAULT)
+ boutonClose.grab_default()
+ boutonClose.show()
+
+
+ self.fenetre.show()
+
+def main():
+ gtk.main()
+ return 0
+
+if __name__ == "__main__":
+ Start()
+ main()
+
+
+
More information about the Frugalware-git
mailing list