home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / hplip / unload < prev   
Encoding:
Text File  |  2006-08-30  |  4.3 KB  |  163 lines

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # (c) Copyright 2003-2006 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.  
  24. __version__ = '1.9'
  25. __title__ = 'Photo Card Access Utility'
  26. __doc__ = "Access inserted photo cards on supported HPLIP printers. This provides an alternative for older devices that do not support USB mass storage or for access to photo cards over a network. (GUI version)"
  27.  
  28. # Std Lib
  29. import sys
  30. import getopt
  31.  
  32. # Local
  33. from base.g import *
  34. from base import utils, device
  35. from prnt import cups
  36.  
  37. use_qt_splashscreen = False
  38.  
  39.  
  40. USAGE = [(__doc__, "", "name", True),
  41.          ("Usage: hp-unload [PRINTER|DEVICE-URI] [OPTIONS]", "", "summary", True),
  42.          utils.USAGE_ARGS,
  43.          utils.USAGE_DEVICE,
  44.          utils.USAGE_PRINTER,
  45.          utils.USAGE_SPACE,
  46.          utils.USAGE_OPTIONS,
  47.          utils.USAGE_BUS1, utils.USAGE_BUS2,
  48.          utils.USAGE_LOGGING1, utils.USAGE_LOGGING2, utils.USAGE_LOGGING3,
  49.          utils.USAGE_HELP,
  50.          utils.USAGE_SPACE,
  51.          utils.USAGE_NOTES,
  52.          utils.USAGE_STD_NOTES1, utils.USAGE_STD_NOTES2, 
  53.          utils.USAGE_SEEALSO,
  54.          ("hp-photo", "", "seealso", False),
  55.          ]
  56.          
  57. def usage(typ='text'):
  58.     if typ == 'text':
  59.         utils.log_title(__title__, __version__)
  60.         
  61.     utils.format_text(USAGE, typ, __title__, 'hp-unload', __version__)
  62.     sys.exit(0)
  63.  
  64. def __tr(s,c = None):
  65.     return qApp.translate("Unload",s,c)
  66.     
  67.  
  68. # PyQt
  69. if not utils.checkPyQtImport():
  70.     log.error("PyQt/Qt initialization error. Please check install of PyQt/Qt and try again.")
  71.     sys.exit(1)
  72.  
  73. from qt import *
  74. from ui import unloadform
  75.  
  76. try:
  77.     opts, args = getopt.getopt(sys.argv[1:],
  78.                                 'p:d:hl:b:g',
  79.                                 ['printer=',
  80.                                   'device=',
  81.                                   'help', 'help-rest', 'help-man',
  82.                                   'logging=',
  83.                                   'bus='
  84.                                 ]
  85.                               )
  86. except getopt.GetoptError:
  87.     usage()
  88.  
  89. if os.getenv("HPLIP_DEBUG"):
  90.     log.set_level('debug')
  91.  
  92. printer_name = None
  93. device_uri = None
  94. bus = device.DEFAULT_PROBE_BUS
  95. log_level = logger.DEFAULT_LOG_LEVEL
  96.  
  97.  
  98. for o, a in opts:
  99.  
  100.     if o in ('-h', '--help'):
  101.         usage()
  102.         
  103.     elif o == '--help-rest':
  104.         usage('rest')
  105.     
  106.     elif o == '--help-man':
  107.         usage('man')
  108.  
  109.     elif o in ('-p', '--printer'):
  110.         if a.startswith('*'):
  111.             printer_name = cups.getDefault()
  112.         else:
  113.             printer_name = a
  114.  
  115.     elif o in ('-d', '--device'):
  116.         device_uri = a
  117.  
  118.     elif o in ('-b', '--bus'):
  119.         bus = a.lower().strip()
  120.         if not device.validateBusList(bus):
  121.             usage()
  122.  
  123.     elif o in ('-l', '--logging'):
  124.         log_level = a.lower().strip()
  125.         if not log.set_level(log_level):
  126.             usage()
  127.             
  128.     elif o == '-g':
  129.         log.set_level('debug')
  130.  
  131.     
  132. utils.log_title(__title__, __version__)
  133.             
  134.  
  135. #try:
  136. if 1:
  137.     a = QApplication(sys.argv)
  138.     QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))
  139.  
  140.     if use_qt_splashscreen:
  141.         pixmap = QPixmap(os.path.join(prop.image_dir, "hp-tux-printer.png"))
  142.         splash = QSplashScreen(pixmap)
  143.         splash.message(__tr("Loading..."), Qt.AlignBottom)
  144.         splash.show()
  145.  
  146.     try:
  147.         w = unloadform.UnloadForm(bus, device_uri, printer_name)
  148.     except Error:
  149.         log.error("Unable to connect to HPLIP I/O. Please (re)start HPLIP and try again.")
  150.         sys.exit(1)
  151.         
  152.     a.setMainWidget(w)
  153.     w.show()
  154.  
  155.     if use_qt_splashscreen:
  156.         splash.finish(w)
  157.  
  158.     a.exec_loop()
  159. #except Exception, e:
  160.     #log.exception()
  161.  
  162.  
  163.