home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / python2.4 / site-packages / debconf.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  5.2 KB  |  174 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. import sys
  5. import os
  6. import errno
  7. import re
  8. import popen2
  9. import fcntl
  10.  
  11. class DebconfError(Exception):
  12.     pass
  13.  
  14. (LOW, MEDIUM, HIGH, CRITICAL) = ('low', 'medium', 'high', 'critical')
  15.  
  16. class Debconf:
  17.     
  18.     def __init__(self, title = None, read = None, write = None):
  19.         for command in 'capb set reset title input beginblock endblock go get register unregister subst fset fget previous_module visible purge metaget exist version settitle info progress'.split():
  20.             self.setCommand(command)
  21.         
  22.         if not read:
  23.             pass
  24.         self.read = sys.stdin
  25.         if not write:
  26.             pass
  27.         self.write = sys.stdout
  28.         sys.stdout = sys.stderr
  29.         self.setUp(title)
  30.  
  31.     
  32.     def setUp(self, title):
  33.         self.version = self.version(2)
  34.         if self.version[:2] != '2.':
  35.             raise DebconfError(256, 'wrong version: %s' % self.version)
  36.         
  37.         self.capabilities = self.capb().split()
  38.         if title:
  39.             self.title(title)
  40.         
  41.  
  42.     
  43.     def setCommand(self, command):
  44.         setattr(self, command, (lambda : self.command(command, *args, **kw)))
  45.  
  46.     
  47.     def command(self, command, *params):
  48.         command = command.upper()
  49.         self.write.write('%s %s\n' % (command, ' '.join(map(str, params))))
  50.         self.write.flush()
  51.         while True:
  52.             
  53.             try:
  54.                 resp = self.read.readline().rstrip('\n')
  55.             continue
  56.             except IOError:
  57.                 e = None
  58.                 if e.errno == errno.EINTR:
  59.                     continue
  60.                 else:
  61.                     raise 
  62.                 e.errno == errno.EINTR
  63.             
  64.  
  65.             None<EXCEPTION MATCH>IOError
  66.         if ' ' in resp:
  67.             (status, data) = resp.split(' ', 1)
  68.         else:
  69.             status = resp
  70.             data = ''
  71.         status = int(status)
  72.         if status == 0:
  73.             return data
  74.         elif status == 1:
  75.             unescaped = ''
  76.             for chunk in re.split('(\\\\.)', data):
  77.                 if chunk.startswith('\\') and len(chunk) == 2:
  78.                     if chunk[1] == 'n':
  79.                         unescaped += '\n'
  80.                     else:
  81.                         unescaped += chunk[1]
  82.                 chunk[1] == 'n'
  83.                 unescaped += chunk
  84.             
  85.             return unescaped
  86.         else:
  87.             raise DebconfError(status, data)
  88.  
  89.     
  90.     def stop(self):
  91.         self.write.write('STOP\n')
  92.         self.write.flush()
  93.  
  94.     
  95.     def forceInput(self, priority, question):
  96.         
  97.         try:
  98.             self.input(priority, question)
  99.             return 1
  100.         except DebconfError:
  101.             e = None
  102.             if e.args[0] != 30:
  103.                 raise 
  104.             
  105.         except:
  106.             e.args[0] != 30
  107.  
  108.         return 0
  109.  
  110.     
  111.     def getBoolean(self, question):
  112.         result = self.get(question)
  113.         return result == 'true'
  114.  
  115.     
  116.     def getString(self, question):
  117.         return self.get(question)
  118.  
  119.  
  120.  
  121. class DebconfCommunicator(Debconf, object):
  122.     
  123.     def __init__(self, owner, title = None, cloexec = False):
  124.         self.dccomm = popen2.Popen3([
  125.             'debconf-communicate',
  126.             '-fnoninteractive',
  127.             owner])
  128.         super(DebconfCommunicator, self).__init__(title = title, read = self.dccomm.fromchild, write = self.dccomm.tochild)
  129.         if cloexec:
  130.             fcntl.fcntl(self.read.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)
  131.             fcntl.fcntl(self.write.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)
  132.         
  133.  
  134.     
  135.     def shutdown(self):
  136.         if self.dccomm is not None:
  137.             self.dccomm.tochild.close()
  138.             self.dccomm.fromchild.close()
  139.             self.dccomm.wait()
  140.             self.dccomm = None
  141.         
  142.  
  143.     
  144.     def __del__(self):
  145.         self.shutdown()
  146.  
  147.  
  148. if 'DEBCONF_USE_CDEBCONF' in os.environ and os.environ['DEBCONF_USE_CDEBCONF'] != '':
  149.     _frontEndProgram = '/usr/lib/cdebconf/debconf'
  150. else:
  151.     _frontEndProgram = '/usr/share/debconf/frontend'
  152.  
  153. def runFrontEnd():
  154.     if not os.environ.has_key('DEBIAN_HAS_FRONTEND'):
  155.         os.environ['PERL_DL_NONLAZY'] = '1'
  156.         os.execv(_frontEndProgram, [
  157.             _frontEndProgram,
  158.             sys.executable] + sys.argv)
  159.     
  160.  
  161. if __name__ == '__main__':
  162.     runFrontEnd()
  163.     db = Debconf()
  164.     db.forceInput(CRITICAL, 'bsdmainutils/calendar_lib_is_not_empty')
  165.     db.go()
  166.     less = db.getBoolean('less/add_mime_handler')
  167.     aptlc = db.getString('apt-listchanges/email-address')
  168.     db.stop()
  169.     print db.version
  170.     print db.capabilities
  171.     print less
  172.     print aptlc
  173.  
  174.