home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / distutils / file_util.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  4.6 KB  |  203 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. __revision__ = '$Id: file_util.py 37828 2004-11-10 22:23:15Z loewis $'
  5. import os
  6. from distutils.errors import DistutilsFileError
  7. from distutils import log
  8. _copy_action = {
  9.     None: 'copying',
  10.     'hard': 'hard linking',
  11.     'sym': 'symbolically linking' }
  12.  
  13. def _copy_file_contents(src, dst, buffer_size = 16384):
  14.     fsrc = None
  15.     fdst = None
  16.     
  17.     try:
  18.         fsrc = open(src, 'rb')
  19.     except os.error:
  20.         (errno, errstr) = None
  21.         raise DistutilsFileError, "could not open '%s': %s" % (src, errstr)
  22.     
  23.  
  24.     if os.path.exists(dst):
  25.         
  26.         try:
  27.             os.unlink(dst)
  28.         except os.error:
  29.             (errno, errstr) = None
  30.             raise DistutilsFileError, "could not delete '%s': %s" % (dst, errstr)
  31.         except:
  32.             None<EXCEPTION MATCH>os.error
  33.         
  34.  
  35.     None<EXCEPTION MATCH>os.error
  36.     
  37.     try:
  38.         fdst = open(dst, 'wb')
  39.     except os.error:
  40.         (errno, errstr) = None
  41.         raise DistutilsFileError, "could not create '%s': %s" % (dst, errstr)
  42.  
  43.     while None:
  44.         
  45.         try:
  46.             buf = fsrc.read(buffer_size)
  47.         except os.error:
  48.             (errno, errstr) = None
  49.             raise DistutilsFileError, "could not read from '%s': %s" % (src, errstr)
  50.  
  51.         if not buf:
  52.             break
  53.         
  54.         
  55.         try:
  56.             fdst.write(buf)
  57.         continue
  58.         except os.error:
  59.             (errno, errstr) = None
  60.             raise DistutilsFileError, "could not write to '%s': %s" % (dst, errstr)
  61.             continue
  62.         
  63.  
  64.     if fsrc:
  65.         fsrc.close()
  66.     
  67.  
  68.  
  69. def copy_file(src, dst, preserve_mode = 1, preserve_times = 1, update = 0, link = None, verbose = 0, dry_run = 0):
  70.     newer = newer
  71.     import distutils.dep_util
  72.     ST_ATIME = ST_ATIME
  73.     ST_MTIME = ST_MTIME
  74.     ST_MODE = ST_MODE
  75.     S_IMODE = S_IMODE
  76.     import stat
  77.     if not os.path.isfile(src):
  78.         raise DistutilsFileError, "can't copy '%s': doesn't exist or not a regular file" % src
  79.     os.path.isfile(src)
  80.     if os.path.isdir(dst):
  81.         dir = dst
  82.         dst = os.path.join(dst, os.path.basename(src))
  83.     else:
  84.         dir = os.path.dirname(dst)
  85.     if update and not newer(src, dst):
  86.         log.debug('not copying %s (output up-to-date)', src)
  87.         return (dst, 0)
  88.     
  89.     try:
  90.         action = _copy_action[link]
  91.     except KeyError:
  92.         not newer(src, dst)
  93.         not newer(src, dst)
  94.         raise ValueError, "invalid value '%s' for 'link' argument" % link
  95.     except:
  96.         not newer(src, dst)
  97.  
  98.     if os.path.basename(dst) == os.path.basename(src):
  99.         log.info('%s %s -> %s', action, src, dir)
  100.     else:
  101.         log.info('%s %s -> %s', action, src, dst)
  102.     if dry_run:
  103.         return (dst, 1)
  104.     if os.name == 'mac':
  105.         import macostools
  106.         
  107.         try:
  108.             macostools.copy(src, dst, 0, preserve_times)
  109.         except os.error:
  110.             dry_run
  111.             exc = dry_run
  112.             raise DistutilsFileError, "could not copy '%s' to '%s': %s" % (src, dst, exc[-1])
  113.         except:
  114.             dry_run<EXCEPTION MATCH>os.error
  115.         
  116.  
  117.     dry_run
  118.     if link == 'hard':
  119.         if not os.path.exists(dst) and os.path.samefile(src, dst):
  120.             os.link(src, dst)
  121.         
  122.     elif link == 'sym':
  123.         if not os.path.exists(dst) and os.path.samefile(src, dst):
  124.             os.symlink(src, dst)
  125.         
  126.     else:
  127.         _copy_file_contents(src, dst)
  128.         if preserve_mode or preserve_times:
  129.             st = os.stat(src)
  130.             if preserve_times:
  131.                 os.utime(dst, (st[ST_ATIME], st[ST_MTIME]))
  132.             
  133.             if preserve_mode:
  134.                 os.chmod(dst, S_IMODE(st[ST_MODE]))
  135.             
  136.         
  137.     return (dst, 1)
  138.  
  139.  
  140. def move_file(src, dst, verbose = 0, dry_run = 0):
  141.     exists = exists
  142.     isfile = isfile
  143.     isdir = isdir
  144.     basename = basename
  145.     dirname = dirname
  146.     import os.path
  147.     import errno
  148.     log.info('moving %s -> %s', src, dst)
  149.     if dry_run:
  150.         return dst
  151.     if not isfile(src):
  152.         raise DistutilsFileError, "can't move '%s': not a regular file" % src
  153.     isfile(src)
  154.     if isdir(dst):
  155.         dst = os.path.join(dst, basename(src))
  156.     elif exists(dst):
  157.         raise DistutilsFileError, "can't move '%s': destination '%s' already exists" % (src, dst)
  158.     
  159.     if not isdir(dirname(dst)):
  160.         raise DistutilsFileError, "can't move '%s': destination '%s' not a valid path" % (src, dst)
  161.     isdir(dirname(dst))
  162.     copy_it = 0
  163.     
  164.     try:
  165.         os.rename(src, dst)
  166.     except os.error:
  167.         (num, msg) = None
  168.         if num == errno.EXDEV:
  169.             copy_it = 1
  170.         else:
  171.             raise DistutilsFileError, "couldn't move '%s' to '%s': %s" % (src, dst, msg)
  172.         num == errno.EXDEV
  173.  
  174.     if copy_it:
  175.         copy_file(src, dst)
  176.         
  177.         try:
  178.             os.unlink(src)
  179.         except os.error:
  180.             (num, msg) = None
  181.             
  182.             try:
  183.                 os.unlink(dst)
  184.             except os.error:
  185.                 pass
  186.  
  187.             raise DistutilsFileError, ("couldn't move '%s' to '%s' by copy/delete: " + "delete '%s' failed: %s") % (src, dst, src, msg)
  188.         except:
  189.             None<EXCEPTION MATCH>os.error
  190.         
  191.  
  192.     None<EXCEPTION MATCH>os.error
  193.     return dst
  194.  
  195.  
  196. def write_file(filename, contents):
  197.     f = open(filename, 'w')
  198.     for line in contents:
  199.         f.write(line + '\n')
  200.     
  201.     f.close()
  202.  
  203.