~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-08-17 21:11:50 UTC
  • Revision ID: coles.david@gmail.com-20090817211150-r3bljeiv5t78v0uz
Normalise usernames to lowercase so that they are case insensitive.
This is to prevent an issue with a certain "unnamed LDAP service" doing case insensative lookups meaning we will create duplicate users.
Fixes lp:415171

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