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

« back to all changes in this revision

Viewing changes to ivle/fileservice_lib/action.py

  • Committer: Nick Chadwick
  • Date: 2009-03-03 01:48:48 UTC
  • mto: (1099.1.227 exercise-ui)
  • mto: This revision was merged to the branch mainline in revision 1162.
  • Revision ID: chadnickbok@gmail.com-20090303014848-dyurvmtmbneohd7f
Modified the setup script to include '.txt' files.

This allows the automatic inclusion of definitions.txt from the rst
code, as it is needed by all worksheets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
import os
132
132
import cStringIO
133
133
import shutil
134
 
import urllib
135
134
 
136
135
import pysvn
137
136
 
198
197
    except KeyError:
199
198
        # Default, just send an error but then continue
200
199
        raise ActionError("Unknown action")
201
 
    return action(req, fields)
 
200
    action(req, fields)
202
201
 
203
202
def actionpath_to_urlpath(req, path):
204
203
    """Determines the URL path (relative to the student home) upon which the
229
228
 
230
229
    Does not mutate req.
231
230
    """
232
 
    r = studpath.to_home_path(actionpath_to_urlpath(req, path))
 
231
    (_, _, r) = studpath.url_to_jailpaths(actionpath_to_urlpath(req, path))
233
232
    if r is None:
234
233
        raise ActionError("Invalid path")
235
234
    return r
421
420
    for datum in data:
422
421
        # Each of the uploaded files
423
422
        filepath = os.path.join(path, datum.filename)
424
 
        filepath_local = studpath.to_home_path(filepath)
 
423
        (_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
425
424
        if os.path.isdir(filepath_local):
426
425
            raise ActionError("A directory already exists "
427
426
                    + "with that name")
437
436
            # filename)
438
437
            try:
439
438
                # First get the entire path (within jail)
440
 
                abspath = studpath.to_home_path(path)
 
439
                _, _, abspath = studpath.url_to_jailpaths(path)
441
440
                abspath = os.path.join(os.sep, abspath)
442
441
                zip.unzip(abspath, filedata)
443
442
            except (OSError, IOError):
446
445
                raise ActionError("File '" + e.filename + "' already exists.")
447
446
        else:
448
447
            # Not a zip file
449
 
            filepath_local = studpath.to_home_path(filepath)
 
448
            (_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
450
449
            if filepath_local is None:
451
450
                raise ActionError("Invalid path")
452
451
 
533
532
    Reads fields: 'path'
534
533
    """
535
534
    paths = fields.getlist('path')
536
 
    user = util.split_path(req.path)[0]
 
535
    user = studpath.url_to_local(req.path)[0]
537
536
    homedir = "/home/%s" % user
538
537
    if len(paths):
539
538
        paths = map(lambda path: actionpath_to_local(req, path), paths)
540
539
    else:
541
 
        paths = [studpath.to_home_path(req.path)]
 
540
        paths = [studpath.url_to_jailpaths(req.path)[2]]
542
541
 
543
542
    # Set all the dirs in home dir world browsable (o+r,o+x)
544
543
    #FIXME: Should really only do those in the direct path not all of the 
568
567
    if len(paths):
569
568
        paths = map(lambda path: actionpath_to_local(req, path), paths)
570
569
    else:
571
 
        paths = [studpath.to_home_path(req.path)]
 
570
        paths = [studpath.url_to_jailpaths(req.path)[2]]
572
571
 
573
572
    try:
574
573
        for path in paths:
665
664
    if len(paths):
666
665
        paths = map(lambda path: actionpath_to_local(req, path), paths)
667
666
    else:
668
 
        paths = [studpath.to_home_path(req.path)]
 
667
        paths = [studpath.url_to_jailpaths(req.path)[2]]
669
668
 
670
669
    try:
671
670
        for path in paths:
714
713
    paths = fields.getlist('path')
715
714
    if len(paths) != 2:
716
715
        raise ActionError("usage: svncheckout url local-path")
717
 
    url = ivle.conf.svn_addr + "/" + urllib.quote(paths[0])
 
716
    url = ivle.conf.svn_addr + "/" + paths[0]
718
717
    local_path = actionpath_to_local(req, str(paths[1]))
719
718
    try:
720
719
        svnclient.callback_get_login = get_login
739
738
def action_svnrepostat(req, fields):
740
739
    """Discovers whether a path exists in a repo under the IVLE SVN root.
741
740
 
742
 
    If it does exist, returns a dict containing its metadata.
743
 
 
744
741
    Reads fields: 'path'
745
742
    """
746
743
    path = fields.getfirst('path')
747
744
    url = ivle.conf.svn_addr + "/" + path
748
 
    svnclient.exception_style = 1
 
745
    svnclient.exception_style = 1 
749
746
 
750
747
    try:
751
748
        svnclient.callback_get_login = get_login
752
 
        info = svnclient.info2(url,
753
 
            revision=pysvn.Revision(pysvn.opt_revision_kind.head))[0][1]
754
 
        return {'svnrevision': info['rev'].number
755
 
                  if info['rev'] and
756
 
                     info['rev'].kind == pysvn.opt_revision_kind.number
757
 
                  else None}
 
749
        svnclient.info2(url)
758
750
    except pysvn.ClientError, e:
759
751
        # Error code 170000 means ENOENT in this revision.
760
752
        if e[1][0][1] == 170000: