home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / hplip / base / g.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  9.4 KB  |  245 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import sys
  5. import os
  6. import os.path as os
  7. import ConfigParser
  8. import locale
  9. import pwd
  10. import stat
  11. from codes import *
  12. import logger
  13. log = logger.Logger('', logger.Logger.LOG_LEVEL_INFO, logger.Logger.LOG_TO_CONSOLE)
  14. log.set_level('info')
  15. MINIMUM_PYQT_MAJOR_VER = 3
  16. MINIMUM_PYQT_MINOR_VER = 8
  17. MINIMUM_QT_MAJOR_VER = 3
  18. MINIMUM_QT_MINOR_VER = 0
  19.  
  20. class Properties(dict):
  21.     
  22.     def __getattr__(self, attr):
  23.         if attr in self.keys():
  24.             return self.__getitem__(attr)
  25.         else:
  26.             return ''
  27.  
  28.     
  29.     def __setattr__(self, attr, val):
  30.         self.__setitem__(attr, val)
  31.  
  32.  
  33. prop = Properties()
  34.  
  35. class ConfigSection(dict):
  36.     
  37.     def __init__(self, section_name, config_obj, filename, *args, **kwargs):
  38.         dict.__setattr__(self, 'section_name', section_name)
  39.         dict.__setattr__(self, 'config_obj', config_obj)
  40.         dict.__setattr__(self, 'filename', filename)
  41.         dict.__init__(self, *args, **kwargs)
  42.  
  43.     
  44.     def __getattr__(self, attr):
  45.         if attr in self.keys():
  46.             return self.__getitem__(attr)
  47.         else:
  48.             return ''
  49.  
  50.     
  51.     def __setattr__(self, option, val):
  52.         self.__setitem__(option, val)
  53.         if not self.config_obj.has_section(self.section_name):
  54.             self.config_obj.add_section(self.section_name)
  55.         
  56.         self.config_obj.set(self.section_name, option, val)
  57.         f = file(self.filename, 'w')
  58.         self.config_obj.write(f)
  59.         f.close()
  60.  
  61.  
  62.  
  63. class Config(dict):
  64.     
  65.     def __init__(self, filename, *args, **kwargs):
  66.         dict.__init__(self, *args, **kwargs)
  67.         dict.__setattr__(self, 'config_obj', ConfigParser.ConfigParser())
  68.         dict.__setattr__(self, 'filename', filename)
  69.         
  70.         try:
  71.             pathmode = os.stat(filename)[stat.ST_MODE]
  72.             if pathmode & 18 != 0:
  73.                 return None
  74.         except (IOError, OSError):
  75.             return None
  76.  
  77.         f = file(filename, 'r')
  78.         self.config_obj.readfp(f)
  79.         f.close()
  80.         for s in self.config_obj.sections():
  81.             opts = []
  82.             for o in self.config_obj.options(s):
  83.                 opts.append((o, self.config_obj.get(s, o)))
  84.             
  85.             self.__setitem__(s, ConfigSection(s, self.config_obj, filename, opts))
  86.         
  87.  
  88.     
  89.     def __getattr__(self, sect):
  90.         if sect not in self.keys():
  91.             self.__setitem__(sect, ConfigSection(sect, self.config_obj, self.filename))
  92.         
  93.         return self.__getitem__(sect)
  94.  
  95.     
  96.     def __setattr__(self, sect, val):
  97.         self.__setitem__(sect, val)
  98.  
  99.  
  100. prop.sys_config_file = '/etc/hp/hplip.conf'
  101. prop.user_config_file = os.path.expanduser('~/.hplip.conf')
  102. sys_cfg = Config(prop.sys_config_file)
  103. user_cfg = Config(prop.user_config_file)
  104.  
  105. try:
  106.     locale.setlocale(locale.LC_ALL, '')
  107. except locale.Error:
  108.     log.error('Unable to set locale.')
  109.     locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
  110.  
  111.  
  112. try:
  113.     (t, prop.encoding) = locale.getdefaultlocale()
  114. except ValueError:
  115.     t = 'en_US'
  116.     prop.encoding = 'ISO8859-1'
  117.  
  118.  
  119. try:
  120.     prop.lang_code = t[:2].lower()
  121. except TypeError:
  122.     prop.lang_code = 'en'
  123.  
  124.  
  125. try:
  126.     prop.hpssd_cfg_port = int(sys_cfg.hpssd.port)
  127. except ValueError:
  128.     prop.hpssd_cfg_port = 0
  129.  
  130. if not sys_cfg.hplip.version:
  131.     pass
  132. prop.version = 'x.x.x'
  133. if not sys_cfg.dirs.home:
  134.     pass
  135. prop.home_dir = os.path.realpath(os.path.normpath(os.getcwd()))
  136. if not sys_cfg.dirs.run:
  137.     pass
  138. prop.run_dir = '/var/run'
  139.  
  140. try:
  141.     prop.hpiod_port = int(file(os.path.join(prop.run_dir, 'hpiod.port'), 'r').read())
  142. except:
  143.     prop.hpiod_port = 0
  144.  
  145.  
  146. try:
  147.     prop.hpssd_port = int(file(os.path.join(prop.run_dir, 'hpssd.port'), 'r').read())
  148. except:
  149.     prop.hpssd_port = 0
  150.  
  151. prop.hpiod_host = 'localhost'
  152. prop.hpssd_host = 'localhost'
  153. prop.username = pwd.getpwuid(os.getuid())[0]
  154. pdb = pwd.getpwnam(prop.username)
  155. prop.userhome = pdb[5]
  156. prop.data_dir = os.path.join(prop.home_dir, 'data')
  157. prop.i18n_dir = os.path.join(prop.home_dir, 'data', 'qm')
  158. prop.image_dir = os.path.join(prop.home_dir, 'data', 'images')
  159. prop.xml_dir = os.path.join(prop.home_dir, 'data', 'xml')
  160. prop.max_message_len = 8192
  161. prop.max_message_read = 65536
  162. prop.read_timeout = 90
  163. prop.ppd_search_path = '/usr/share;/usr/local/share;/usr/lib;/usr/local/lib;/usr/libexec;/opt'
  164. prop.ppd_search_pattern = 'HP-*.ppd.*'
  165. prop.ppd_download_url = 'http://www.linuxprinting.org/ppd-o-matic.cgi'
  166. prop.ppd_file_suffix = '-hpijs.ppd'
  167. prop.errors_file = os.path.join(prop.home_dir, 'data', 'xml', 'errors.xml')
  168. prop.strings_file = os.path.join(prop.home_dir, 'data', 'xml', 'strings.xml')
  169. prop.models_file = os.path.join(prop.home_dir, 'data', 'xml', 'models.xml')
  170. spinner = '\\|/-\\|/-'
  171. spinpos = 0
  172.  
  173. def update_spinner():
  174.     global spinpos
  175.     if sys.stdout.isatty():
  176.         sys.stdout.write('\x08' + spinner[spinpos])
  177.         spinpos = (spinpos + 1) % 8
  178.         sys.stdout.flush()
  179.     
  180.  
  181. ERROR_STRINGS = {
  182.     ERROR_SUCCESS: 'No error',
  183.     ERROR_UNKNOWN_ERROR: 'Unknown error',
  184.     ERROR_DEVICE_NOT_FOUND: 'Device not found',
  185.     ERROR_INVALID_DEVICE_ID: 'Unknown/invalid device-id field',
  186.     ERROR_INVALID_DEVICE_URI: 'Unknown/invalid device-uri field',
  187.     ERROR_INVALID_MSG_TYPE: 'Unknown message type',
  188.     ERROR_INVALID_DATA_ENCODING: 'Unknown data encoding',
  189.     ERROR_INVALID_CHAR_ENCODING: 'Unknown character encoding',
  190.     ERROR_DATA_LENGTH_EXCEEDS_MAX: 'Data length exceeds maximum',
  191.     ERROR_DATA_LENGTH_MISMATCH: "Data length doesn't match length field",
  192.     ERROR_DATA_DIGEST_MISMATCH: "Digest of data doesn't match digest field",
  193.     ERROR_INVALID_JOB_ID: 'Invalid job-id',
  194.     ERROR_DEVICE_IO_ERROR: 'Device I/O error',
  195.     ERROR_STRING_QUERY_FAILED: 'String/error query failed',
  196.     ERROR_QUERY_FAILED: 'Query failed',
  197.     ERROR_GUI_NOT_AVAILABLE: 'hpguid not running',
  198.     ERROR_NO_CUPS_DEVICES_FOUND: 'No CUPS devices found (deprecated)',
  199.     ERROR_NO_PROBED_DEVICES_FOUND: 'No probed devices found',
  200.     ERROR_INVALID_BUS_TYPE: 'Invalid bus type',
  201.     ERROR_BUS_TYPE_CANNOT_BE_PROBED: 'Bus cannot be probed',
  202.     ERROR_DEVICE_BUSY: 'Device busy',
  203.     ERROR_NO_DATA_AVAILABLE: 'No data avaiable',
  204.     ERROR_INVALID_DEVICEID: 'Invalid/missing DeviceID',
  205.     ERROR_INVALID_CUPS_VERSION: 'Invlaid CUPS version',
  206.     ERROR_CUPS_NOT_RUNNING: 'CUPS not running',
  207.     ERROR_DEVICE_STATUS_NOT_AVAILABLE: 'DeviceStatus not available',
  208.     ERROR_DATA_IN_SHORT_READ: 'ChannelDataIn short read',
  209.     ERROR_INVALID_SERVICE_NAME: 'Invalid service name',
  210.     ERROR_INVALID_USER_ERROR_CODE: 'Invalid user level error code',
  211.     ERROR_ERROR_INVALID_CHANNEL_ID: 'Invalid channel-id',
  212.     ERROR_CHANNEL_BUSY: 'Channel busy/in-use',
  213.     ERROR_CHANNEL_CLOSE_FAILED: 'ChannelClose failed. Channel not open',
  214.     ERROR_UNSUPPORTED_BUS_TYPE: 'Unsupported bus type',
  215.     ERROR_DEVICE_DOES_NOT_SUPPORT_OPERATION: 'Device does not support operation',
  216.     ERROR_INTERNAL: 'Unknown internal error',
  217.     ERROR_DEVICE_NOT_OPEN: 'Device not open',
  218.     ERROR_UNABLE_TO_CONTACT_SERVICE: 'Unable to contact service',
  219.     ERROR_UNABLE_TO_BIND_SOCKET: 'Unable to bind to socket',
  220.     ERROR_DEVICEOPEN_FAILED_ONE_DEVICE_ONLY: 'Device open failed - 1 open per session allowed',
  221.     ERROR_DEVICEOPEN_FAILED_DEV_NODE_MOVED: 'Device open failed - device node moved',
  222.     ERROR_TEST_EMAIL_FAILED: 'Email test failed',
  223.     ERROR_INVALID_HOSTNAME: 'Invalid hostname ip address',
  224.     ERROR_INVALID_PORT_NUMBER: 'Invalid JetDirect port number',
  225.     ERROR_INTERFACE_BUSY: 'Interface busy',
  226.     ERROR_NO_CUPS_QUEUE_FOUND_FOR_DEVICE: 'No CUPS queue found for device.',
  227.     ERROR_UNSUPPORTED_MODEL: 'Unsupported printer model.' }
  228.  
  229. class Error(Exception):
  230.     
  231.     def __init__(self, opt = ERROR_INTERNAL):
  232.         self.opt = opt
  233.         self.msg = ERROR_STRINGS.get(opt, ERROR_STRINGS[ERROR_INTERNAL])
  234.         log.debug('Exception: %d (%s)' % (opt, self.msg))
  235.         Exception.__init__(self, self.msg, opt)
  236.  
  237.  
  238.  
  239. try:
  240.     True
  241. except NameError:
  242.     True = 1 == 1
  243.     False = not True
  244.  
  245.