ArthurPeters

Attachment 'install-nondefault-features.py'

Download

   1 #! /usr/bin/python
   2 
   3 import pygtk
   4 pygtk.require('2.0')
   5 import gtk
   6 #import gtk.gdk
   7 #import gtk.glade
   8 #import gobject
   9 #import gnome
  10 #import gettext
  11 import os
  12 import sys
  13 
  14 import apt
  15 import apt_pkg
  16 import SoftwareProperties.aptsources
  17 #import apt.cache
  18 
  19 import re
  20 import subprocess
  21 
  22 INSTALL, UPDATE = range(2)
  23 
  24 def run_synaptic(action, packages = []):
  25     cmd = ["/usr/sbin/synaptic", "--hide-main-window",  "--non-interactive"]
  26     if action == INSTALL:
  27       cmd.append("--set-selections")
  28       cmd.append("--progress-str")
  29       cmd.append("%s" % _("The updates are being applied."))
  30       cmd.append("--finish-str")
  31       cmd.append("%s" %  _("Upgrade is complete"))
  32       proc = subprocess.Popen(cmd, stdin=subprocess.PIPE)
  33       f = proc.stdin
  34       for s in packages:
  35         f.write("%s\tinstall\n" % s)
  36       f.close()
  37       proc.wait()
  38     elif action == UPDATE:
  39       cmd.append("--update-at-startup")
  40       subprocess.call(cmd)
  41     else:
  42       print "run_synaptic() called with unknown action"
  43       sys.exit(1)
  44 
  45 if __name__ == "__main__":
  46   if os.geteuid() != 0:
  47     os.system( "gksudo %s" % sys.argv[0] )
  48     sys.exit()
  49   _ = str
  50 
  51   mainarchivere = re.compile( "http://.*archive.ubuntu.com.*" )
  52 
  53   archiveuri = "http://archive.ubuntu.com/ubuntu/"
  54 
  55   sourceslist = SoftwareProperties.aptsources.SourcesList()
  56   for i in sourceslist:
  57     if mainarchivere.match( i.uri ):
  58       archiveuri = i.uri
  59       print "Found archive URI to be:", i.uri
  60       break
  61   
  62   packages_to_install = []
  63   def ask_feature( text, packages ):
  64     dialog = gtk.MessageDialog(message_format=text, 
  65                                type=gtk.MESSAGE_QUESTION,
  66                                buttons=gtk.BUTTONS_YES_NO)
  67     if dialog.run() == gtk.RESPONSE_YES:
  68       packages_to_install.extend(packages)
  69     dialog.destroy()
  70   
  71   ask_feature( "Do you want playback MP3 support?", ["gstreamer0.10-plugins-ugly"] )
  72   ask_feature( "Do you want common video codec support (DivX, XVid, AC3, but not DVDs)?", ["gstreamer0.10-plugins-ugly", "gstreamer0.10-ffmpeg"] )
  73   ask_feature( "Do you want other video codecs (still not DVDs, sorry)?", ["gstreamer0.10-plugins-ugly-multiverse"] )
  74   ask_feature( """Do you want ZeroConf (AKA Bonjour or Rendezvous) support?
  75 This includes resolving hostnames using mDNS.
  76 
  77 WARNING: This does not play nice with NetworkManager.""", ["avahi-discover", "gnome-user-share", "libnss-mdns"] )
  78   ask_feature( """Do you want NetworkManager?
  79 This provides network interface handing in a dynamic way.
  80 Allowing you to select which wireless network or wired 
  81 network to use. You should add nm-applet to your session
  82 to make this useful (add it in System -> Preferences -> 
  83 Session -> Start Up Programs).
  84 
  85 WARNING: This does not play nice with ZeroConf (avahi).""", ["network-manager"] )
  86   
  87   packages_to_install = set(packages_to_install)
  88   if len( packages_to_install ) > 0:
  89     dialog = gtk.MessageDialog(message_format="""I am going to configure your system to get software
  90 that, although still part of Ubuntu, does not
  91 receive as much testing and attention. Also
  92 some of this software may be illegal in your
  93 contry because of patents.
  94 
  95 The following packages will be installed:
  96 %s
  97 
  98 Is this alright? (if you click "No", no changes will be made)""" % ("\n".join(packages_to_install)), 
  99                                type=gtk.MESSAGE_QUESTION,
 100                                buttons=gtk.BUTTONS_YES_NO)
 101     if dialog.run() == gtk.RESPONSE_YES:
 102       dialog.destroy()
 103       sourceslist.backup()
 104       sourceslist.add( "deb", archiveuri, "dapper", ["universe", "multiverse"] )
 105       sourceslist.add( "deb-src", archiveuri, "dapper", ["universe"] )
 106       sourceslist.save()
 107 
 108       run_synaptic( UPDATE )
 109       run_synaptic( INSTALL, packages_to_install )
 110 
 111       dialog = gtk.MessageDialog(message_format="""The features you requested are now installed, 
 112 but you may need to reboot to see them.
 113 You can run this script again to add more features, 
 114 but I am not smart enough to remove features.""", buttons=gtk.BUTTONS_OK)
 115       dialog.run()
 116     else:
 117       dialog = gtk.MessageDialog(message_format="""Your system have not been modified. Run this script again later if you like.""", buttons=gtk.BUTTONS_OK )
 118       dialog.run()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-05-20 03:21:29, 4.1 KB) [[attachment:install-nondefault-features.py]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.