~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-08 02:10:26 UTC
  • Revision ID: coles.david@gmail.com-20091208021026-3a27ecdzm49y39me
Configuration documentation - fixing a few references

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
136
144
from ivle import (util, studpath, zip)
137
145
from ivle.fileservice_lib.exceptions import WillNotOverwrite
138
146
import ivle.conf
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)
 
147
 
 
148
 
 
149
def get_login(_realm, existing_login, _may_save):
 
150
    """Callback function used by pysvn for authentication.
 
151
    realm, existing_login, _may_save: The 3 arguments passed by pysvn to
 
152
        callback_get_login.
 
153
        The following has been determined empirically, not from docs:
 
154
        existing_login will be the name of the user who owns the process on
 
155
        the first attempt, "" on subsequent attempts. We use this fact.
 
156
    """
 
157
    # Only provide credentials on the _first_ attempt.
 
158
    # If we're being asked again, then it means the credentials failed for
 
159
    # some reason and we should just fail. (This is not desirable, but it's
 
160
    # better than being asked an infinite number of times).
 
161
    return (existing_login != "", str(ivle.conf.login),
 
162
                                  str(ivle.conf.svn_pass), True)
 
163
 
 
164
# Make a Subversion client object
 
165
svnclient = pysvn.Client()
 
166
svnclient.callback_get_login = get_login
145
167
svnclient.exception_style = 0               # Simple (string) exceptions
146
168
 
147
169
DEFAULT_LOGMESSAGE = "No log message supplied."
572
594
    Reads fields: 'path' (multiple)
573
595
    """
574
596
    paths = fields.getlist('path')
575
 
    paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
576
 
                paths)
 
597
    paths = map(lambda path: actionpath_to_local(req, path), paths)
577
598
 
578
599
    try:
579
600
        svnclient.add(paths, recurse=True, force=True)
586
607
    Reads fields: 'path' (multiple)
587
608
    """
588
609
    paths = fields.getlist('path')
589
 
    paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
590
 
                paths)
 
610
    paths = map(lambda path: actionpath_to_local(req, path), paths)
591
611
 
592
612
    try:
593
613
        svnclient.remove(paths, force=True)
611
631
                    int(revision))
612
632
        except ValueError, e:
613
633
            raise ActionError("Bad revision number: '%s'"%revision,)
614
 
    path = actionpath_to_local(req, path).decode('utf-8')
 
634
    path = actionpath_to_local(req, path)
615
635
 
616
636
    try:
617
637
        svnclient.update(path, recurse=True, revision=revision)
626
646
    path = fields.getfirst('path')
627
647
    if path is None:
628
648
        raise ActionError("Required field missing")
629
 
    path = actionpath_to_local(req, path).decode('utf-8')
 
649
    path = actionpath_to_local(req, path)
630
650
 
631
651
    try:
632
652
        svnclient.resolved(path, recurse=True)
639
659
    Reads fields: 'path' (multiple)
640
660
    """
641
661
    paths = fields.getlist('path')
642
 
    paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
643
 
                paths)
 
662
    paths = map(lambda path: actionpath_to_local(req, path), paths)
644
663
 
645
664
    try:
646
665
        svnclient.revert(paths, recurse=True)
647
666
    except pysvn.ClientError, e:
648
667
        raise ActionError(str(e))
649
668
 
 
669
def action_svnpublish(req, fields):
 
670
    """Sets svn property "ivle:published" on each file specified.
 
671
    Should only be called on directories (only effective on directories
 
672
    anyway).
 
673
 
 
674
    Reads fields: 'path'
 
675
 
 
676
    XXX Currently unused by the client (calls action_publish instead, which
 
677
    has a completely different publishing model).
 
678
    """
 
679
    paths = fields.getlist('path')
 
680
    if len(paths):
 
681
        paths = map(lambda path: actionpath_to_local(req, path), paths)
 
682
    else:
 
683
        paths = [studpath.to_home_path(req.path)]
 
684
 
 
685
    try:
 
686
        for path in paths:
 
687
            # Note: Property value doesn't matter
 
688
            svnclient.propset("ivle:published", "", path, recurse=False)
 
689
    except pysvn.ClientError, e:
 
690
        raise ActionError("Directory could not be published")
 
691
 
 
692
def action_svnunpublish(req, fields):
 
693
    """Deletes svn property "ivle:published" on each file specified.
 
694
 
 
695
    Reads fields: 'path'
 
696
 
 
697
    XXX Currently unused by the client (calls action_unpublish instead, which
 
698
    has a completely different publishing model).
 
699
    """
 
700
    paths = fields.getlist('path')
 
701
    paths = map(lambda path: actionpath_to_local(req, path), paths)
 
702
 
 
703
    try:
 
704
        for path in paths:
 
705
            svnclient.propdel("ivle:published", path, recurse=False)
 
706
    except pysvn.ClientError, e:
 
707
        raise ActionError("Directory could not be unpublished")
 
708
 
650
709
def action_svncommit(req, fields):
651
710
    """Performs a "svn commit" to each file specified.
652
711
 
653
712
    Reads fields: 'path' (multiple), 'logmsg' (optional)
654
713
    """
655
714
    paths = fields.getlist('path')
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')
 
715
    paths = map(lambda path: actionpath_to_local(req, str(path)), paths)
 
716
    logmsg = str(fields.getfirst('logmsg', DEFAULT_LOGMESSAGE))
663
717
    if logmsg == '': logmsg = DEFAULT_LOGMESSAGE
664
718
 
665
719
    try:
677
731
        raise ActionError("usage: svncheckout url local-path")
678
732
    url = ivle.conf.svn_addr + "/" + urllib.quote(paths[0])
679
733
    local_path = actionpath_to_local(req, str(paths[1]))
680
 
    url = url.decode('utf-8')
681
 
    local_path = local_path.decode('utf-8')
682
734
    try:
 
735
        svnclient.callback_get_login = get_login
683
736
        svnclient.checkout(url, local_path, recurse=True)
684
737
    except pysvn.ClientError, e:
685
738
        raise ActionError(str(e))
691
744
    """
692
745
    path = fields.getfirst('path')
693
746
    logmsg = fields.getfirst('logmsg')
694
 
    url = (ivle.conf.svn_addr + "/" + urllib.quote(path)).decode('utf-8')
 
747
    url = ivle.conf.svn_addr + "/" + path
695
748
    try:
 
749
        svnclient.callback_get_login = get_login
696
750
        svnclient.mkdir(url, log_message=logmsg)
697
751
    except pysvn.ClientError, e:
698
752
        raise ActionError(str(e))
705
759
    Reads fields: 'path'
706
760
    """
707
761
    path = fields.getfirst('path')
708
 
    url = (ivle.conf.svn_addr + "/" + urllib.quote(path)).decode('utf-8')
 
762
    url = ivle.conf.svn_addr + "/" + path
709
763
    svnclient.exception_style = 1
710
764
 
711
765
    try:
 
766
        svnclient.callback_get_login = get_login
712
767
        info = svnclient.info2(url,
713
768
            revision=pysvn.Revision(pysvn.opt_revision_kind.head))[0][1]
714
769
        return {'svnrevision': info['rev'].number
731
786
    path = fields.getfirst('path')
732
787
    if path is None:
733
788
        raise ActionError("Required field missing")
734
 
    path = actionpath_to_local(req, path).decode('utf-8')
 
789
    path = actionpath_to_local(req, path)
735
790
 
736
791
    try:
737
792
        svnclient.cleanup(path)
757
812
    "svnupdate" : action_svnupdate,
758
813
    "svnresolved" : action_svnresolved,
759
814
    "svnrevert" : action_svnrevert,
 
815
    "svnpublish" : action_svnpublish,
 
816
    "svnunpublish" : action_svnunpublish,
760
817
    "svncommit" : action_svncommit,
761
818
    "svncheckout" : action_svncheckout,
762
819
    "svnrepomkdir" : action_svnrepomkdir,