1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """Represents a file or directory on the local host.
19 """
20
21 import os
22 import pickle
23
24 import osh.util
25
26 DIR_MASK = 040000
27 FILE_MASK = 0100000
28 LINK_MASK = 0120000
29 FILE_TYPE_MASK = DIR_MASK | FILE_MASK | LINK_MASK
30
32
33 _os_stat = None
34
35 - def __new__(self, dir, file = None):
36 if file is None:
37 path = dir
38 else:
39 path = os.path.join(dir, file)
40 return str.__new__(self, path)
41
43 self._dir = dir
44 self._file = file
45
50
52 if self._file:
53 return os.path.join(self._dir, self._file)
54 else:
55 return self._dir
56
57 abspath = property(lambda self: os.path.abspath(self),
58 doc = """Absolute path to this file.""")
59 stat = property(lambda self: self._stat(),
60 doc = """Information on this file, as returned by C{os.stat}.""")
61 mode = property(lambda self: self._stat()[0],
62 doc = """mode of this file.""")
63 inode = property(lambda self: self._stat()[1],
64 doc = """inode of this file.""")
65 device = property(lambda self: self._stat()[2],
66 doc = """device of this file.""")
67 links = property(lambda self: self._stat()[3],
68 doc = """ Number of links of this file.""")
69 uid = property(lambda self: self._stat()[4],
70 doc = """Owner of this file.""")
71 gid = property(lambda self: self._stat()[5],
72 doc = """Owning group of this file.""")
73 size = property(lambda self: self._stat()[6],
74 doc = """Size of this file (bytes).""")
75 atime = property(lambda self: self._stat()[7],
76 doc = """Access time of this file.""")
77 mtime = property(lambda self: self._stat()[8],
78 doc = """Modify time of this file.""")
79 ctime = property(lambda self: self._stat()[9],
80 doc = """Change time of this file.""")
81 isdir = property(lambda self: self.mode & FILE_TYPE_MASK == DIR_MASK,
82 doc = """True iff this file is a directory.""")
83 isfile = property(lambda self: self.mode & FILE_TYPE_MASK == FILE_MASK,
84 doc = """True iff this file is neither a directory nor a symlink.""")
85 islink = property(lambda self: self.mode & FILE_TYPE_MASK == LINK_MASK,
86 doc = """True iff this file is a symlink.""")
87