home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / bin / gdebi < prev    next >
Encoding:
Text File  |  2007-04-05  |  3.6 KB  |  107 lines

  1. #!/usr/bin/python
  2. #
  3. # Copyright (c) 2005-2007 Canonical
  4. #
  5. # AUTHOR:
  6. # Michael Vogt <mvo@ubuntu.com>
  7. #
  8. # This file is part of GDebi
  9. #
  10. # GDebi is free software; you can redistribute it and/or
  11. # modify it under the terms of the GNU General Public License as published
  12. # by the Free Software Foundation; either version 2 of the License, or (at
  13. # your option) any later version.
  14. #
  15. # GDebi is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. # General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with GDebi; if not, write to the Free Software
  22. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23. #
  24.  
  25. import warnings
  26. from warnings import warn
  27. warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
  28. import sys
  29. import apt
  30. import os.path
  31. import gettext
  32. from gettext import gettext as _
  33.  
  34. from optparse import OptionParser
  35. from GDebi.GDebiCli import GDebiCli
  36.  
  37. # FIXME: - add "--assume-yes" option
  38. #        - add check for removal of essential packages
  39.  
  40. if __name__ == "__main__":
  41.     localesApp="gdebi"
  42.     localesDir="/usr/share/locale"
  43.     gettext.bindtextdomain(localesApp, localesDir)
  44.     gettext.textdomain(localesApp)
  45.  
  46.     usage = unicode(_("usage: %prog [options] filename\n"
  47.                       "For a graphical version run gdebi-gtk\n"),"UTF-8")
  48.     parser = OptionParser(usage=usage)
  49.     parser.add_option("-n", "--non-interactive",
  50.                       action="store_true", dest="non_interactive",
  51.                       default=False,
  52.                       help=unicode(_("Run non-interactive (dangerous!)"),"UTF-8"))
  53.     parser.add_option("-q", "--quiet",
  54.                       action="store_true", dest="quiet",
  55.                       default=False,
  56.                       help=unicode(_("Do not show progress information"),"UTF-8"))
  57.     parser.add_option("--apt-line",
  58.                       action="store_true", dest="apt_line",
  59.                       default=False,
  60.                       help=unicode(_("Simulate only and print a apt-get install compatible line to stderr"), "UTF-8"))
  61.     parser.add_option("--root", dest="rootdir", default="/",
  62.                       help=unicode(_("Use alternative root dir"), "UTF-8"))
  63.     (options, args) = parser.parse_args()
  64.  
  65.     if len(args) == 0:
  66.         parser.print_help()
  67.         sys.exit(1)
  68.  
  69.     if not os.path.exists(args[0]):
  70.         sys.stderr.write(_("gdebi error, file not found: %s\n" % args[0]))
  71.         sys.exit(1)
  72.  
  73.     try:
  74.         debi = GDebiCli(options)
  75.     except SystemError, e:
  76.         print "Error opening the cache:\n%s" % e
  77.         sys.exit(1)
  78.     if not debi.open(args[0]):
  79.         sys.exit(1)
  80.  
  81.     if options.apt_line == True:
  82.         (install, remove, unauthenticated) = debi._deb.requiredChanges
  83.         print " ".join(install)
  84.         print " ".join([pkg+"-" for pkg in remove])
  85.         sys.exit(0)
  86.  
  87.     if options.non_interactive == True:
  88.         if os.getuid() != 0:
  89.             print _("Need to be root to install packages")
  90.             sys.exit(1)
  91.         debi.install()
  92.         sys.exit(0)
  93.  
  94.     # show information
  95.     debi.show_dependencies()
  96.     debi.show_description()
  97.     # check if we actually can install it
  98.     if os.getuid() != 0:
  99.         print _("Need to be root to install packages")
  100.         sys.exit(1)
  101.     print _("Do you want to install the software package? [y/N]:"),
  102.     sys.stdout.flush()
  103.     res = sys.stdin.readline()
  104.     # TRANSLATORS: the first char in a "Yes" word
  105.     if res.upper().startswith(_("Y")):
  106.         debi.install()
  107.