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
95
# action=svnpublish: Set the "published" flag on a file to True.
96
# path: The path to the file to be published. Can be specified
99
# action=svnunpublish: Set the "published" flag on a file to False.
100
# path: The path to the file to be unpublished. Can be specified
97
103
# action=svncommit: Commit a file(s) or directory(s) to the repository.
98
104
# path: The path to the file or directory to be committed. Can be
113
119
# path: The path to the directory to be checked (under the IVLE
114
120
# repository base).
116
# action=svncleanup: Recursively clean up the working copy, removing locks,
117
# resuming unfinished operations, etc.
118
# path: The path to the directory to be cleaned
120
122
# TODO: Implement the following actions:
121
123
# svnupdate (done?)
122
124
# TODO: Implement ZIP unpacking in putfiles (done?).
136
138
from ivle import (util, studpath, zip)
137
139
from ivle.fileservice_lib.exceptions import WillNotOverwrite
141
# Make a Subversion client object (which will log in with this user's
142
# credentials, upon request)
143
svnclient = ivle.svn.create_auth_svn_client(username=ivle.conf.login,
144
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
145
161
svnclient.exception_style = 0 # Simple (string) exceptions
147
163
DEFAULT_LOGMESSAGE = "No log message supplied."
572
588
Reads fields: 'path' (multiple)
574
590
paths = fields.getlist('path')
575
paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
591
paths = map(lambda path: actionpath_to_local(req, path), paths)
579
594
svnclient.add(paths, recurse=True, force=True)
586
601
Reads fields: 'path' (multiple)
588
603
paths = fields.getlist('path')
589
paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
604
paths = map(lambda path: actionpath_to_local(req, path), paths)
593
607
svnclient.remove(paths, force=True)
597
611
def action_svnupdate(req, fields):
598
612
"""Performs a "svn update" to each file specified.
600
Reads fields: 'path' and 'revision'
602
616
path = fields.getfirst('path')
603
revision = fields.getfirst('revision')
605
618
raise ActionError("Required field missing")
607
revision = pysvn.Revision( pysvn.opt_revision_kind.head )
610
revision = pysvn.Revision(pysvn.opt_revision_kind.number,
612
except ValueError, e:
613
raise ActionError("Bad revision number: '%s'"%revision,)
614
path = actionpath_to_local(req, path).decode('utf-8')
619
path = actionpath_to_local(req, path)
617
svnclient.update(path, recurse=True, revision=revision)
622
svnclient.update(path, recurse=True)
618
623
except pysvn.ClientError, e:
619
624
raise ActionError(str(e))
639
644
Reads fields: 'path' (multiple)
641
646
paths = fields.getlist('path')
642
paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
647
paths = map(lambda path: actionpath_to_local(req, path), paths)
646
650
svnclient.revert(paths, recurse=True)
647
651
except pysvn.ClientError, e:
648
652
raise ActionError(str(e))
654
def action_svnpublish(req, fields):
655
"""Sets svn property "ivle:published" on each file specified.
656
Should only be called on directories (only effective on directories
661
XXX Currently unused by the client (calls action_publish instead, which
662
has a completely different publishing model).
664
paths = fields.getlist('path')
666
paths = map(lambda path: actionpath_to_local(req, path), paths)
668
paths = [studpath.to_home_path(req.path)]
672
# Note: Property value doesn't matter
673
svnclient.propset("ivle:published", "", path, recurse=False)
674
except pysvn.ClientError, e:
675
raise ActionError("Directory could not be published")
677
def action_svnunpublish(req, fields):
678
"""Deletes svn property "ivle:published" on each file specified.
682
XXX Currently unused by the client (calls action_unpublish instead, which
683
has a completely different publishing model).
685
paths = fields.getlist('path')
686
paths = map(lambda path: actionpath_to_local(req, path), paths)
690
svnclient.propdel("ivle:published", path, recurse=False)
691
except pysvn.ClientError, e:
692
raise ActionError("Directory could not be unpublished")
650
694
def action_svncommit(req, fields):
651
695
"""Performs a "svn commit" to each file specified.
653
697
Reads fields: 'path' (multiple), 'logmsg' (optional)
655
699
paths = fields.getlist('path')
657
paths = map(lambda path:actionpath_to_local(req,path).decode('utf-8'),
660
paths = [studpath.to_home_path(req.path).decode('utf-8')]
661
logmsg = str(fields.getfirst('logmsg',
662
DEFAULT_LOGMESSAGE)).decode('utf-8')
700
paths = map(lambda path: actionpath_to_local(req, str(path)), paths)
701
logmsg = str(fields.getfirst('logmsg', DEFAULT_LOGMESSAGE))
663
702
if logmsg == '': logmsg = DEFAULT_LOGMESSAGE
677
716
raise ActionError("usage: svncheckout url local-path")
678
717
url = ivle.conf.svn_addr + "/" + urllib.quote(paths[0])
679
718
local_path = actionpath_to_local(req, str(paths[1]))
680
url = url.decode('utf-8')
681
local_path = local_path.decode('utf-8')
720
svnclient.callback_get_login = get_login
683
721
svnclient.checkout(url, local_path, recurse=True)
684
722
except pysvn.ClientError, e:
685
723
raise ActionError(str(e))
692
730
path = fields.getfirst('path')
693
731
logmsg = fields.getfirst('logmsg')
694
url = (ivle.conf.svn_addr + "/" + urllib.quote(path)).decode('utf-8')
732
url = ivle.conf.svn_addr + "/" + path
734
svnclient.callback_get_login = get_login
696
735
svnclient.mkdir(url, log_message=logmsg)
697
736
except pysvn.ClientError, e:
698
737
raise ActionError(str(e))
705
744
Reads fields: 'path'
707
746
path = fields.getfirst('path')
708
url = (ivle.conf.svn_addr + "/" + urllib.quote(path)).decode('utf-8')
747
url = ivle.conf.svn_addr + "/" + path
709
748
svnclient.exception_style = 1
751
svnclient.callback_get_login = get_login
712
752
info = svnclient.info2(url,
713
753
revision=pysvn.Revision(pysvn.opt_revision_kind.head))[0][1]
714
754
return {'svnrevision': info['rev'].number
721
761
raise util.IVLEError(404, 'The specified repository path does not exist')
723
763
raise ActionError(str(e[0]))
726
def action_svncleanup(req, fields):
727
"""Recursively clean up the working copy, removing locks, resuming
728
unfinished operations, etc.
729
path: The path to be cleaned"""
731
path = fields.getfirst('path')
733
raise ActionError("Required field missing")
734
path = actionpath_to_local(req, path).decode('utf-8')
737
svnclient.cleanup(path)
738
except pysvn.ClientError, e:
739
raise ActionError(str(e))
742
766
# Table of all action functions #
743
767
# Each function has the interface f(req, fields).
757
781
"svnupdate" : action_svnupdate,
758
782
"svnresolved" : action_svnresolved,
759
783
"svnrevert" : action_svnrevert,
784
"svnpublish" : action_svnpublish,
785
"svnunpublish" : action_svnunpublish,
760
786
"svncommit" : action_svncommit,
761
787
"svncheckout" : action_svncheckout,
762
788
"svnrepomkdir" : action_svnrepomkdir,
763
789
"svnrepostat" : action_svnrepostat,
764
"svncleanup" : action_svncleanup,