~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-05-19 03:51:14 UTC
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: matt.giuca@gmail.com-20090519035114-4scjhvg7ai73anq0
doc/man: Renamed filesystem to directory hierarchy.

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?).
235
229
 
236
230
    Does not mutate req.
237
231
    """
238
 
    r = studpath.to_home_path(actionpath_to_urlpath(req, path))
 
232
    (_, _, r) = studpath.url_to_jailpaths(actionpath_to_urlpath(req, path))
239
233
    if r is None:
240
234
        raise ActionError("Invalid path")
241
235
    return r
427
421
    for datum in data:
428
422
        # Each of the uploaded files
429
423
        filepath = os.path.join(path, datum.filename)
430
 
        filepath_local = studpath.to_home_path(filepath)
 
424
        (_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
431
425
        if os.path.isdir(filepath_local):
432
426
            raise ActionError("A directory already exists "
433
427
                    + "with that name")
443
437
            # filename)
444
438
            try:
445
439
                # First get the entire path (within jail)
446
 
                abspath = studpath.to_home_path(path)
 
440
                _, _, abspath = studpath.url_to_jailpaths(path)
447
441
                abspath = os.path.join(os.sep, abspath)
448
442
                zip.unzip(abspath, filedata)
449
443
            except (OSError, IOError):
452
446
                raise ActionError("File '" + e.filename + "' already exists.")
453
447
        else:
454
448
            # Not a zip file
455
 
            filepath_local = studpath.to_home_path(filepath)
 
449
            (_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
456
450
            if filepath_local is None:
457
451
                raise ActionError("Invalid path")
458
452
 
539
533
    Reads fields: 'path'
540
534
    """
541
535
    paths = fields.getlist('path')
542
 
    user = util.split_path(req.path)[0]
 
536
    user = studpath.url_to_local(req.path)[0]
543
537
    homedir = "/home/%s" % user
544
538
    if len(paths):
545
539
        paths = map(lambda path: actionpath_to_local(req, path), paths)
546
540
    else:
547
 
        paths = [studpath.to_home_path(req.path)]
 
541
        paths = [studpath.url_to_jailpaths(req.path)[2]]
548
542
 
549
543
    # Set all the dirs in home dir world browsable (o+r,o+x)
550
544
    #FIXME: Should really only do those in the direct path not all of the 
574
568
    if len(paths):
575
569
        paths = map(lambda path: actionpath_to_local(req, path), paths)
576
570
    else:
577
 
        paths = [studpath.to_home_path(req.path)]
 
571
        paths = [studpath.url_to_jailpaths(req.path)[2]]
578
572
 
579
573
    try:
580
574
        for path in paths:
617
611
def action_svnupdate(req, fields):
618
612
    """Performs a "svn update" to each file specified.
619
613
 
620
 
    Reads fields: 'path' and 'revision'
 
614
    Reads fields: 'path'
621
615
    """
622
616
    path = fields.getfirst('path')
623
 
    revision = fields.getfirst('revision')
624
617
    if path is None:
625
618
        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
619
    path = actionpath_to_local(req, path)
635
620
 
636
621
    try:
637
 
        svnclient.update(path, recurse=True, revision=revision)
 
622
        svnclient.update(path, recurse=True)
638
623
    except pysvn.ClientError, e:
639
624
        raise ActionError(str(e))
640
625
 
680
665
    if len(paths):
681
666
        paths = map(lambda path: actionpath_to_local(req, path), paths)
682
667
    else:
683
 
        paths = [studpath.to_home_path(req.path)]
 
668
        paths = [studpath.url_to_jailpaths(req.path)[2]]
684
669
 
685
670
    try:
686
671
        for path in paths:
776
761
            raise util.IVLEError(404, 'The specified repository path does not exist')
777
762
        else:
778
763
            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
 
 
 
764
            
796
765
 
797
766
# Table of all action functions #
798
767
# Each function has the interface f(req, fields).
818
787
    "svncheckout" : action_svncheckout,
819
788
    "svnrepomkdir" : action_svnrepomkdir,
820
789
    "svnrepostat" : action_svnrepostat,
821
 
    "svncleanup" : action_svncleanup,
822
790
}