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

« back to all changes in this revision

Viewing changes to ivle/fileservice_lib/action.py

  • Committer: Matt Giuca
  • Date: 2009-03-24 06:50:39 UTC
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: matt.giuca@gmail.com-20090324065039-5c6xkjeb8x2f5d01
doc/conf.py: Renamed project from "ivle" to "IVLE". (Turns out this is a
    friendly name).

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
# action=svnupdate: Bring a file up to date with the head revision.
92
92
#       path:   The path to the file to be updated. Only one file may be
93
93
#               specified.
94
 
#       revision: The revision number to update to. If not provided this
95
 
#               defaults to HEAD.
96
94
#
97
95
# action=svnpublish: Set the "published" flag on a file to True.
98
96
#       path:   The path to the file to be published. Can be specified
121
119
#       path:   The path to the directory to be checked (under the IVLE
122
120
#               repository base).
123
121
#
124
 
# action=svncleanup: Recursively clean up the working copy, removing locks,
125
 
#   resuming unfinished operations, etc.
126
 
#       path:   The path to the directory to be cleaned
127
 
#
128
122
# TODO: Implement the following actions:
129
123
#   svnupdate (done?)
130
124
# TODO: Implement ZIP unpacking in putfiles (done?).
137
131
import os
138
132
import cStringIO
139
133
import shutil
140
 
import urllib
141
134
 
142
135
import pysvn
143
136
 
204
197
    except KeyError:
205
198
        # Default, just send an error but then continue
206
199
        raise ActionError("Unknown action")
207
 
    return action(req, fields)
 
200
    action(req, fields)
208
201
 
209
202
def actionpath_to_urlpath(req, path):
210
203
    """Determines the URL path (relative to the student home) upon which the
235
228
 
236
229
    Does not mutate req.
237
230
    """
238
 
    r = studpath.to_home_path(actionpath_to_urlpath(req, path))
 
231
    (_, _, r) = studpath.url_to_jailpaths(actionpath_to_urlpath(req, path))
239
232
    if r is None:
240
233
        raise ActionError("Invalid path")
241
234
    return r
427
420
    for datum in data:
428
421
        # Each of the uploaded files
429
422
        filepath = os.path.join(path, datum.filename)
430
 
        filepath_local = studpath.to_home_path(filepath)
 
423
        (_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
431
424
        if os.path.isdir(filepath_local):
432
425
            raise ActionError("A directory already exists "
433
426
                    + "with that name")
443
436
            # filename)
444
437
            try:
445
438
                # First get the entire path (within jail)
446
 
                abspath = studpath.to_home_path(path)
 
439
                _, _, abspath = studpath.url_to_jailpaths(path)
447
440
                abspath = os.path.join(os.sep, abspath)
448
441
                zip.unzip(abspath, filedata)
449
442
            except (OSError, IOError):
452
445
                raise ActionError("File '" + e.filename + "' already exists.")
453
446
        else:
454
447
            # Not a zip file
455
 
            filepath_local = studpath.to_home_path(filepath)
 
448
            (_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
456
449
            if filepath_local is None:
457
450
                raise ActionError("Invalid path")
458
451
 
539
532
    Reads fields: 'path'
540
533
    """
541
534
    paths = fields.getlist('path')
542
 
    user = util.split_path(req.path)[0]
 
535
    user = studpath.url_to_local(req.path)[0]
543
536
    homedir = "/home/%s" % user
544
537
    if len(paths):
545
538
        paths = map(lambda path: actionpath_to_local(req, path), paths)
546
539
    else:
547
 
        paths = [studpath.to_home_path(req.path)]
 
540
        paths = [studpath.url_to_jailpaths(req.path)[2]]
548
541
 
549
542
    # Set all the dirs in home dir world browsable (o+r,o+x)
550
543
    #FIXME: Should really only do those in the direct path not all of the 
574
567
    if len(paths):
575
568
        paths = map(lambda path: actionpath_to_local(req, path), paths)
576
569
    else:
577
 
        paths = [studpath.to_home_path(req.path)]
 
570
        paths = [studpath.url_to_jailpaths(req.path)[2]]
578
571
 
579
572
    try:
580
573
        for path in paths:
617
610
def action_svnupdate(req, fields):
618
611
    """Performs a "svn update" to each file specified.
619
612
 
620
 
    Reads fields: 'path' and 'revision'
 
613
    Reads fields: 'path'
621
614
    """
622
615
    path = fields.getfirst('path')
623
 
    revision = fields.getfirst('revision')
624
616
    if path is None:
625
617
        raise ActionError("Required field missing")
626
 
    if revision is None:
627
 
        revision = pysvn.Revision( pysvn.opt_revision_kind.head )
628
 
    else:
629
 
        try:
630
 
            revision = pysvn.Revision(pysvn.opt_revision_kind.number,
631
 
                    int(revision))
632
 
        except ValueError, e:
633
 
            raise ActionError("Bad revision number: '%s'"%revision,)
634
618
    path = actionpath_to_local(req, path)
635
619
 
636
620
    try:
637
 
        svnclient.update(path, recurse=True, revision=revision)
 
621
        svnclient.update(path, recurse=True)
638
622
    except pysvn.ClientError, e:
639
623
        raise ActionError(str(e))
640
624
 
680
664
    if len(paths):
681
665
        paths = map(lambda path: actionpath_to_local(req, path), paths)
682
666
    else:
683
 
        paths = [studpath.to_home_path(req.path)]
 
667
        paths = [studpath.url_to_jailpaths(req.path)[2]]
684
668
 
685
669
    try:
686
670
        for path in paths:
729
713
    paths = fields.getlist('path')
730
714
    if len(paths) != 2:
731
715
        raise ActionError("usage: svncheckout url local-path")
732
 
    url = ivle.conf.svn_addr + "/" + urllib.quote(paths[0])
 
716
    url = ivle.conf.svn_addr + "/" + paths[0]
733
717
    local_path = actionpath_to_local(req, str(paths[1]))
734
718
    try:
735
719
        svnclient.callback_get_login = get_login
754
738
def action_svnrepostat(req, fields):
755
739
    """Discovers whether a path exists in a repo under the IVLE SVN root.
756
740
 
757
 
    If it does exist, returns a dict containing its metadata.
758
 
 
759
741
    Reads fields: 'path'
760
742
    """
761
743
    path = fields.getfirst('path')
762
744
    url = ivle.conf.svn_addr + "/" + path
763
 
    svnclient.exception_style = 1
 
745
    svnclient.exception_style = 1 
764
746
 
765
747
    try:
766
748
        svnclient.callback_get_login = get_login
767
 
        info = svnclient.info2(url,
768
 
            revision=pysvn.Revision(pysvn.opt_revision_kind.head))[0][1]
769
 
        return {'svnrevision': info['rev'].number
770
 
                  if info['rev'] and
771
 
                     info['rev'].kind == pysvn.opt_revision_kind.number
772
 
                  else None}
 
749
        svnclient.info2(url)
773
750
    except pysvn.ClientError, e:
774
751
        # Error code 170000 means ENOENT in this revision.
775
752
        if e[1][0][1] == 170000:
776
753
            raise util.IVLEError(404, 'The specified repository path does not exist')
777
754
        else:
778
755
            raise ActionError(str(e[0]))
779
 
 
780
 
 
781
 
def action_svncleanup(req, fields):
782
 
    """Recursively clean up the working copy, removing locks, resuming 
783
 
    unfinished operations, etc.
784
 
        path:   The path to be cleaned"""
785
 
 
786
 
    path = fields.getfirst('path')
787
 
    if path is None:
788
 
        raise ActionError("Required field missing")
789
 
    path = actionpath_to_local(req, path)
790
 
 
791
 
    try:
792
 
        svnclient.cleanup(path)
793
 
    except pysvn.ClientError, e:
794
 
        raise ActionError(str(e))
795
 
 
 
756
            
796
757
 
797
758
# Table of all action functions #
798
759
# Each function has the interface f(req, fields).
818
779
    "svncheckout" : action_svncheckout,
819
780
    "svnrepomkdir" : action_svnrepomkdir,
820
781
    "svnrepostat" : action_svnrepostat,
821
 
    "svncleanup" : action_svncleanup,
822
782
}