94
94
# revision: The revision number to update to. If not provided this
95
95
# defaults to HEAD.
97
# action=svnpublish: Set the "published" flag on a file to True.
98
# path: The path to the file to be published. Can be specified
101
# action=svnunpublish: Set the "published" flag on a file to False.
102
# path: The path to the file to be unpublished. Can be specified
105
97
# action=svncommit: Commit a file(s) or directory(s) to the repository.
106
98
# path: The path to the file or directory to be committed. Can be
107
99
# specified multiple times. Directories are committed
144
136
from ivle import (util, studpath, zip)
145
137
from ivle.fileservice_lib.exceptions import WillNotOverwrite
149
def get_login(_realm, existing_login, _may_save):
150
"""Callback function used by pysvn for authentication.
151
realm, existing_login, _may_save: The 3 arguments passed by pysvn to
153
The following has been determined empirically, not from docs:
154
existing_login will be the name of the user who owns the process on
155
the first attempt, "" on subsequent attempts. We use this fact.
157
# Only provide credentials on the _first_ attempt.
158
# If we're being asked again, then it means the credentials failed for
159
# some reason and we should just fail. (This is not desirable, but it's
160
# better than being asked an infinite number of times).
161
return (existing_login != "", str(ivle.conf.login),
162
str(ivle.conf.svn_pass), True)
164
# Make a Subversion client object
165
svnclient = pysvn.Client()
166
svnclient.callback_get_login = get_login
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)
167
145
svnclient.exception_style = 0 # Simple (string) exceptions
169
147
DEFAULT_LOGMESSAGE = "No log message supplied."
594
572
Reads fields: 'path' (multiple)
596
574
paths = fields.getlist('path')
597
paths = map(lambda path: actionpath_to_local(req, path), paths)
575
paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
600
579
svnclient.add(paths, recurse=True, force=True)
607
586
Reads fields: 'path' (multiple)
609
588
paths = fields.getlist('path')
610
paths = map(lambda path: actionpath_to_local(req, path), paths)
589
paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
613
593
svnclient.remove(paths, force=True)
659
639
Reads fields: 'path' (multiple)
661
641
paths = fields.getlist('path')
662
paths = map(lambda path: actionpath_to_local(req, path), paths)
642
paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
665
646
svnclient.revert(paths, recurse=True)
666
647
except pysvn.ClientError, e:
667
648
raise ActionError(str(e))
669
def action_svnpublish(req, fields):
670
"""Sets svn property "ivle:published" on each file specified.
671
Should only be called on directories (only effective on directories
676
XXX Currently unused by the client (calls action_publish instead, which
677
has a completely different publishing model).
679
paths = fields.getlist('path')
681
paths = map(lambda path: actionpath_to_local(req, path), paths)
683
paths = [studpath.to_home_path(req.path)]
687
# Note: Property value doesn't matter
688
svnclient.propset("ivle:published", "", path, recurse=False)
689
except pysvn.ClientError, e:
690
raise ActionError("Directory could not be published")
692
def action_svnunpublish(req, fields):
693
"""Deletes svn property "ivle:published" on each file specified.
697
XXX Currently unused by the client (calls action_unpublish instead, which
698
has a completely different publishing model).
700
paths = fields.getlist('path')
701
paths = map(lambda path: actionpath_to_local(req, path), paths)
705
svnclient.propdel("ivle:published", path, recurse=False)
706
except pysvn.ClientError, e:
707
raise ActionError("Directory could not be unpublished")
709
650
def action_svncommit(req, fields):
710
651
"""Performs a "svn commit" to each file specified.
712
653
Reads fields: 'path' (multiple), 'logmsg' (optional)
714
655
paths = fields.getlist('path')
715
paths = map(lambda path: actionpath_to_local(req, str(path)), paths)
716
logmsg = str(fields.getfirst('logmsg', DEFAULT_LOGMESSAGE))
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')
717
663
if logmsg == '': logmsg = DEFAULT_LOGMESSAGE
731
677
raise ActionError("usage: svncheckout url local-path")
732
678
url = ivle.conf.svn_addr + "/" + urllib.quote(paths[0])
733
679
local_path = actionpath_to_local(req, str(paths[1]))
680
url = url.decode('utf-8')
681
local_path = local_path.decode('utf-8')
735
svnclient.callback_get_login = get_login
736
683
svnclient.checkout(url, local_path, recurse=True)
737
684
except pysvn.ClientError, e:
738
685
raise ActionError(str(e))
745
692
path = fields.getfirst('path')
746
693
logmsg = fields.getfirst('logmsg')
747
url = ivle.conf.svn_addr + "/" + path
694
url = (ivle.conf.svn_addr + "/" + urllib.quote(path)).decode('utf-8')
749
svnclient.callback_get_login = get_login
750
696
svnclient.mkdir(url, log_message=logmsg)
751
697
except pysvn.ClientError, e:
752
698
raise ActionError(str(e))
759
705
Reads fields: 'path'
761
707
path = fields.getfirst('path')
762
url = ivle.conf.svn_addr + "/" + path
708
url = (ivle.conf.svn_addr + "/" + urllib.quote(path)).decode('utf-8')
763
709
svnclient.exception_style = 1
766
svnclient.callback_get_login = get_login
767
712
info = svnclient.info2(url,
768
713
revision=pysvn.Revision(pysvn.opt_revision_kind.head))[0][1]
769
714
return {'svnrevision': info['rev'].number
812
757
"svnupdate" : action_svnupdate,
813
758
"svnresolved" : action_svnresolved,
814
759
"svnrevert" : action_svnrevert,
815
"svnpublish" : action_svnpublish,
816
"svnunpublish" : action_svnunpublish,
817
760
"svncommit" : action_svncommit,
818
761
"svncheckout" : action_svncheckout,
819
762
"svnrepomkdir" : action_svnrepomkdir,