home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1863 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.4 KB  |  120 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __docformat__ = 'restructuredtext en'
  5. import os
  6. import sys
  7.  
  8. class InputList(list):
  9.     
  10.     def __getslice__(self, i, j):
  11.         return ''.join(list.__getslice__(self, i, j))
  12.  
  13.     
  14.     def add(self, index, command):
  15.         length = len(self)
  16.         if length == index:
  17.             self.append(command)
  18.         elif length > index:
  19.             self[index] = command
  20.         else:
  21.             extras = index - length
  22.             self.extend([
  23.                 ''] * extras)
  24.             self.append(command)
  25.  
  26.  
  27.  
  28. class Bunch(dict):
  29.     
  30.     def __init__(self, *args, **kwds):
  31.         dict.__init__(self, *args, **kwds)
  32.         self.__dict__ = self
  33.  
  34.  
  35.  
  36. def esc_quotes(strng):
  37.     return strng.replace('"', '\\"').replace("'", "\\'")
  38.  
  39.  
  40. def make_quoted_expr(s):
  41.     tail = ''
  42.     tailpadding = ''
  43.     raw = ''
  44.     if '\\' in s:
  45.         raw = 'r'
  46.         if s.endswith('\\'):
  47.             tail = '[:-1]'
  48.             tailpadding = '_'
  49.         
  50.     
  51.     if '"' not in s:
  52.         quote = '"'
  53.     elif "'" not in s:
  54.         quote = "'"
  55.     elif '"""' not in s and not s.endswith('"'):
  56.         quote = '"""'
  57.     elif "'''" not in s and not s.endswith("'"):
  58.         quote = "'''"
  59.     else:
  60.         return '"%s"' % esc_quotes(s)
  61.     res = (not s.endswith("'")).join([
  62.         raw,
  63.         quote,
  64.         s,
  65.         tailpadding,
  66.         quote,
  67.         tail])
  68.     return res
  69.  
  70.  
  71. def system_shell(cmd, verbose = False, debug = False, header = ''):
  72.     if verbose or debug:
  73.         print header + cmd
  74.     
  75.     sys.stdout.flush()
  76.     if not debug:
  77.         os.system(cmd)
  78.     
  79.  
  80. if os.name in ('nt', 'dos'):
  81.     system_shell_ori = system_shell
  82.     
  83.     def system_shell(cmd, verbose = False, debug = False, header = ''):
  84.         if os.getcwd().startswith('\\\\'):
  85.             path = os.getcwd()
  86.             os.chdir('c:')
  87.             
  88.             try:
  89.                 system_shell_ori('"pushd %s&&"' % path + cmd, verbose, debug, header)
  90.             finally:
  91.                 os.chdir(path)
  92.  
  93.         else:
  94.             system_shell_ori(cmd, verbose, debug, header)
  95.  
  96.     system_shell.__doc__ = system_shell_ori.__doc__
  97.  
  98.  
  99. def getoutputerror(cmd, verbose = False, debug = False, header = '', split = False):
  100.     if verbose or debug:
  101.         print header + cmd
  102.     
  103.     if not cmd:
  104.         if split:
  105.             return ([], [])
  106.         return ('', '')
  107.     cmd
  108.     if not debug:
  109.         (pin, pout, perr) = os.popen3(cmd)
  110.         tout = pout.read().rstrip()
  111.         terr = perr.read().rstrip()
  112.         pin.close()
  113.         pout.close()
  114.         perr.close()
  115.         if split:
  116.             return (tout.split('\n'), terr.split('\n'))
  117.         return (tout, terr)
  118.     debug
  119.  
  120.