~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: 2010-02-11 09:09:53 UTC
  • Revision ID: grantw@unimelb.edu.au-20100211090953-592dk5jruwdg1qrq
Declare appropriate tabs on the rest of the views.

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
#       revision: The revision number to update to. If not provided this
95
95
#               defaults to HEAD.
96
96
#
 
97
# action=svnpublish: Set the "published" flag on a file to True.
 
98
#       path:   The path to the file to be published. Can be specified
 
99
#               multiple times.
 
100
#
 
101
# action=svnunpublish: Set the "published" flag on a file to False.
 
102
#       path:   The path to the file to be unpublished. Can be specified
 
103
#               multiple times.
 
104
#
97
105
# action=svncommit: Commit a file(s) or directory(s) to the repository.
98
106
#       path:   The path to the file or directory to be committed. Can be
99
107
#               specified multiple times. Directories are committed
317
325
    """
318
326
    frompath = fields.getfirst('from')
319
327
    topath = fields.getfirst('to')
320
 
    svn = fields.getfirst('svn')
321
 
    if svn:
322
 
        svn_movefile(req, frompath, topath)
323
 
    else:
324
 
        movefile(req, frompath, topath)
 
328
    movefile(req, frompath, topath)
325
329
 
326
330
def action_mkdir(req, fields):
327
331
    """Creates a directory with the given path.
576
580
    Reads fields: 'path' (multiple)
577
581
    """
578
582
    paths = fields.getlist('path')
579
 
    paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
580
 
                paths)
 
583
    paths = map(lambda path: actionpath_to_local(req, path), paths)
581
584
 
582
585
    try:
583
586
        svnclient.add(paths, recurse=True, force=True)
590
593
    Reads fields: 'path' (multiple)
591
594
    """
592
595
    paths = fields.getlist('path')
593
 
    paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
594
 
                paths)
 
596
    paths = map(lambda path: actionpath_to_local(req, path), paths)
595
597
 
596
598
    try:
597
599
        svnclient.remove(paths, force=True)
615
617
                    int(revision))
616
618
        except ValueError, e:
617
619
            raise ActionError("Bad revision number: '%s'"%revision,)
618
 
    path = actionpath_to_local(req, path).decode('utf-8')
 
620
    path = actionpath_to_local(req, path)
619
621
 
620
622
    try:
621
623
        svnclient.update(path, recurse=True, revision=revision)
630
632
    path = fields.getfirst('path')
631
633
    if path is None:
632
634
        raise ActionError("Required field missing")
633
 
    path = actionpath_to_local(req, path).decode('utf-8')
 
635
    path = actionpath_to_local(req, path)
634
636
 
635
637
    try:
636
638
        svnclient.resolved(path, recurse=True)
643
645
    Reads fields: 'path' (multiple)
644
646
    """
645
647
    paths = fields.getlist('path')
646
 
    paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
647
 
                paths)
 
648
    paths = map(lambda path: actionpath_to_local(req, path), paths)
648
649
 
649
650
    try:
650
651
        svnclient.revert(paths, recurse=True)
651
652
    except pysvn.ClientError, e:
652
653
        raise ActionError(str(e))
653
654
 
 
655
def action_svnpublish(req, fields):
 
656
    """Sets svn property "ivle:published" on each file specified.
 
657
    Should only be called on directories (only effective on directories
 
658
    anyway).
 
659
 
 
660
    Reads fields: 'path'
 
661
 
 
662
    XXX Currently unused by the client (calls action_publish instead, which
 
663
    has a completely different publishing model).
 
664
    """
 
665
    paths = fields.getlist('path')
 
666
    if len(paths):
 
667
        paths = map(lambda path: actionpath_to_local(req, path), paths)
 
668
    else:
 
669
        paths = [studpath.to_home_path(req.path)]
 
670
 
 
671
    try:
 
672
        for path in paths:
 
673
            # Note: Property value doesn't matter
 
674
            svnclient.propset("ivle:published", "", path, recurse=False)
 
675
    except pysvn.ClientError, e:
 
676
        raise ActionError("Directory could not be published")
 
677
 
 
678
def action_svnunpublish(req, fields):
 
679
    """Deletes svn property "ivle:published" on each file specified.
 
680
 
 
681
    Reads fields: 'path'
 
682
 
 
683
    XXX Currently unused by the client (calls action_unpublish instead, which
 
684
    has a completely different publishing model).
 
685
    """
 
686
    paths = fields.getlist('path')
 
687
    paths = map(lambda path: actionpath_to_local(req, path), paths)
 
688
 
 
689
    try:
 
690
        for path in paths:
 
691
            svnclient.propdel("ivle:published", path, recurse=False)
 
692
    except pysvn.ClientError, e:
 
693
        raise ActionError("Directory could not be unpublished")
 
694
 
654
695
def action_svncommit(req, fields):
655
696
    """Performs a "svn commit" to each file specified.
656
697
 
657
698
    Reads fields: 'path' (multiple), 'logmsg' (optional)
658
699
    """
659
700
    paths = fields.getlist('path')
660
 
    if len(paths):
661
 
        paths = map(lambda path:actionpath_to_local(req,path).decode('utf-8'),
662
 
                    paths)
663
 
    else:
664
 
        paths = [studpath.to_home_path(req.path).decode('utf-8')]
665
 
    logmsg = str(fields.getfirst('logmsg',
666
 
                 DEFAULT_LOGMESSAGE)).decode('utf-8')
 
701
    paths = map(lambda path: actionpath_to_local(req, str(path)), paths)
 
702
    logmsg = str(fields.getfirst('logmsg', DEFAULT_LOGMESSAGE))
667
703
    if logmsg == '': logmsg = DEFAULT_LOGMESSAGE
668
704
 
669
705
    try:
681
717
        raise ActionError("usage: svncheckout url local-path")
682
718
    url = ivle.conf.svn_addr + "/" + urllib.quote(paths[0])
683
719
    local_path = actionpath_to_local(req, str(paths[1]))
684
 
    url = url.decode('utf-8')
685
 
    local_path = local_path.decode('utf-8')
686
720
    try:
687
721
        svnclient.checkout(url, local_path, recurse=True)
688
722
    except pysvn.ClientError, e:
695
729
    """
696
730
    path = fields.getfirst('path')
697
731
    logmsg = fields.getfirst('logmsg')
698
 
    url = (ivle.conf.svn_addr + "/" + urllib.quote(path)).decode('utf-8')
 
732
    url = ivle.conf.svn_addr + "/" + urllib.quote(path)
699
733
    try:
700
734
        svnclient.mkdir(url, log_message=logmsg)
701
735
    except pysvn.ClientError, e:
709
743
    Reads fields: 'path'
710
744
    """
711
745
    path = fields.getfirst('path')
712
 
    url = (ivle.conf.svn_addr + "/" + urllib.quote(path)).decode('utf-8')
 
746
    url = ivle.conf.svn_addr + "/" + urllib.quote(path)
713
747
    svnclient.exception_style = 1
714
748
 
715
749
    try:
722
756
    except pysvn.ClientError, e:
723
757
        # Error code 170000 means ENOENT in this revision.
724
758
        if e[1][0][1] == 170000:
725
 
            req.status = 404
726
 
            raise ActionError('The specified repository path does not exist')
 
759
            raise util.IVLEError(404, 'The specified repository path does not exist')
727
760
        else:
728
761
            raise ActionError(str(e[0]))
729
762
 
736
769
    path = fields.getfirst('path')
737
770
    if path is None:
738
771
        raise ActionError("Required field missing")
739
 
    path = actionpath_to_local(req, path).decode('utf-8')
 
772
    path = actionpath_to_local(req, path)
740
773
 
741
774
    try:
742
775
        svnclient.cleanup(path)
762
795
    "svnupdate" : action_svnupdate,
763
796
    "svnresolved" : action_svnresolved,
764
797
    "svnrevert" : action_svnrevert,
 
798
    "svnpublish" : action_svnpublish,
 
799
    "svnunpublish" : action_svnunpublish,
765
800
    "svncommit" : action_svncommit,
766
801
    "svncheckout" : action_svncheckout,
767
802
    "svnrepomkdir" : action_svnrepomkdir,