91
91
# action=svnupdate: Bring a file up to date with the head revision.
92
92
# path: The path to the file to be updated. Only one file may be
94
# revision: The revision number to update to. If not provided this
97
95
# action=svnpublish: Set the "published" flag on a file to True.
98
96
# path: The path to the file to be published. Can be specified
121
119
# path: The path to the directory to be checked (under the IVLE
122
120
# repository base).
124
# action=svncleanup: Recursively clean up the working copy, removing locks,
125
# resuming unfinished operations, etc.
126
# path: The path to the directory to be cleaned
128
122
# TODO: Implement the following actions:
129
123
# svnupdate (done?)
130
124
# TODO: Implement ZIP unpacking in putfiles (done?).
144
138
from ivle import (util, studpath, zip)
145
139
from ivle.fileservice_lib.exceptions import WillNotOverwrite
149
# Make a Subversion client object (which will log in with this user's
150
# credentials, upon request)
151
svnclient = ivle.svn.create_auth_svn_client(username=ivle.conf.login,
152
password=ivle.conf.svn_pass)
143
def get_login(_realm, existing_login, _may_save):
144
"""Callback function used by pysvn for authentication.
145
realm, existing_login, _may_save: The 3 arguments passed by pysvn to
147
The following has been determined empirically, not from docs:
148
existing_login will be the name of the user who owns the process on
149
the first attempt, "" on subsequent attempts. We use this fact.
151
# Only provide credentials on the _first_ attempt.
152
# If we're being asked again, then it means the credentials failed for
153
# some reason and we should just fail. (This is not desirable, but it's
154
# better than being asked an infinite number of times).
155
return (existing_login != "", str(ivle.conf.login),
156
str(ivle.conf.svn_pass), True)
158
# Make a Subversion client object
159
svnclient = pysvn.Client()
160
svnclient.callback_get_login = get_login
153
161
svnclient.exception_style = 0 # Simple (string) exceptions
155
163
DEFAULT_LOGMESSAGE = "No log message supplied."
222
230
Does not mutate req.
224
r = studpath.to_home_path(actionpath_to_urlpath(req, path))
232
(_, _, r) = studpath.url_to_jailpaths(actionpath_to_urlpath(req, path))
226
234
raise ActionError("Invalid path")
413
421
for datum in data:
414
422
# Each of the uploaded files
415
423
filepath = os.path.join(path, datum.filename)
416
filepath_local = studpath.to_home_path(filepath)
424
(_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
417
425
if os.path.isdir(filepath_local):
418
426
raise ActionError("A directory already exists "
419
427
+ "with that name")
431
439
# First get the entire path (within jail)
432
abspath = studpath.to_home_path(path)
440
_, _, abspath = studpath.url_to_jailpaths(path)
433
441
abspath = os.path.join(os.sep, abspath)
434
442
zip.unzip(abspath, filedata)
435
443
except (OSError, IOError):
438
446
raise ActionError("File '" + e.filename + "' already exists.")
441
filepath_local = studpath.to_home_path(filepath)
449
(_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
442
450
if filepath_local is None:
443
451
raise ActionError("Invalid path")
525
533
Reads fields: 'path'
527
535
paths = fields.getlist('path')
528
user = util.split_path(req.path)[0]
536
user = studpath.url_to_local(req.path)[0]
529
537
homedir = "/home/%s" % user
531
539
paths = map(lambda path: actionpath_to_local(req, path), paths)
533
paths = [studpath.to_home_path(req.path)]
541
paths = [studpath.url_to_jailpaths(req.path)[2]]
535
543
# Set all the dirs in home dir world browsable (o+r,o+x)
536
544
#FIXME: Should really only do those in the direct path not all of the
603
611
def action_svnupdate(req, fields):
604
612
"""Performs a "svn update" to each file specified.
606
Reads fields: 'path' and 'revision'
608
616
path = fields.getfirst('path')
609
revision = fields.getfirst('revision')
611
618
raise ActionError("Required field missing")
613
revision = pysvn.Revision( pysvn.opt_revision_kind.head )
616
revision = pysvn.Revision(pysvn.opt_revision_kind.number,
618
except ValueError, e:
619
raise ActionError("Bad revision number: '%s'"%revision,)
620
619
path = actionpath_to_local(req, path)
623
svnclient.update(path, recurse=True, revision=revision)
622
svnclient.update(path, recurse=True)
624
623
except pysvn.ClientError, e:
625
624
raise ActionError(str(e))
718
717
url = ivle.conf.svn_addr + "/" + urllib.quote(paths[0])
719
718
local_path = actionpath_to_local(req, str(paths[1]))
720
svnclient.callback_get_login = get_login
721
721
svnclient.checkout(url, local_path, recurse=True)
722
722
except pysvn.ClientError, e:
723
723
raise ActionError(str(e))
730
730
path = fields.getfirst('path')
731
731
logmsg = fields.getfirst('logmsg')
732
url = ivle.conf.svn_addr + "/" + urllib.quote(path)
732
url = ivle.conf.svn_addr + "/" + path
734
svnclient.callback_get_login = get_login
734
735
svnclient.mkdir(url, log_message=logmsg)
735
736
except pysvn.ClientError, e:
736
737
raise ActionError(str(e))
743
744
Reads fields: 'path'
745
746
path = fields.getfirst('path')
746
url = ivle.conf.svn_addr + "/" + urllib.quote(path)
747
url = ivle.conf.svn_addr + "/" + path
747
748
svnclient.exception_style = 1
751
svnclient.callback_get_login = get_login
750
752
info = svnclient.info2(url,
751
753
revision=pysvn.Revision(pysvn.opt_revision_kind.head))[0][1]
752
754
return {'svnrevision': info['rev'].number
759
761
raise util.IVLEError(404, 'The specified repository path does not exist')
761
763
raise ActionError(str(e[0]))
764
def action_svncleanup(req, fields):
765
"""Recursively clean up the working copy, removing locks, resuming
766
unfinished operations, etc.
767
path: The path to be cleaned"""
769
path = fields.getfirst('path')
771
raise ActionError("Required field missing")
772
path = actionpath_to_local(req, path)
775
svnclient.cleanup(path)
776
except pysvn.ClientError, e:
777
raise ActionError(str(e))
780
766
# Table of all action functions #
781
767
# Each function has the interface f(req, fields).
801
787
"svncheckout" : action_svncheckout,
802
788
"svnrepomkdir" : action_svnrepomkdir,
803
789
"svnrepostat" : action_svnrepostat,
804
"svncleanup" : action_svncleanup,