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

Functions

def normcase
 
def isabs
 
def join
 
def split
 
def splitext
 
def splitdrive
 
def dirname
 
def basename
 
def isdir
 
def getsize
 
def getmtime
 
def getatime
 
def islink
 
def isfile
 
def exists
 
def commonprefix
 
def expandvars
 
def expanduser
 
def normpath
 
def walk
 
def abspath
 

Variables

list __all__
 
string norm_error = 'macpath.norm_error: path cannot be normalized'
 
 realpath = abspath
 

Detailed Description

Pathname and path-related operations for the Macintosh.

Function Documentation

def macpath.abspath (   path)
Return an absolute path.

Definition at line 229 of file macpath.py.

References isabs(), join(), and normpath().

230 def abspath(path):
231  """Return an absolute path."""
232  if not isabs(path):
233  path = join(os.getcwd(), path)
234  return normpath(path)
235 
# realpath is a no-op on systems without islink support
def macpath.basename (   s)

Definition at line 93 of file macpath.py.

93 
94 def basename(s): return split(s)[1]
95 
def macpath.commonprefix (   m)

Definition at line 152 of file macpath.py.

153 def commonprefix(m):
154  "Given a list of pathnames, returns the longest common leading component"
155  if not m: return ''
156  prefix = m[0]
157  for item in m:
158  for i in range(len(prefix)):
159  if prefix[:i+1] != item[:i+1]:
160  prefix = prefix[:i]
161  if i == 0: return ''
162  break
163  return prefix
def macpath.dirname (   s)

Definition at line 92 of file macpath.py.

92 
def dirname(s): return split(s)[0]
def macpath.exists (   s)
Return true if the pathname refers to an existing file or directory.

Definition at line 141 of file macpath.py.

142 def exists(s):
143  """Return true if the pathname refers to an existing file or directory."""
144 
145  try:
146  st = os.stat(s)
147  except os.error:
148  return 0
149  return 1
150 
151 # Return the longest prefix of all list elements.
def macpath.expanduser (   path)
Dummy to retain interface-compatibility with other operating systems.

Definition at line 169 of file macpath.py.

170 def expanduser(path):
171  """Dummy to retain interface-compatibility with other operating systems."""
172  return path
def macpath.expandvars (   path)
Dummy to retain interface-compatibility with other operating systems.

Definition at line 164 of file macpath.py.

165 def expandvars(path):
166  """Dummy to retain interface-compatibility with other operating systems."""
167  return path
168 
def macpath.getatime (   filename)
Return the last access time of a file, reported by os.stat().

Definition at line 118 of file macpath.py.

119 def getatime(filename):
120  """Return the last access time of a file, reported by os.stat()."""
121  st = os.stat(filename)
122  return st[ST_ATIME]
123 
def macpath.getmtime (   filename)
Return the last modification time of a file, reported by os.stat().

Definition at line 113 of file macpath.py.

114 def getmtime(filename):
115  """Return the last modification time of a file, reported by os.stat()."""
116  st = os.stat(filename)
117  return st[ST_MTIME]
def macpath.getsize (   filename)
Return the size of a file, reported by os.stat().

Definition at line 108 of file macpath.py.

109 def getsize(filename):
110  """Return the size of a file, reported by os.stat()."""
111  st = os.stat(filename)
112  return st[ST_SIZE]
def macpath.isabs (   s)
Return true if a path is absolute.
On the Mac, relative paths begin with a colon,
but as a special case, paths with no colons at all are also relative.
Anything else is absolute (the string up to the first colon is the
volume name).

Definition at line 17 of file macpath.py.

17 
18 def isabs(s):
19  """Return true if a path is absolute.
20  On the Mac, relative paths begin with a colon,
21  but as a special case, paths with no colons at all are also relative.
22  Anything else is absolute (the string up to the first colon is the
23  volume name)."""
24 
25  return ':' in s and s[0] != ':'
26 
def macpath.isdir (   s)
Return true if the pathname refers to an existing directory.

Definition at line 96 of file macpath.py.

References stat.S_ISDIR().

96 
97 def isdir(s):
98  """Return true if the pathname refers to an existing directory."""
99 
100  try:
101  st = os.stat(s)
102  except os.error:
103  return 0
104  return S_ISDIR(st[ST_MODE])
105 
106 
107 # Get size, mtime, atime of files.
def macpath.isfile (   s)
Return true if the pathname refers to an existing regular file.

Definition at line 131 of file macpath.py.

References stat.S_ISREG().

132 def isfile(s):
133  """Return true if the pathname refers to an existing regular file."""
134 
135  try:
136  st = os.stat(s)
137  except os.error:
138  return 0
139  return S_ISREG(st[ST_MODE])
140 
def macpath.islink (   s)
Return true if the pathname refers to a symbolic link.
Always false on the Mac, until we understand Aliases.)

Definition at line 124 of file macpath.py.

125 def islink(s):
126  """Return true if the pathname refers to a symbolic link.
127  Always false on the Mac, until we understand Aliases.)"""
128 
129  return 0
130 
def macpath.join (   s,
  p 
)

Definition at line 27 of file macpath.py.

References isabs().

27 
28 def join(s, *p):
29  path = s
30  for t in p:
31  if (not s) or isabs(t):
32  path = t
33  continue
34  if t[:1] == ':':
35  t = t[1:]
36  if ':' not in path:
37  path = ':' + path
38  if path[-1:] != ':':
39  path = path + ':'
40  path = path + t
41  return path
42 
def macpath.normcase (   path)

Definition at line 13 of file macpath.py.

13 
14 def normcase(path):
15  return path.lower()
16 
def macpath.normpath (   s)
Normalize a pathname.  Will return the same result for
equivalent paths.

Definition at line 175 of file macpath.py.

References join().

176 def normpath(s):
177  """Normalize a pathname. Will return the same result for
178  equivalent paths."""
179 
180  if ":" not in s:
181  return ":"+s
182 
183  comps = s.split(":")
184  i = 1
185  while i < len(comps)-1:
186  if comps[i] == "" and comps[i-1] != "":
187  if i > 1:
188  del comps[i-1:i+1]
189  i = i - 1
190  else:
191  # best way to handle this is to raise an exception
192  raise norm_error, 'Cannot use :: immediately after volume name'
193  else:
194  i = i + 1
195 
196  s = ":".join(comps)
197 
198  # remove trailing ":" except for ":" and "Volume:"
199  if s[-1] == ":" and len(comps) > 2 and s != ":"*len(s):
200  s = s[:-1]
201  return s
202 
def macpath.split (   s)
Split a pathname into two parts: the directory leading up to the final
bit, and the basename (the filename, without colons, in that directory).
The result (s, t) is such that join(s, t) yields the original argument.

Definition at line 43 of file macpath.py.

43 
44 def split(s):
45  """Split a pathname into two parts: the directory leading up to the final
46  bit, and the basename (the filename, without colons, in that directory).
47  The result (s, t) is such that join(s, t) yields the original argument."""
48 
49  if ':' not in s: return '', s
50  colon = 0
51  for i in range(len(s)):
52  if s[i] == ':': colon = i + 1
53  path, file = s[:colon-1], s[colon:]
54  if path and not ':' in path:
55  path = path + ':'
56  return path, file
57 
def macpath.splitdrive (   p)
Split a pathname into a drive specification and the rest of the
path.  Useful on DOS/Windows/NT; on the Mac, the drive is always
empty (don't use the volume name -- it doesn't have the same
syntactic and semantic oddities as DOS drive letters, such as there
being a separate current directory per drive).

Definition at line 80 of file macpath.py.

80 
81 def splitdrive(p):
82  """Split a pathname into a drive specification and the rest of the
83  path. Useful on DOS/Windows/NT; on the Mac, the drive is always
84  empty (don't use the volume name -- it doesn't have the same
85  syntactic and semantic oddities as DOS drive letters, such as there
86  being a separate current directory per drive)."""
87 
88  return '', p
89 
90 
91 # Short interfaces to split()
def macpath.splitext (   p)
Split a path into root and extension.
The extension is everything starting at the last dot in the last
pathname component; the root is everything before that.
It is always true that root + ext == p.

Definition at line 58 of file macpath.py.

58 
59 def splitext(p):
60  """Split a path into root and extension.
61  The extension is everything starting at the last dot in the last
62  pathname component; the root is everything before that.
63  It is always true that root + ext == p."""
64 
65  root, ext = '', ''
66  for c in p:
67  if c == ':':
68  root, ext = root + ext + c, ''
69  elif c == '.':
70  if ext:
71  root, ext = root + ext, c
72  else:
73  ext = c
74  elif ext:
75  ext = ext + c
76  else:
77  root = root + c
78  return root, ext
79 
def macpath.walk (   top,
  func,
  arg 
)
Directory tree walk with callback function.

For each directory in the directory tree rooted at top (including top
itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
dirname is the name of the directory, and fnames a list of the names of
the files and subdirectories in dirname (excluding '.' and '..').  func
may modify the fnames list in-place (e.g. via del or slice assignment),
and walk will only recurse into the subdirectories whose names remain in
fnames; this can be used to implement a filter, or to impose a specific
order of visiting.  No semantics are defined for, or required of, arg,
beyond that arg is always passed to func.  It can be used, e.g., to pass
a filename pattern, or a mutable object designed to accumulate
statistics.  Passing None for arg is common.

Definition at line 203 of file macpath.py.

References isdir(), and join().

204 def walk(top, func, arg):
205  """Directory tree walk with callback function.
206 
207  For each directory in the directory tree rooted at top (including top
208  itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
209  dirname is the name of the directory, and fnames a list of the names of
210  the files and subdirectories in dirname (excluding '.' and '..'). func
211  may modify the fnames list in-place (e.g. via del or slice assignment),
212  and walk will only recurse into the subdirectories whose names remain in
213  fnames; this can be used to implement a filter, or to impose a specific
214  order of visiting. No semantics are defined for, or required of, arg,
215  beyond that arg is always passed to func. It can be used, e.g., to pass
216  a filename pattern, or a mutable object designed to accumulate
217  statistics. Passing None for arg is common."""
218 
219  try:
220  names = os.listdir(top)
221  except os.error:
222  return
223  func(arg, top, names)
224  for name in names:
225  name = join(top, name)
226  if isdir(name):
227  walk(name, func, arg)
228 

Variable Documentation

list __all__
Initial value:
1 = ["normcase","isabs","join","splitdrive","split","splitext",
2  "basename","dirname","commonprefix","getsize","getmtime",
3  "getatime","islink","exists","isdir","isfile",
4  "walk","expanduser","expandvars","normpath","abspath"]

Definition at line 6 of file macpath.py.

string norm_error = 'macpath.norm_error: path cannot be normalized'

Definition at line 173 of file macpath.py.

realpath = abspath

Definition at line 236 of file macpath.py.