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

« back to all changes in this revision

Viewing changes to ivle/fileservice_lib/action.py

Add a route from / to the browser redirection view.

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
#       path:   The path to the directory to be checked (under the IVLE
120
120
#               repository base).
121
121
#
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
125
 
#
126
122
# TODO: Implement the following actions:
127
123
#   svnupdate (done?)
128
124
# TODO: Implement ZIP unpacking in putfiles (done?).
135
131
import os
136
132
import cStringIO
137
133
import shutil
138
 
import urllib
139
134
 
140
135
import pysvn
141
136
 
202
197
    except KeyError:
203
198
        # Default, just send an error but then continue
204
199
        raise ActionError("Unknown action")
205
 
    return action(req, fields)
 
200
    action(req, fields)
206
201
 
207
202
def actionpath_to_urlpath(req, path):
208
203
    """Determines the URL path (relative to the student home) upon which the
233
228
 
234
229
    Does not mutate req.
235
230
    """
236
 
    r = studpath.to_home_path(actionpath_to_urlpath(req, path))
 
231
    (_, _, r) = studpath.url_to_jailpaths(actionpath_to_urlpath(req, path))
237
232
    if r is None:
238
233
        raise ActionError("Invalid path")
239
234
    return r
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")
441
436
            # filename)
442
437
            try:
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.")
451
446
        else:
452
447
            # Not a zip file
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")
456
451
 
537
532
    Reads fields: 'path'
538
533
    """
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
542
537
    if len(paths):
543
538
        paths = map(lambda path: actionpath_to_local(req, path), paths)
544
539
    else:
545
 
        paths = [studpath.to_home_path(req.path)]
 
540
        paths = [studpath.url_to_jailpaths(req.path)[2]]
546
541
 
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 
572
567
    if len(paths):
573
568
        paths = map(lambda path: actionpath_to_local(req, path), paths)
574
569
    else:
575
 
        paths = [studpath.to_home_path(req.path)]
 
570
        paths = [studpath.url_to_jailpaths(req.path)[2]]
576
571
 
577
572
    try:
578
573
        for path in paths:
669
664
    if len(paths):
670
665
        paths = map(lambda path: actionpath_to_local(req, path), paths)
671
666
    else:
672
 
        paths = [studpath.to_home_path(req.path)]
 
667
        paths = [studpath.url_to_jailpaths(req.path)[2]]
673
668
 
674
669
    try:
675
670
        for path in paths:
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]))
723
718
    try:
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.
745
740
 
746
 
    If it does exist, returns a dict containing its metadata.
747
 
 
748
741
    Reads fields: 'path'
749
742
    """
750
743
    path = fields.getfirst('path')
751
744
    url = ivle.conf.svn_addr + "/" + path
752
 
    svnclient.exception_style = 1
 
745
    svnclient.exception_style = 1 
753
746
 
754
747
    try:
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
759
 
                  if info['rev'] and
760
 
                     info['rev'].kind == pysvn.opt_revision_kind.number
761
 
                  else None}
 
749
        svnclient.info2(url)
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')
766
754
        else:
767
755
            raise ActionError(str(e[0]))
768
 
 
769
 
 
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"""
774
 
 
775
 
    path = fields.getfirst('path')
776
 
    if path is None:
777
 
        raise ActionError("Required field missing")
778
 
    path = actionpath_to_local(req, path)
779
 
 
780
 
    try:
781
 
        svnclient.cleanup(path)
782
 
    except pysvn.ClientError, e:
783
 
        raise ActionError(str(e))
784
 
 
 
756
            
785
757
 
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,
811
782
}