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

« back to all changes in this revision

Viewing changes to ivle/fileservice_lib/action.py

  • Committer: William Grant
  • Date: 2009-04-28 05:06:00 UTC
  • Revision ID: grantw@unimelb.edu.au-20090428050600-hogd9d6wo7ksyqy8
ivle.database.get_store() now takes a configuration object.

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
 
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
776
760
            raise util.IVLEError(404, 'The specified repository path does not exist')
777
761
        else:
778
762
            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
 
 
 
763
            
796
764
 
797
765
# Table of all action functions #
798
766
# Each function has the interface f(req, fields).
818
786
    "svncheckout" : action_svncheckout,
819
787
    "svnrepomkdir" : action_svnrepomkdir,
820
788
    "svnrepostat" : action_svnrepostat,
821
 
    "svncleanup" : action_svncleanup,
822
789
}