Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
shutil Namespace Reference

Functions

def copyfileobj
 
def copyfile
 
def copymode
 
def copystat
 
def copy
 
def copy2
 
def copytree
 
def rmtree
 

Variables

list __all__
 

Detailed Description

Utility functions for copying files and directory trees.

XXX The functions here don't copy the resource fork or other metadata on Mac.

Function Documentation

def shutil.copy (   src,
  dst 
)
Copy data and mode bits ("cp src dst").

The destination may be a directory.

Definition at line 54 of file shutil.py.

References copyfile(), and copymode().

54 
55 def copy(src, dst):
56  """Copy data and mode bits ("cp src dst").
57 
58  The destination may be a directory.
59 
60  """
61  if os.path.isdir(dst):
62  dst = os.path.join(dst, os.path.basename(src))
63  copyfile(src, dst)
64  copymode(src, dst)
def shutil.copy2 (   src,
  dst 
)
Copy data and all stat info ("cp -p src dst").

The destination may be a directory.

Definition at line 65 of file shutil.py.

References copyfile(), and copystat().

65 
66 def copy2(src, dst):
67  """Copy data and all stat info ("cp -p src dst").
68 
69  The destination may be a directory.
70 
71  """
72  if os.path.isdir(dst):
73  dst = os.path.join(dst, os.path.basename(src))
74  copyfile(src, dst)
75  copystat(src, dst)
76 
def shutil.copyfile (   src,
  dst 
)
Copy data from src to dst

Definition at line 23 of file shutil.py.

References copyfileobj(), and aifc.open().

23 
24 def copyfile(src, dst):
25  """Copy data from src to dst"""
26  fsrc = None
27  fdst = None
28  try:
29  fsrc = open(src, 'rb')
30  fdst = open(dst, 'wb')
31  copyfileobj(fsrc, fdst)
32  finally:
33  if fdst:
34  fdst.close()
35  if fsrc:
36  fsrc.close()
def shutil.copyfileobj (   fsrc,
  fdst,
  length = 16*1024 
)
copy data from file-like object fsrc to file-like object fdst

Definition at line 14 of file shutil.py.

14 
15 def copyfileobj(fsrc, fdst, length=16*1024):
16  """copy data from file-like object fsrc to file-like object fdst"""
17  while 1:
18  buf = fsrc.read(length)
19  if not buf:
20  break
21  fdst.write(buf)
22 
def shutil.copymode (   src,
  dst 
)
Copy mode bits from src to dst

Definition at line 37 of file shutil.py.

References stat.S_IMODE().

37 
38 def copymode(src, dst):
39  """Copy mode bits from src to dst"""
40  if hasattr(os, 'chmod'):
41  st = os.stat(src)
42  mode = stat.S_IMODE(st[stat.ST_MODE])
43  os.chmod(dst, mode)
def shutil.copystat (   src,
  dst 
)
Copy all stat info (mode bits, atime and mtime) from src to dst

Definition at line 44 of file shutil.py.

References stat.S_IMODE().

44 
45 def copystat(src, dst):
46  """Copy all stat info (mode bits, atime and mtime) from src to dst"""
47  st = os.stat(src)
48  mode = stat.S_IMODE(st[stat.ST_MODE])
49  if hasattr(os, 'utime'):
50  os.utime(dst, (st[stat.ST_ATIME], st[stat.ST_MTIME]))
51  if hasattr(os, 'chmod'):
52  os.chmod(dst, mode)
53 
def shutil.copytree (   src,
  dst,
  symlinks = 0 
)
Recursively copy a directory tree using copy2().

The destination directory must not already exist.
Error are reported to standard output.

If the optional symlinks flag is true, symbolic links in the
source tree result in symbolic links in the destination tree; if
it is false, the contents of the files pointed to by symbolic
links are copied.

XXX Consider this example code rather than the ultimate tool.

Definition at line 77 of file shutil.py.

References copy2(), and locale.str().

77 
78 def copytree(src, dst, symlinks=0):
79  """Recursively copy a directory tree using copy2().
80 
81  The destination directory must not already exist.
82  Error are reported to standard output.
83 
84  If the optional symlinks flag is true, symbolic links in the
85  source tree result in symbolic links in the destination tree; if
86  it is false, the contents of the files pointed to by symbolic
87  links are copied.
88 
89  XXX Consider this example code rather than the ultimate tool.
90 
91  """
92  names = os.listdir(src)
93  os.mkdir(dst)
94  for name in names:
95  srcname = os.path.join(src, name)
96  dstname = os.path.join(dst, name)
97  try:
98  if symlinks and os.path.islink(srcname):
99  linkto = os.readlink(srcname)
100  os.symlink(linkto, dstname)
101  elif os.path.isdir(srcname):
102  copytree(srcname, dstname, symlinks)
103  else:
104  copy2(srcname, dstname)
105  # XXX What about devices, sockets etc.?
106  except (IOError, os.error), why:
107  print "Can't copy %s to %s: %s" % (`srcname`, `dstname`, str(why))
def shutil.rmtree (   path,
  ignore_errors = 0,
  onerror = None 
)
Recursively delete a directory tree.

If ignore_errors is set, errors are ignored; otherwise, if
onerror is set, it is called to handle the error; otherwise, an
exception is raised.

Definition at line 108 of file shutil.py.

109 def rmtree(path, ignore_errors=0, onerror=None):
110  """Recursively delete a directory tree.
111 
112  If ignore_errors is set, errors are ignored; otherwise, if
113  onerror is set, it is called to handle the error; otherwise, an
114  exception is raised.
115 
116  """
117  cmdtuples = []
118  _build_cmdtuple(path, cmdtuples)
119  for cmd in cmdtuples:
120  try:
121  apply(cmd[0], (cmd[1],))
122  except:
123  exc = sys.exc_info()
124  if ignore_errors:
125  pass
126  elif onerror:
127  onerror(cmd[0], cmd[1], exc)
128  else:
129  raise exc[0], (exc[1][0], exc[1][1] + ' removing '+cmd[1])
130 
# Helper for rmtree()

Variable Documentation

list __all__
Initial value:
1 = ["copyfileobj","copyfile","copymode","copystat","copy","copy2",
2  "copytree","rmtree"]

Definition at line 11 of file shutil.py.