~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/fileservice_lib/action.py

  • Committer: David Coles
  • Date: 2009-12-02 00:31:40 UTC
  • mfrom: (1326.1.4 svn-fixes)
  • Revision ID: coles.david@gmail.com-20091202003140-n0k6rmv86hu6mj2p
Allow updating files to past revisions through 'Subversion Log' page.

Show diffs side-by-side

added added

removed removed

Lines of Context:
144
144
from ivle import (util, studpath, zip)
145
145
from ivle.fileservice_lib.exceptions import WillNotOverwrite
146
146
import ivle.conf
147
 
import ivle.svn
148
 
 
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)
 
147
 
 
148
 
 
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
 
152
        callback_get_login.
 
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.
 
156
    """
 
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)
 
163
 
 
164
# Make a Subversion client object
 
165
svnclient = pysvn.Client()
 
166
svnclient.callback_get_login = get_login
153
167
svnclient.exception_style = 0               # Simple (string) exceptions
154
168
 
155
169
DEFAULT_LOGMESSAGE = "No log message supplied."
718
732
    url = ivle.conf.svn_addr + "/" + urllib.quote(paths[0])
719
733
    local_path = actionpath_to_local(req, str(paths[1]))
720
734
    try:
 
735
        svnclient.callback_get_login = get_login
721
736
        svnclient.checkout(url, local_path, recurse=True)
722
737
    except pysvn.ClientError, e:
723
738
        raise ActionError(str(e))
729
744
    """
730
745
    path = fields.getfirst('path')
731
746
    logmsg = fields.getfirst('logmsg')
732
 
    url = ivle.conf.svn_addr + "/" + urllib.quote(path)
 
747
    url = ivle.conf.svn_addr + "/" + path
733
748
    try:
 
749
        svnclient.callback_get_login = get_login
734
750
        svnclient.mkdir(url, log_message=logmsg)
735
751
    except pysvn.ClientError, e:
736
752
        raise ActionError(str(e))
743
759
    Reads fields: 'path'
744
760
    """
745
761
    path = fields.getfirst('path')
746
 
    url = ivle.conf.svn_addr + "/" + urllib.quote(path)
 
762
    url = ivle.conf.svn_addr + "/" + path
747
763
    svnclient.exception_style = 1
748
764
 
749
765
    try:
 
766
        svnclient.callback_get_login = get_login
750
767
        info = svnclient.info2(url,
751
768
            revision=pysvn.Revision(pysvn.opt_revision_kind.head))[0][1]
752
769
        return {'svnrevision': info['rev'].number