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 / base / g.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-04-29  |  9.9 KB  |  258 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  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 = 14
  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, error_if_not_found = False, *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.             if error_if_not_found:
  76.                 log.warn('Config file %s not found or not readable.' % filename)
  77.             
  78.             return None
  79.  
  80.         log.debug('Reading config file %s' % filename)
  81.         f = file(filename, 'r')
  82.         
  83.         try:
  84.             self.config_obj.readfp(f)
  85.         except:
  86.             log.error('There is an error in the config file: %s' % filename)
  87.             sys.exit(1)
  88.  
  89.         f.close()
  90.         for s in self.config_obj.sections():
  91.             opts = []
  92.             for o in self.config_obj.options(s):
  93.                 opts.append((o, self.config_obj.get(s, o)))
  94.             
  95.             self.__setitem__(s, ConfigSection(s, self.config_obj, filename, opts))
  96.         
  97.  
  98.     
  99.     def __getattr__(self, sect):
  100.         if sect not in self.keys():
  101.             self.__setitem__(sect, ConfigSection(sect, self.config_obj, self.filename))
  102.         
  103.         return self.__getitem__(sect)
  104.  
  105.     
  106.     def __setattr__(self, sect, val):
  107.         self.__setitem__(sect, val)
  108.  
  109.  
  110. prop.sys_config_file = '/etc/hp/hplip.conf'
  111. prop.user_config_file = os.path.expanduser('~/.hplip.conf')
  112. sys_cfg = Config(prop.sys_config_file, True)
  113. user_cfg = Config(prop.user_config_file)
  114.  
  115. try:
  116.     locale.setlocale(locale.LC_ALL, '')
  117. except locale.Error:
  118.     log.error('Unable to set locale.')
  119.  
  120.  
  121. try:
  122.     (t, prop.encoding) = locale.getdefaultlocale()
  123. except ValueError:
  124.     t = 'en_US'
  125.     prop.encoding = 'ISO8859-1'
  126.  
  127.  
  128. try:
  129.     prop.lang_code = t[:2].lower()
  130. except TypeError:
  131.     prop.lang_code = 'en'
  132.  
  133.  
  134. try:
  135.     prop.hpssd_cfg_port = int(sys_cfg.hpssd.port)
  136. except ValueError:
  137.     prop.hpssd_cfg_port = 0
  138.  
  139. if not sys_cfg.hplip.version:
  140.     pass
  141. prop.version = 'x.x.x'
  142. if not sys_cfg.dirs.home:
  143.     pass
  144. prop.home_dir = os.path.realpath(os.path.normpath(os.getcwd()))
  145. if not sys_cfg.dirs.run:
  146.     pass
  147. prop.run_dir = '/var/run'
  148.  
  149. try:
  150.     prop.hpiod_port = int(file(os.path.join(prop.run_dir, 'hpiod.port'), 'r').read())
  151. except:
  152.     prop.hpiod_port = 0
  153.  
  154.  
  155. try:
  156.     prop.hpssd_port = int(file(os.path.join(prop.run_dir, 'hpssd.port'), 'r').read())
  157. except:
  158.     prop.hpssd_port = 0
  159.  
  160. prop.hpiod_host = 'localhost'
  161. prop.hpssd_host = 'localhost'
  162. prop.username = pwd.getpwuid(os.getuid())[0]
  163. pdb = pwd.getpwnam(prop.username)
  164. prop.userhome = pdb[5]
  165. prop.data_dir = os.path.join(prop.home_dir, 'data')
  166. prop.image_dir = os.path.join(prop.home_dir, 'data', 'images')
  167. prop.xml_dir = os.path.join(prop.home_dir, 'data', 'xml')
  168. prop.models_dir = os.path.join(prop.home_dir, 'data', 'models')
  169. prop.max_message_len = 8192
  170. prop.max_message_read = 65536
  171. prop.read_timeout = 90
  172. prop.ppd_search_path = '/usr/share;/usr/local/share;/usr/lib;/usr/local/lib;/usr/libexec;/opt;/usr/lib64'
  173. prop.ppd_search_pattern = 'HP-*.ppd.*'
  174. prop.ppd_download_url = 'http://www.linuxprinting.org/ppd-o-matic.cgi'
  175. prop.ppd_file_suffix = '-hpijs.ppd'
  176. spinner = '\\|/-\\|/-'
  177. spinpos = 0
  178.  
  179. def update_spinner():
  180.     global spinpos
  181.     if log.get_level() != log.LOG_LEVEL_DEBUG and sys.stdout.isatty():
  182.         sys.stdout.write('\x08' + spinner[spinpos])
  183.         spinpos = (spinpos + 1) % 8
  184.         sys.stdout.flush()
  185.     
  186.  
  187.  
  188. def cleanup_spinner():
  189.     if log.get_level() != log.LOG_LEVEL_DEBUG and sys.stdout.isatty():
  190.         sys.stdout.write('\x08 \x08')
  191.         sys.stdout.flush()
  192.     
  193.  
  194. ERROR_STRINGS = {
  195.     ERROR_SUCCESS: 'No error',
  196.     ERROR_UNKNOWN_ERROR: 'Unknown error',
  197.     ERROR_DEVICE_NOT_FOUND: 'Device not found',
  198.     ERROR_INVALID_DEVICE_ID: 'Unknown/invalid device-id field',
  199.     ERROR_INVALID_DEVICE_URI: 'Unknown/invalid device-uri field',
  200.     ERROR_INVALID_MSG_TYPE: 'Unknown message type',
  201.     ERROR_INVALID_DATA_ENCODING: 'Unknown data encoding',
  202.     ERROR_INVALID_CHAR_ENCODING: 'Unknown character encoding',
  203.     ERROR_DATA_LENGTH_EXCEEDS_MAX: 'Data length exceeds maximum',
  204.     ERROR_DATA_LENGTH_MISMATCH: "Data length doesn't match length field",
  205.     ERROR_DATA_DIGEST_MISMATCH: "Digest of data doesn't match digest field",
  206.     ERROR_INVALID_JOB_ID: 'Invalid job-id',
  207.     ERROR_DEVICE_IO_ERROR: 'Device I/O error',
  208.     ERROR_STRING_QUERY_FAILED: 'String/error query failed',
  209.     ERROR_QUERY_FAILED: 'Query failed',
  210.     ERROR_GUI_NOT_AVAILABLE: 'hpguid not running',
  211.     ERROR_NO_CUPS_DEVICES_FOUND: 'No CUPS devices found (deprecated)',
  212.     ERROR_NO_PROBED_DEVICES_FOUND: 'No probed devices found',
  213.     ERROR_INVALID_BUS_TYPE: 'Invalid bus type',
  214.     ERROR_BUS_TYPE_CANNOT_BE_PROBED: 'Bus cannot be probed',
  215.     ERROR_DEVICE_BUSY: 'Device busy',
  216.     ERROR_NO_DATA_AVAILABLE: 'No data avaiable',
  217.     ERROR_INVALID_DEVICEID: 'Invalid/missing DeviceID',
  218.     ERROR_INVALID_CUPS_VERSION: 'Invlaid CUPS version',
  219.     ERROR_CUPS_NOT_RUNNING: 'CUPS not running',
  220.     ERROR_DEVICE_STATUS_NOT_AVAILABLE: 'DeviceStatus not available',
  221.     ERROR_DATA_IN_SHORT_READ: 'ChannelDataIn short read',
  222.     ERROR_INVALID_SERVICE_NAME: 'Invalid service name',
  223.     ERROR_INVALID_USER_ERROR_CODE: 'Invalid user level error code',
  224.     ERROR_ERROR_INVALID_CHANNEL_ID: 'Invalid channel-id',
  225.     ERROR_CHANNEL_BUSY: 'Channel busy/in-use',
  226.     ERROR_CHANNEL_CLOSE_FAILED: 'ChannelClose failed. Channel not open',
  227.     ERROR_UNSUPPORTED_BUS_TYPE: 'Unsupported bus type',
  228.     ERROR_DEVICE_DOES_NOT_SUPPORT_OPERATION: 'Device does not support operation',
  229.     ERROR_INTERNAL: 'Unknown internal error',
  230.     ERROR_DEVICE_NOT_OPEN: 'Device not open',
  231.     ERROR_UNABLE_TO_CONTACT_SERVICE: 'Unable to contact service',
  232.     ERROR_UNABLE_TO_BIND_SOCKET: 'Unable to bind to socket',
  233.     ERROR_DEVICEOPEN_FAILED_ONE_DEVICE_ONLY: 'Device open failed - 1 open per session allowed',
  234.     ERROR_DEVICEOPEN_FAILED_DEV_NODE_MOVED: 'Device open failed - device node moved',
  235.     ERROR_TEST_EMAIL_FAILED: 'Email test failed',
  236.     ERROR_INVALID_HOSTNAME: 'Invalid hostname ip address',
  237.     ERROR_INVALID_PORT_NUMBER: 'Invalid JetDirect port number',
  238.     ERROR_INTERFACE_BUSY: 'Interface busy',
  239.     ERROR_NO_CUPS_QUEUE_FOUND_FOR_DEVICE: 'No CUPS queue found for device.',
  240.     ERROR_UNSUPPORTED_MODEL: 'Unsupported printer model.' }
  241.  
  242. class Error(Exception):
  243.     
  244.     def __init__(self, opt = ERROR_INTERNAL):
  245.         self.opt = opt
  246.         self.msg = ERROR_STRINGS.get(opt, ERROR_STRINGS[ERROR_INTERNAL])
  247.         log.debug('Exception: %d (%s)' % (opt, self.msg))
  248.         Exception.__init__(self, self.msg, opt)
  249.  
  250.  
  251.  
  252. try:
  253.     True
  254. except NameError:
  255.     True = 1 == 1
  256.     False = not True
  257.  
  258.