126
126
mime_dirlisting = "text/plain"
127
127
#mime_dirlisting = "application/json"
129
# Indicates that a directory is unversioned
130
class UnversionedDir(Exception):
129
133
def handle_return(req, return_contents):
131
135
Perform the "return" part of the response.
251
253
# Start by trying to do an SVN status, so we can report file version
256
svnclient.exception_style = 1 # Get rich exceptions
256
259
ls_list = svnclient.list(path, revision=revision, recurse=False)
257
260
for ls in ls_list:
258
261
filename, attrs = PysvnList_to_fileinfo(path, ls)
259
listing[filename.decode('utf-8')] = attrs
262
if isinstance(filename, str): # Expect a unicode from pysvn
263
filename = filename.decode('utf-8')
264
listing[filename] = attrs
261
266
status_list = svnclient.status(path, recurse=False, get_all=True,
263
268
for status in status_list:
264
269
filename, attrs = PysvnStatus_to_fileinfo(path, status)
265
listing[filename.decode('utf-8')] = attrs
266
except pysvn.ClientError:
267
# Presumably the directory is not under version control.
270
if isinstance(filename, str): # Expect a unicode from pysvn
271
filename = filename.decode('utf-8')
272
listing[filename] = attrs
273
except (pysvn.ClientError, UnversionedDir), e:
274
# Could indicate a serious SVN error, or just that the directory is
275
# not under version control (which is perfectly normal).
276
# Error code 155007 is "<dir> is not a working copy"
277
if isinstance(e, pysvn.ClientError) and e[1][0][1] != 155007:
278
# This is a serious error -- let it propagate upwards
280
# The directory is not under version control.
268
281
# Fallback to just an OS file listing.
270
283
for filename in os.listdir(path):
306
319
def _fullpath_stat_fileinfo(fullpath):
320
if isinstance(fullpath, unicode):
321
fullpath = fullpath.encode('utf-8') # os.stat can't handle unicode
307
322
file_stat = os.stat(fullpath)
308
323
return _stat_fileinfo(fullpath, file_stat)
339
354
needs to display about the filename. Returns a pair mapping filename to
340
355
a dict containing a number of other fields."""
341
356
path = os.path.normcase(path)
342
fullpath = status.path
357
if isinstance(status.path, str):
358
fullpath = status.path
360
fullpath = status.path.encode("utf-8")
343
361
# If this is "." (the directory itself)
344
362
if path == os.path.normcase(fullpath):
345
363
# If this directory is unversioned, then we aren't
346
364
# looking at any interesting files, so throw
347
365
# an exception and default to normal OS-based listing.
348
366
if status.text_status == pysvn.wc_status_kind.unversioned:
349
raise pysvn.ClientError
367
raise UnversionedDir()
350
368
# We actually want to return "." because we want its
351
369
# subversion status.
384
402
# looking at any interesting files, so throw
385
403
# an exception and default to normal OS-based listing.
386
404
#if status.text_status == pysvn.wc_status_kind.unversioned:
387
# raise pysvn.ClientError
405
# raise UnversionedDir()
388
406
# We actually want to return "." because we want its
389
407
# subversion status.