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 / print < prev    next >
Encoding:
Text File  |  2007-04-04  |  4.1 KB  |  152 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.  
  23. __version__ = '4.0'
  24. __title__ = 'Print Utility'
  25. __doc__ = "A simple front end to 'lp'. Provides a print UI from the Device Manager if kprinter, gtklp, or xpp are not installed."
  26.  
  27. # Std Lib
  28. import sys, os, getopt, re, socket
  29.  
  30. # Local
  31. from base.g import *
  32. from base.msg import *
  33. from base import utils, device
  34. from prnt import cups
  35.  
  36. log.set_module('hp-print')
  37.  
  38. app = None
  39. printdlg = None
  40.  
  41. USAGE = [(__doc__, "", "name", True),
  42.          ("Usage: hp-print [PRINTER|DEVICE-URI] [OPTIONS] [FILE LIST]", "", "summary", True),
  43.          utils.USAGE_ARGS,
  44.          utils.USAGE_DEVICE,
  45.          ("To specify a CUPS printer:", "-P<printer>, -p<printer> or --printer=<printer>", "option", False),
  46.          utils.USAGE_SPACE,
  47.          utils.USAGE_OPTIONS,
  48.          utils.USAGE_LOGGING1, utils.USAGE_LOGGING2, utils.USAGE_LOGGING3,
  49.          utils.USAGE_HELP,
  50.          ("[FILELIST]", "", "heading", False),
  51.          ("Optional list of files:", """Space delimited list of files to print. Files can also be selected for print by adding them to the file list in the UI.""", "option", False),
  52.          utils.USAGE_SPACE,
  53.          utils.USAGE_NOTES,
  54.          utils.USAGE_STD_NOTES1, utils.USAGE_STD_NOTES2, 
  55.          ]
  56.  
  57.  
  58. def usage(typ='text'):
  59.     if typ == 'text':
  60.         utils.log_title(__title__, __version__)
  61.  
  62.     utils.format_text(USAGE, typ, __title__, 'hp-print', __version__)
  63.     sys.exit(0)
  64.  
  65.  
  66. try:
  67.     opts, args = getopt.getopt(sys.argv[1:], 'P:p:d:hl:g',
  68.                                ['printer=', 'device=', 'help', 
  69.                                 'help-rest', 'help-man', 'logging=', 'help-desc'])
  70. except getopt.GetoptError:
  71.     usage()
  72.  
  73. printer_name = None
  74. device_uri = None
  75. log_level = logger.DEFAULT_LOG_LEVEL
  76. bus = 'cups'
  77.  
  78. if os.getenv("HPLIP_DEBUG"):
  79.     log.set_level('debug')
  80.  
  81. for o, a in opts:
  82.     if o in ('-h', '--help'):
  83.         usage()
  84.  
  85.     elif o == '--help-rest':
  86.         usage('rest')
  87.  
  88.     elif o == '--help-man':
  89.         usage('man')
  90.  
  91.     elif o == '--help-desc':
  92.         print __doc__,
  93.         sys.exit(0)
  94.  
  95.     elif o in ('-p', '-P', '--printer'):
  96.         printer_name = a
  97.  
  98.     elif o in ('-d', '--device'):
  99.         device_uri = a
  100.  
  101.     elif o in ('-l', '--logging'):
  102.         log_level = a.lower().strip()
  103.         if not log.set_level(log_level):
  104.             usage()
  105.  
  106.     elif o == '-g':
  107.         log.set_level('debug')
  108.  
  109.  
  110. # Security: Do *not* create files that other users can muck around with
  111. os.umask (0077)
  112.  
  113. utils.log_title(__title__, __version__)
  114.  
  115. # PyQt
  116. if not utils.checkPyQtImport():
  117.     log.error("PyQt/Qt initialization error. Please check install of PyQt/Qt and try again.")
  118.     sys.exit(1)
  119.  
  120. from qt import *
  121. from ui.printerform import PrinterForm
  122.  
  123. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  124. try:
  125.     sock.connect((prop.hpssd_host, prop.hpssd_port))
  126. except socket.error:
  127.     log.error("Unable to connect to HPLIP I/O (hpssd).")
  128.     sys.exit(1)
  129.  
  130. # create the main application object
  131. app = QApplication(sys.argv)
  132.  
  133. printdlg = PrinterForm(sock, bus, device_uri, printer_name, args)
  134. printdlg.show()
  135. app.setMainWidget(printdlg)
  136.  
  137. user_config = os.path.expanduser('~/.hplip.conf')
  138. loc = utils.loadTranslators(app, user_config)
  139.  
  140. try:
  141.     log.debug("Starting GUI loop...")
  142.     app.exec_loop()
  143. except KeyboardInterrupt:
  144.     pass
  145. except:
  146.     log.exception()
  147.  
  148. sock.close()
  149. sys.exit(0)
  150.  
  151.  
  152.