~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: 2010-02-25 08:21:47 UTC
  • Revision ID: matt.giuca@gmail.com-20100225082147-tus03ah630n74156
ProjectSet view: Prettied up the group management interface, including fixing delete icons.

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
 
#
95
 
# action=svnpublish: Set the "published" flag on a file to True.
96
 
#       path:   The path to the file to be published. Can be specified
97
 
#               multiple times.
98
 
#
99
 
# action=svnunpublish: Set the "published" flag on a file to False.
100
 
#       path:   The path to the file to be unpublished. Can be specified
101
 
#               multiple times.
 
94
#       revision: The revision number to update to. If not provided this
 
95
#               defaults to HEAD.
102
96
#
103
97
# action=svncommit: Commit a file(s) or directory(s) to the repository.
104
98
#       path:   The path to the file or directory to be committed. Can be
119
113
#       path:   The path to the directory to be checked (under the IVLE
120
114
#               repository base).
121
115
#
 
116
# action=svncleanup: Recursively clean up the working copy, removing locks,
 
117
#   resuming unfinished operations, etc.
 
118
#       path:   The path to the directory to be cleaned
 
119
#
122
120
# TODO: Implement the following actions:
123
121
#   svnupdate (done?)
124
122
# TODO: Implement ZIP unpacking in putfiles (done?).
138
136
from ivle import (util, studpath, zip)
139
137
from ivle.fileservice_lib.exceptions import WillNotOverwrite
140
138
import ivle.conf
141
 
 
142
 
 
143
 
def get_login(_realm, existing_login, _may_save):
144
 
    """Callback function used by pysvn for authentication.
145
 
    realm, existing_login, _may_save: The 3 arguments passed by pysvn to
146
 
        callback_get_login.
147
 
        The following has been determined empirically, not from docs:
148
 
        existing_login will be the name of the user who owns the process on
149
 
        the first attempt, "" on subsequent attempts. We use this fact.
150
 
    """
151
 
    # Only provide credentials on the _first_ attempt.
152
 
    # If we're being asked again, then it means the credentials failed for
153
 
    # some reason and we should just fail. (This is not desirable, but it's
154
 
    # better than being asked an infinite number of times).
155
 
    return (existing_login != "", str(ivle.conf.login),
156
 
                                  str(ivle.conf.svn_pass), True)
157
 
 
158
 
# Make a Subversion client object
159
 
svnclient = pysvn.Client()
160
 
svnclient.callback_get_login = get_login
 
139
import ivle.svn
 
140
 
 
141
# Make a Subversion client object (which will log in with this user's
 
142
# credentials, upon request)
 
143
svnclient = ivle.svn.create_auth_svn_client(username=ivle.conf.login,
 
144
                                            password=ivle.conf.svn_pass)
161
145
svnclient.exception_style = 0               # Simple (string) exceptions
162
146
 
163
147
DEFAULT_LOGMESSAGE = "No log message supplied."
588
572
    Reads fields: 'path' (multiple)
589
573
    """
590
574
    paths = fields.getlist('path')
591
 
    paths = map(lambda path: actionpath_to_local(req, path), paths)
 
575
    paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
 
576
                paths)
592
577
 
593
578
    try:
594
579
        svnclient.add(paths, recurse=True, force=True)
601
586
    Reads fields: 'path' (multiple)
602
587
    """
603
588
    paths = fields.getlist('path')
604
 
    paths = map(lambda path: actionpath_to_local(req, path), paths)
 
589
    paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
 
590
                paths)
605
591
 
606
592
    try:
607
593
        svnclient.remove(paths, force=True)
611
597
def action_svnupdate(req, fields):
612
598
    """Performs a "svn update" to each file specified.
613
599
 
614
 
    Reads fields: 'path'
 
600
    Reads fields: 'path' and 'revision'
615
601
    """
616
602
    path = fields.getfirst('path')
 
603
    revision = fields.getfirst('revision')
617
604
    if path is None:
618
605
        raise ActionError("Required field missing")
619
 
    path = actionpath_to_local(req, path)
 
606
    if revision is None:
 
607
        revision = pysvn.Revision( pysvn.opt_revision_kind.head )
 
608
    else:
 
609
        try:
 
610
            revision = pysvn.Revision(pysvn.opt_revision_kind.number,
 
611
                    int(revision))
 
612
        except ValueError, e:
 
613
            raise ActionError("Bad revision number: '%s'"%revision,)
 
614
    path = actionpath_to_local(req, path).decode('utf-8')
620
615
 
621
616
    try:
622
 
        svnclient.update(path, recurse=True)
 
617
        svnclient.update(path, recurse=True, revision=revision)
623
618
    except pysvn.ClientError, e:
624
619
        raise ActionError(str(e))
625
620
 
631
626
    path = fields.getfirst('path')
632
627
    if path is None:
633
628
        raise ActionError("Required field missing")
634
 
    path = actionpath_to_local(req, path)
 
629
    path = actionpath_to_local(req, path).decode('utf-8')
635
630
 
636
631
    try:
637
632
        svnclient.resolved(path, recurse=True)
644
639
    Reads fields: 'path' (multiple)
645
640
    """
646
641
    paths = fields.getlist('path')
647
 
    paths = map(lambda path: actionpath_to_local(req, path), paths)
 
642
    paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
 
643
                paths)
648
644
 
649
645
    try:
650
646
        svnclient.revert(paths, recurse=True)
651
647
    except pysvn.ClientError, e:
652
648
        raise ActionError(str(e))
653
649
 
654
 
def action_svnpublish(req, fields):
655
 
    """Sets svn property "ivle:published" on each file specified.
656
 
    Should only be called on directories (only effective on directories
657
 
    anyway).
658
 
 
659
 
    Reads fields: 'path'
660
 
 
661
 
    XXX Currently unused by the client (calls action_publish instead, which
662
 
    has a completely different publishing model).
663
 
    """
664
 
    paths = fields.getlist('path')
665
 
    if len(paths):
666
 
        paths = map(lambda path: actionpath_to_local(req, path), paths)
667
 
    else:
668
 
        paths = [studpath.to_home_path(req.path)]
669
 
 
670
 
    try:
671
 
        for path in paths:
672
 
            # Note: Property value doesn't matter
673
 
            svnclient.propset("ivle:published", "", path, recurse=False)
674
 
    except pysvn.ClientError, e:
675
 
        raise ActionError("Directory could not be published")
676
 
 
677
 
def action_svnunpublish(req, fields):
678
 
    """Deletes svn property "ivle:published" on each file specified.
679
 
 
680
 
    Reads fields: 'path'
681
 
 
682
 
    XXX Currently unused by the client (calls action_unpublish instead, which
683
 
    has a completely different publishing model).
684
 
    """
685
 
    paths = fields.getlist('path')
686
 
    paths = map(lambda path: actionpath_to_local(req, path), paths)
687
 
 
688
 
    try:
689
 
        for path in paths:
690
 
            svnclient.propdel("ivle:published", path, recurse=False)
691
 
    except pysvn.ClientError, e:
692
 
        raise ActionError("Directory could not be unpublished")
693
 
 
694
650
def action_svncommit(req, fields):
695
651
    """Performs a "svn commit" to each file specified.
696
652
 
697
653
    Reads fields: 'path' (multiple), 'logmsg' (optional)
698
654
    """
699
655
    paths = fields.getlist('path')
700
 
    paths = map(lambda path: actionpath_to_local(req, str(path)), paths)
701
 
    logmsg = str(fields.getfirst('logmsg', DEFAULT_LOGMESSAGE))
 
656
    if len(paths):
 
657
        paths = map(lambda path:actionpath_to_local(req,path).decode('utf-8'),
 
658
                    paths)
 
659
    else:
 
660
        paths = [studpath.to_home_path(req.path).decode('utf-8')]
 
661
    logmsg = str(fields.getfirst('logmsg',
 
662
                 DEFAULT_LOGMESSAGE)).decode('utf-8')
702
663
    if logmsg == '': logmsg = DEFAULT_LOGMESSAGE
703
664
 
704
665
    try:
716
677
        raise ActionError("usage: svncheckout url local-path")
717
678
    url = ivle.conf.svn_addr + "/" + urllib.quote(paths[0])
718
679
    local_path = actionpath_to_local(req, str(paths[1]))
 
680
    url = url.decode('utf-8')
 
681
    local_path = local_path.decode('utf-8')
719
682
    try:
720
 
        svnclient.callback_get_login = get_login
721
683
        svnclient.checkout(url, local_path, recurse=True)
722
684
    except pysvn.ClientError, e:
723
685
        raise ActionError(str(e))
729
691
    """
730
692
    path = fields.getfirst('path')
731
693
    logmsg = fields.getfirst('logmsg')
732
 
    url = ivle.conf.svn_addr + "/" + path
 
694
    url = (ivle.conf.svn_addr + "/" + urllib.quote(path)).decode('utf-8')
733
695
    try:
734
 
        svnclient.callback_get_login = get_login
735
696
        svnclient.mkdir(url, log_message=logmsg)
736
697
    except pysvn.ClientError, e:
737
698
        raise ActionError(str(e))
744
705
    Reads fields: 'path'
745
706
    """
746
707
    path = fields.getfirst('path')
747
 
    url = ivle.conf.svn_addr + "/" + path
 
708
    url = (ivle.conf.svn_addr + "/" + urllib.quote(path)).decode('utf-8')
748
709
    svnclient.exception_style = 1
749
710
 
750
711
    try:
751
 
        svnclient.callback_get_login = get_login
752
712
        info = svnclient.info2(url,
753
713
            revision=pysvn.Revision(pysvn.opt_revision_kind.head))[0][1]
754
714
        return {'svnrevision': info['rev'].number
761
721
            raise util.IVLEError(404, 'The specified repository path does not exist')
762
722
        else:
763
723
            raise ActionError(str(e[0]))
764
 
            
 
724
 
 
725
 
 
726
def action_svncleanup(req, fields):
 
727
    """Recursively clean up the working copy, removing locks, resuming 
 
728
    unfinished operations, etc.
 
729
        path:   The path to be cleaned"""
 
730
 
 
731
    path = fields.getfirst('path')
 
732
    if path is None:
 
733
        raise ActionError("Required field missing")
 
734
    path = actionpath_to_local(req, path).decode('utf-8')
 
735
 
 
736
    try:
 
737
        svnclient.cleanup(path)
 
738
    except pysvn.ClientError, e:
 
739
        raise ActionError(str(e))
 
740
 
765
741
 
766
742
# Table of all action functions #
767
743
# Each function has the interface f(req, fields).
781
757
    "svnupdate" : action_svnupdate,
782
758
    "svnresolved" : action_svnresolved,
783
759
    "svnrevert" : action_svnrevert,
784
 
    "svnpublish" : action_svnpublish,
785
 
    "svnunpublish" : action_svnunpublish,
786
760
    "svncommit" : action_svncommit,
787
761
    "svncheckout" : action_svncheckout,
788
762
    "svnrepomkdir" : action_svnrepomkdir,
789
763
    "svnrepostat" : action_svnrepostat,
 
764
    "svncleanup" : action_svncleanup,
790
765
}