~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-12-10 01:18:36 UTC
  • Revision ID: coles.david@gmail.com-20091210011836-6kk2omcmr9hvphj0
Correct documentation's system diagram (console communication goes via Application Slaves)

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.
94
96
#
95
97
# action=svnpublish: Set the "published" flag on a file to True.
96
98
#       path:   The path to the file to be published. Can be specified
119
121
#       path:   The path to the directory to be checked (under the IVLE
120
122
#               repository base).
121
123
#
 
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
#
122
128
# TODO: Implement the following actions:
123
129
#   svnupdate (done?)
124
130
# TODO: Implement ZIP unpacking in putfiles (done?).
131
137
import os
132
138
import cStringIO
133
139
import shutil
 
140
import urllib
134
141
 
135
142
import pysvn
136
143
 
228
235
 
229
236
    Does not mutate req.
230
237
    """
231
 
    (_, _, r) = studpath.url_to_jailpaths(actionpath_to_urlpath(req, path))
 
238
    r = studpath.to_home_path(actionpath_to_urlpath(req, path))
232
239
    if r is None:
233
240
        raise ActionError("Invalid path")
234
241
    return r
420
427
    for datum in data:
421
428
        # Each of the uploaded files
422
429
        filepath = os.path.join(path, datum.filename)
423
 
        (_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
 
430
        filepath_local = studpath.to_home_path(filepath)
424
431
        if os.path.isdir(filepath_local):
425
432
            raise ActionError("A directory already exists "
426
433
                    + "with that name")
436
443
            # filename)
437
444
            try:
438
445
                # First get the entire path (within jail)
439
 
                _, _, abspath = studpath.url_to_jailpaths(path)
 
446
                abspath = studpath.to_home_path(path)
440
447
                abspath = os.path.join(os.sep, abspath)
441
448
                zip.unzip(abspath, filedata)
442
449
            except (OSError, IOError):
445
452
                raise ActionError("File '" + e.filename + "' already exists.")
446
453
        else:
447
454
            # Not a zip file
448
 
            (_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
 
455
            filepath_local = studpath.to_home_path(filepath)
449
456
            if filepath_local is None:
450
457
                raise ActionError("Invalid path")
451
458
 
532
539
    Reads fields: 'path'
533
540
    """
534
541
    paths = fields.getlist('path')
535
 
    user = studpath.url_to_local(req.path)[0]
 
542
    user = util.split_path(req.path)[0]
536
543
    homedir = "/home/%s" % user
537
544
    if len(paths):
538
545
        paths = map(lambda path: actionpath_to_local(req, path), paths)
539
546
    else:
540
 
        paths = [studpath.url_to_jailpaths(req.path)[2]]
 
547
        paths = [studpath.to_home_path(req.path)]
541
548
 
542
549
    # Set all the dirs in home dir world browsable (o+r,o+x)
543
550
    #FIXME: Should really only do those in the direct path not all of the 
567
574
    if len(paths):
568
575
        paths = map(lambda path: actionpath_to_local(req, path), paths)
569
576
    else:
570
 
        paths = [studpath.url_to_jailpaths(req.path)[2]]
 
577
        paths = [studpath.to_home_path(req.path)]
571
578
 
572
579
    try:
573
580
        for path in paths:
610
617
def action_svnupdate(req, fields):
611
618
    """Performs a "svn update" to each file specified.
612
619
 
613
 
    Reads fields: 'path'
 
620
    Reads fields: 'path' and 'revision'
614
621
    """
615
622
    path = fields.getfirst('path')
 
623
    revision = fields.getfirst('revision')
616
624
    if path is None:
617
625
        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,)
618
634
    path = actionpath_to_local(req, path)
619
635
 
620
636
    try:
621
 
        svnclient.update(path, recurse=True)
 
637
        svnclient.update(path, recurse=True, revision=revision)
622
638
    except pysvn.ClientError, e:
623
639
        raise ActionError(str(e))
624
640
 
664
680
    if len(paths):
665
681
        paths = map(lambda path: actionpath_to_local(req, path), paths)
666
682
    else:
667
 
        paths = [studpath.url_to_jailpaths(req.path)[2]]
 
683
        paths = [studpath.to_home_path(req.path)]
668
684
 
669
685
    try:
670
686
        for path in paths:
713
729
    paths = fields.getlist('path')
714
730
    if len(paths) != 2:
715
731
        raise ActionError("usage: svncheckout url local-path")
716
 
    url = ivle.conf.svn_addr + "/" + paths[0]
 
732
    url = ivle.conf.svn_addr + "/" + urllib.quote(paths[0])
717
733
    local_path = actionpath_to_local(req, str(paths[1]))
718
734
    try:
719
735
        svnclient.callback_get_login = get_login
760
776
            raise util.IVLEError(404, 'The specified repository path does not exist')
761
777
        else:
762
778
            raise ActionError(str(e[0]))
763
 
            
 
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
 
764
796
 
765
797
# Table of all action functions #
766
798
# Each function has the interface f(req, fields).
786
818
    "svncheckout" : action_svncheckout,
787
819
    "svnrepomkdir" : action_svnrepomkdir,
788
820
    "svnrepostat" : action_svnrepostat,
 
821
    "svncleanup" : action_svncleanup,
789
822
}