Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3bb710d

Browse files
committed
updated again
1 parent c8b4791 commit 3bb710d

4 files changed

Lines changed: 98 additions & 62 deletions

File tree

Lib/dos-8x3/posixfil.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,25 @@ def lock(self, how, *args):
174174
elif len(args) > 3:
175175
raise TypeError, 'too many arguments'
176176

177-
flock = struct.pack('hhllhh', l_type, l_whence, l_start, l_len, 0, 0)
177+
# Hack by [email protected] to get locking to go on freebsd
178+
import sys, os
179+
if sys.platform == 'freebsd2':
180+
flock = struct.pack('lxxxxlxxxxlhh', \
181+
l_start, l_len, os.getpid(), l_type, l_whence)
182+
else:
183+
flock = struct.pack('hhllhh', \
184+
l_type, l_whence, l_start, l_len, 0, 0)
185+
178186
flock = fcntl.fcntl(self._file_.fileno(), cmd, flock)
179187

180188
if '?' in how:
181-
l_type, l_whence, l_start, l_len, l_sysid, l_pid = \
182-
struct.unpack('hhllhh', flock)
189+
if sys.platform == 'freebsd2':
190+
l_start, l_len, l_pid, l_type, l_whence = \
191+
struct.unpack('lxxxxlxxxxlhh', flock)
192+
else:
193+
l_type, l_whence, l_start, l_len, l_sysid, l_pid = \
194+
struct.unpack('hhllhh', flock)
195+
183196
if l_type != FCNTL.F_UNLCK:
184197
if l_type == FCNTL.F_RDLCK:
185198
return 'r', l_len, l_start, l_whence, l_pid

Lib/dos-8x3/posixpat.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
# Module 'posixpath' -- common operations on POSIX pathnames
2-
3-
import posix
1+
# Module 'posixpath' -- common operations on Posix pathnames.
2+
# Some of this can actually be useful on non-Posix systems too, e.g.
3+
# for manipulation of the pathname component of URLs.
4+
# The "os.path" name is an alias for this module on Posix systems;
5+
# on other systems (e.g. Mac, Windows), os.path provides the same
6+
# operations in a manner specific to that platform, and is an alias
7+
# to another module (e.g. macpath, ntpath).
8+
9+
import os
410
import stat
511

612

@@ -102,12 +108,12 @@ def commonprefix(m):
102108

103109

104110
# Is a path a symbolic link?
105-
# This will always return false on systems where posix.lstat doesn't exist.
111+
# This will always return false on systems where os.lstat doesn't exist.
106112

107113
def islink(path):
108114
try:
109-
st = posix.lstat(path)
110-
except (posix.error, AttributeError):
115+
st = os.lstat(path)
116+
except (os.error, AttributeError):
111117
return 0
112118
return stat.S_ISLNK(st[stat.ST_MODE])
113119

@@ -117,20 +123,20 @@ def islink(path):
117123

118124
def exists(path):
119125
try:
120-
st = posix.stat(path)
121-
except posix.error:
126+
st = os.stat(path)
127+
except os.error:
122128
return 0
123129
return 1
124130

125131

126-
# Is a path a posix directory?
132+
# Is a path a directory?
127133
# This follows symbolic links, so both islink() and isdir() can be true
128134
# for the same path.
129135

130136
def isdir(path):
131137
try:
132-
st = posix.stat(path)
133-
except posix.error:
138+
st = os.stat(path)
139+
except os.error:
134140
return 0
135141
return stat.S_ISDIR(st[stat.ST_MODE])
136142

@@ -141,27 +147,26 @@ def isdir(path):
141147

142148
def isfile(path):
143149
try:
144-
st = posix.stat(path)
145-
except posix.error:
150+
st = os.stat(path)
151+
except os.error:
146152
return 0
147153
return stat.S_ISREG(st[stat.ST_MODE])
148154

149155

150156
# Are two filenames really pointing to the same file?
151157

152158
def samefile(f1, f2):
153-
s1 = posix.stat(f1)
154-
s2 = posix.stat(f2)
159+
s1 = os.stat(f1)
160+
s2 = os.stat(f2)
155161
return samestat(s1, s2)
156162

157163

158164
# Are two open files really referencing the same file?
159165
# (Not necessarily the same file descriptor!)
160-
# XXX Oops, posix.fstat() doesn't exist yet!
161166

162167
def sameopenfile(fp1, fp2):
163-
s1 = posix.fstat(fp1)
164-
s2 = posix.fstat(fp2)
168+
s1 = os.fstat(fp1)
169+
s2 = os.fstat(fp2)
165170
return samestat(s1, s2)
166171

167172

@@ -174,13 +179,13 @@ def samestat(s1, s2):
174179

175180

176181
# Is a path a mount point?
177-
# (Does this work for all UNIXes? Is it even guaranteed to work by POSIX?)
182+
# (Does this work for all UNIXes? Is it even guaranteed to work by Posix?)
178183

179184
def ismount(path):
180185
try:
181-
s1 = posix.stat(path)
182-
s2 = posix.stat(join(path, '..'))
183-
except posix.error:
186+
s1 = os.stat(path)
187+
s2 = os.stat(join(path, '..'))
188+
except os.error:
184189
return 0 # It doesn't exist -- so not a mount point :-)
185190
dev1 = s1[stat.ST_DEV]
186191
dev2 = s2[stat.ST_DEV]
@@ -203,8 +208,8 @@ def ismount(path):
203208

204209
def walk(top, func, arg):
205210
try:
206-
names = posix.listdir(top)
207-
except posix.error:
211+
names = os.listdir(top)
212+
except os.error:
208213
return
209214
func(arg, top, names)
210215
exceptions = ('.', '..')
@@ -231,9 +236,9 @@ def expanduser(path):
231236
while i < n and path[i] <> '/':
232237
i = i+1
233238
if i == 1:
234-
if not posix.environ.has_key('HOME'):
239+
if not os.environ.has_key('HOME'):
235240
return path
236-
userhome = posix.environ['HOME']
241+
userhome = os.environ['HOME']
237242
else:
238243
import pwd
239244
try:
@@ -267,9 +272,9 @@ def expandvars(path):
267272
j = i + len(_varprog.group(0))
268273
if name[:1] == '{' and name[-1:] == '}':
269274
name = name[1:-1]
270-
if posix.environ.has_key(name):
275+
if os.environ.has_key(name):
271276
tail = path[j:]
272-
path = path[:i] + posix.environ[name]
277+
path = path[:i] + os.environ[name]
273278
i = len(path)
274279
path = path + tail
275280
else:

Lib/dos_8x3/posixfil.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,25 @@ def lock(self, how, *args):
174174
elif len(args) > 3:
175175
raise TypeError, 'too many arguments'
176176

177-
flock = struct.pack('hhllhh', l_type, l_whence, l_start, l_len, 0, 0)
177+
# Hack by [email protected] to get locking to go on freebsd
178+
import sys, os
179+
if sys.platform == 'freebsd2':
180+
flock = struct.pack('lxxxxlxxxxlhh', \
181+
l_start, l_len, os.getpid(), l_type, l_whence)
182+
else:
183+
flock = struct.pack('hhllhh', \
184+
l_type, l_whence, l_start, l_len, 0, 0)
185+
178186
flock = fcntl.fcntl(self._file_.fileno(), cmd, flock)
179187

180188
if '?' in how:
181-
l_type, l_whence, l_start, l_len, l_sysid, l_pid = \
182-
struct.unpack('hhllhh', flock)
189+
if sys.platform == 'freebsd2':
190+
l_start, l_len, l_pid, l_type, l_whence = \
191+
struct.unpack('lxxxxlxxxxlhh', flock)
192+
else:
193+
l_type, l_whence, l_start, l_len, l_sysid, l_pid = \
194+
struct.unpack('hhllhh', flock)
195+
183196
if l_type != FCNTL.F_UNLCK:
184197
if l_type == FCNTL.F_RDLCK:
185198
return 'r', l_len, l_start, l_whence, l_pid

Lib/dos_8x3/posixpat.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
# Module 'posixpath' -- common operations on POSIX pathnames
2-
3-
import posix
1+
# Module 'posixpath' -- common operations on Posix pathnames.
2+
# Some of this can actually be useful on non-Posix systems too, e.g.
3+
# for manipulation of the pathname component of URLs.
4+
# The "os.path" name is an alias for this module on Posix systems;
5+
# on other systems (e.g. Mac, Windows), os.path provides the same
6+
# operations in a manner specific to that platform, and is an alias
7+
# to another module (e.g. macpath, ntpath).
8+
9+
import os
410
import stat
511

612

@@ -102,12 +108,12 @@ def commonprefix(m):
102108

103109

104110
# Is a path a symbolic link?
105-
# This will always return false on systems where posix.lstat doesn't exist.
111+
# This will always return false on systems where os.lstat doesn't exist.
106112

107113
def islink(path):
108114
try:
109-
st = posix.lstat(path)
110-
except (posix.error, AttributeError):
115+
st = os.lstat(path)
116+
except (os.error, AttributeError):
111117
return 0
112118
return stat.S_ISLNK(st[stat.ST_MODE])
113119

@@ -117,20 +123,20 @@ def islink(path):
117123

118124
def exists(path):
119125
try:
120-
st = posix.stat(path)
121-
except posix.error:
126+
st = os.stat(path)
127+
except os.error:
122128
return 0
123129
return 1
124130

125131

126-
# Is a path a posix directory?
132+
# Is a path a directory?
127133
# This follows symbolic links, so both islink() and isdir() can be true
128134
# for the same path.
129135

130136
def isdir(path):
131137
try:
132-
st = posix.stat(path)
133-
except posix.error:
138+
st = os.stat(path)
139+
except os.error:
134140
return 0
135141
return stat.S_ISDIR(st[stat.ST_MODE])
136142

@@ -141,27 +147,26 @@ def isdir(path):
141147

142148
def isfile(path):
143149
try:
144-
st = posix.stat(path)
145-
except posix.error:
150+
st = os.stat(path)
151+
except os.error:
146152
return 0
147153
return stat.S_ISREG(st[stat.ST_MODE])
148154

149155

150156
# Are two filenames really pointing to the same file?
151157

152158
def samefile(f1, f2):
153-
s1 = posix.stat(f1)
154-
s2 = posix.stat(f2)
159+
s1 = os.stat(f1)
160+
s2 = os.stat(f2)
155161
return samestat(s1, s2)
156162

157163

158164
# Are two open files really referencing the same file?
159165
# (Not necessarily the same file descriptor!)
160-
# XXX Oops, posix.fstat() doesn't exist yet!
161166

162167
def sameopenfile(fp1, fp2):
163-
s1 = posix.fstat(fp1)
164-
s2 = posix.fstat(fp2)
168+
s1 = os.fstat(fp1)
169+
s2 = os.fstat(fp2)
165170
return samestat(s1, s2)
166171

167172

@@ -174,13 +179,13 @@ def samestat(s1, s2):
174179

175180

176181
# Is a path a mount point?
177-
# (Does this work for all UNIXes? Is it even guaranteed to work by POSIX?)
182+
# (Does this work for all UNIXes? Is it even guaranteed to work by Posix?)
178183

179184
def ismount(path):
180185
try:
181-
s1 = posix.stat(path)
182-
s2 = posix.stat(join(path, '..'))
183-
except posix.error:
186+
s1 = os.stat(path)
187+
s2 = os.stat(join(path, '..'))
188+
except os.error:
184189
return 0 # It doesn't exist -- so not a mount point :-)
185190
dev1 = s1[stat.ST_DEV]
186191
dev2 = s2[stat.ST_DEV]
@@ -203,8 +208,8 @@ def ismount(path):
203208

204209
def walk(top, func, arg):
205210
try:
206-
names = posix.listdir(top)
207-
except posix.error:
211+
names = os.listdir(top)
212+
except os.error:
208213
return
209214
func(arg, top, names)
210215
exceptions = ('.', '..')
@@ -231,9 +236,9 @@ def expanduser(path):
231236
while i < n and path[i] <> '/':
232237
i = i+1
233238
if i == 1:
234-
if not posix.environ.has_key('HOME'):
239+
if not os.environ.has_key('HOME'):
235240
return path
236-
userhome = posix.environ['HOME']
241+
userhome = os.environ['HOME']
237242
else:
238243
import pwd
239244
try:
@@ -267,9 +272,9 @@ def expandvars(path):
267272
j = i + len(_varprog.group(0))
268273
if name[:1] == '{' and name[-1:] == '}':
269274
name = name[1:-1]
270-
if posix.environ.has_key(name):
275+
if os.environ.has_key(name):
271276
tail = path[j:]
272-
path = path[:i] + posix.environ[name]
277+
path = path[:i] + os.environ[name]
273278
i = len(path)
274279
path = path + tail
275280
else:

0 commit comments

Comments
 (0)