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 / lib / hplip / toolbox < prev    next >
Encoding:
Text File  |  2007-04-04  |  4.4 KB  |  182 lines

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # (c) Copyright 2003-2007 Hewlett-Packard Development Company, L.P.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  19. #
  20. # Author: Don Welch
  21. #
  22. # Thanks to Henrique M. Holschuh <hmh@debian.org> for various security patches
  23. #
  24.  
  25. __version__ = '9.0'
  26. __title__ = 'HP Device Manager'
  27. __doc__ = "The HP Device Manager (aka Toolbox) for HPLIP supported devices. Provides status, tools, and supplies levels."
  28.  
  29. # Std Lib
  30. import sys
  31. import socket
  32. import os, os.path
  33. import getopt
  34. import signal
  35. import atexit
  36.  
  37. # Local
  38. from base.g import *
  39.  
  40. import base.utils as utils
  41. from base.msg import *
  42.  
  43. log.set_module('hp-toolbox')
  44.  
  45. # UI Forms and PyQt
  46. if not utils.checkPyQtImport():
  47.     log.error("PyQt/Qt initialization error. Please check install of PyQt/Qt and try again.")
  48.     sys.exit(1)
  49.  
  50. from qt import *
  51. from ui.devmgr4 import DevMgr4
  52.  
  53.  
  54. app = None
  55. toolbox  = None
  56.  
  57. USAGE = [(__doc__, "", "name", True),
  58.          ("Usage: hp-toolbox [OPTIONS]", "", "summary", True),
  59.          utils.USAGE_OPTIONS,
  60.          utils.USAGE_LOGGING1, utils.USAGE_LOGGING2, utils.USAGE_LOGGING3,
  61.          utils.USAGE_HELP,
  62.          utils.USAGE_SEEALSO,
  63.          ("hp-info", "", "seealso", False),
  64.          ("hp-clean", "", "seealso", False),
  65.          ("hp-colorcal", "", "seealso", False),
  66.          ("hp-align", "", "seealso", False),
  67.          ("hp-print", "", "seealso", False),
  68.          ("hp-sendfax", "", "seealso", False),
  69.          ("hp-fab", "", "seealso", False),
  70.          ("hp-testpage", "", "seealso", False),
  71.         ]
  72.  
  73. def usage(typ='text'):
  74.     if typ == 'text':
  75.         utils.log_title(__title__, __version__)
  76.  
  77.     utils.format_text(USAGE, typ, __title__, 'hp-toolbox', __version__)
  78.     sys.exit(0)
  79.  
  80. def toolboxCleanup():
  81.     pass
  82.  
  83. def handleEXIT():
  84.     if hpiod_sock is not None:
  85.         hpiod_sock.close()
  86.  
  87.     if hpssd_sock is not None:
  88.         hpssd_sock.close()
  89.  
  90.     try:
  91.         app.quit()
  92.     except:
  93.         pass
  94.  
  95.  
  96. prop.prog = sys.argv[0]
  97.  
  98. try:
  99.     opts, args = getopt.getopt(sys.argv[1:], 'l:hg', 
  100.         ['level=', 'help', 'help-rest', 'help-man', 'help-desc'])
  101.  
  102. except getopt.GetoptError:
  103.     usage()
  104.  
  105. if os.getenv("HPLIP_DEBUG"):
  106.     log.set_level('debug')
  107.  
  108.  
  109. for o, a in opts:
  110.     if o in ('-l', '--logging'):
  111.         log_level = a.lower().strip()
  112.         if not log.set_level(log_level):
  113.             usage()
  114.  
  115.     elif o == '-g':
  116.         log.set_level('debug')
  117.  
  118.     elif o in ('-h', '--help'):
  119.         usage()
  120.  
  121.     elif o == '--help-rest':
  122.         usage('rest')
  123.  
  124.     elif o == '--help-man':
  125.         usage('man')
  126.  
  127.     elif o == '--help-desc':
  128.         print __doc__,
  129.         sys.exit(0)
  130.  
  131.  
  132.  
  133. utils.log_title(__title__, __version__)
  134.  
  135. # Security: Do *not* create files that other users can muck around with
  136. os.umask (0077)
  137.  
  138. # create the main application object
  139. app = QApplication(sys.argv)
  140.  
  141. hpiod_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  142. try:
  143.     hpiod_sock.connect((prop.hpiod_host, prop.hpiod_port))
  144. except socket.error:
  145.     log.error("Unable to connect to HPLIP I/O (hpiod).")
  146.     sys.exit(1)
  147.  
  148. log.debug("Connected to hpiod on %s:%d" % (prop.hpiod_host, prop.hpiod_port))
  149.  
  150. hpssd_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  151. try:
  152.     hpssd_sock.connect((prop.hpssd_host, prop.hpssd_port))
  153. except socket.error:
  154.     log.error("Unable to connect to HPLIP I/O (hpssd).")
  155.     sys.exit(1)
  156.  
  157. log.debug("Connected to hpssd on %s:%d" % (prop.hpssd_host, prop.hpssd_port))
  158.  
  159. toolbox = DevMgr4(hpiod_sock, hpssd_sock, toolboxCleanup, __version__)
  160. app.setMainWidget(toolbox)
  161.  
  162. toolbox.show()
  163.  
  164. atexit.register(handleEXIT)
  165. signal.signal(signal.SIGPIPE, signal.SIG_IGN)
  166.  
  167. user_config = os.path.expanduser('~/.hplip.conf')
  168. loc = utils.loadTranslators(app, user_config)
  169.  
  170. try:
  171.     log.debug("Starting GUI loop...")
  172.     app.exec_loop()
  173. except KeyboardInterrupt:
  174.     pass
  175. except:
  176.     log.exception()
  177.  
  178. handleEXIT()
  179.  
  180. sys.exit(0)
  181.  
  182.