119
119
# path: The path to the directory to be checked (under the IVLE
120
120
# repository base).
122
# action=svncleanup: Recursively clean up the working copy, removing locks,
123
# resuming unfinished operations, etc.
124
# path: The path to the directory to be cleaned
126
122
# TODO: Implement the following actions:
127
123
# svnupdate (done?)
128
124
# TODO: Implement ZIP unpacking in putfiles (done?).
203
198
# Default, just send an error but then continue
204
199
raise ActionError("Unknown action")
205
return action(req, fields)
207
202
def actionpath_to_urlpath(req, path):
208
203
"""Determines the URL path (relative to the student home) upon which the
234
229
Does not mutate req.
236
r = studpath.to_home_path(actionpath_to_urlpath(req, path))
231
(_, _, r) = studpath.url_to_jailpaths(actionpath_to_urlpath(req, path))
238
233
raise ActionError("Invalid path")
425
420
for datum in data:
426
421
# Each of the uploaded files
427
422
filepath = os.path.join(path, datum.filename)
428
filepath_local = studpath.to_home_path(filepath)
423
(_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
429
424
if os.path.isdir(filepath_local):
430
425
raise ActionError("A directory already exists "
431
426
+ "with that name")
443
438
# First get the entire path (within jail)
444
abspath = studpath.to_home_path(path)
439
_, _, abspath = studpath.url_to_jailpaths(path)
445
440
abspath = os.path.join(os.sep, abspath)
446
441
zip.unzip(abspath, filedata)
447
442
except (OSError, IOError):
450
445
raise ActionError("File '" + e.filename + "' already exists.")
453
filepath_local = studpath.to_home_path(filepath)
448
(_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
454
449
if filepath_local is None:
455
450
raise ActionError("Invalid path")
537
532
Reads fields: 'path'
539
534
paths = fields.getlist('path')
540
user = util.split_path(req.path)[0]
535
user = studpath.url_to_local(req.path)[0]
541
536
homedir = "/home/%s" % user
543
538
paths = map(lambda path: actionpath_to_local(req, path), paths)
545
paths = [studpath.to_home_path(req.path)]
540
paths = [studpath.url_to_jailpaths(req.path)[2]]
547
542
# Set all the dirs in home dir world browsable (o+r,o+x)
548
543
#FIXME: Should really only do those in the direct path not all of the
718
713
paths = fields.getlist('path')
719
714
if len(paths) != 2:
720
715
raise ActionError("usage: svncheckout url local-path")
721
url = ivle.conf.svn_addr + "/" + urllib.quote(paths[0])
716
url = ivle.conf.svn_addr + "/" + paths[0]
722
717
local_path = actionpath_to_local(req, str(paths[1]))
724
719
svnclient.callback_get_login = get_login
743
738
def action_svnrepostat(req, fields):
744
739
"""Discovers whether a path exists in a repo under the IVLE SVN root.
746
If it does exist, returns a dict containing its metadata.
748
741
Reads fields: 'path'
750
743
path = fields.getfirst('path')
751
744
url = ivle.conf.svn_addr + "/" + path
752
svnclient.exception_style = 1
745
svnclient.exception_style = 1
755
748
svnclient.callback_get_login = get_login
756
info = svnclient.info2(url,
757
revision=pysvn.Revision(pysvn.opt_revision_kind.head))[0][1]
758
return {'svnrevision': info['rev'].number
760
info['rev'].kind == pysvn.opt_revision_kind.number
762
750
except pysvn.ClientError, e:
763
751
# Error code 170000 means ENOENT in this revision.
764
752
if e[1][0][1] == 170000:
765
753
raise util.IVLEError(404, 'The specified repository path does not exist')
767
755
raise ActionError(str(e[0]))
770
def action_svncleanup(req, fields):
771
"""Recursively clean up the working copy, removing locks, resuming
772
unfinished operations, etc.
773
path: The path to be cleaned"""
775
path = fields.getfirst('path')
777
raise ActionError("Required field missing")
778
path = actionpath_to_local(req, path)
781
svnclient.cleanup(path)
782
except pysvn.ClientError, e:
783
raise ActionError(str(e))
786
758
# Table of all action functions #
787
759
# Each function has the interface f(req, fields).
807
779
"svncheckout" : action_svncheckout,
808
780
"svnrepomkdir" : action_svnrepomkdir,
809
781
"svnrepostat" : action_svnrepostat,
810
"svncleanup" : action_svncleanup,