~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-18 03:31:47 UTC
  • Revision ID: grantw@unimelb.edu.au-20100218033147-z1es9tzrx7eg85gu
Ensure that we always close the DB connection at request termination, even in the case of an exception.

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
572
580
    Reads fields: 'path' (multiple)
573
581
    """
574
582
    paths = fields.getlist('path')
575
 
    paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
576
 
                paths)
 
583
    paths = map(lambda path: actionpath_to_local(req, path), paths)
577
584
 
578
585
    try:
579
586
        svnclient.add(paths, recurse=True, force=True)
586
593
    Reads fields: 'path' (multiple)
587
594
    """
588
595
    paths = fields.getlist('path')
589
 
    paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
590
 
                paths)
 
596
    paths = map(lambda path: actionpath_to_local(req, path), paths)
591
597
 
592
598
    try:
593
599
        svnclient.remove(paths, force=True)
611
617
                    int(revision))
612
618
        except ValueError, e:
613
619
            raise ActionError("Bad revision number: '%s'"%revision,)
614
 
    path = actionpath_to_local(req, path).decode('utf-8')
 
620
    path = actionpath_to_local(req, path)
615
621
 
616
622
    try:
617
623
        svnclient.update(path, recurse=True, revision=revision)
626
632
    path = fields.getfirst('path')
627
633
    if path is None:
628
634
        raise ActionError("Required field missing")
629
 
    path = actionpath_to_local(req, path).decode('utf-8')
 
635
    path = actionpath_to_local(req, path)
630
636
 
631
637
    try:
632
638
        svnclient.resolved(path, recurse=True)
639
645
    Reads fields: 'path' (multiple)
640
646
    """
641
647
    paths = fields.getlist('path')
642
 
    paths = map(lambda path: actionpath_to_local(req, path).decode('utf-8'),
643
 
                paths)
 
648
    paths = map(lambda path: actionpath_to_local(req, path), paths)
644
649
 
645
650
    try:
646
651
        svnclient.revert(paths, recurse=True)
647
652
    except pysvn.ClientError, e:
648
653
        raise ActionError(str(e))
649
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
 
650
695
def action_svncommit(req, fields):
651
696
    """Performs a "svn commit" to each file specified.
652
697
 
653
698
    Reads fields: 'path' (multiple), 'logmsg' (optional)
654
699
    """
655
700
    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')
 
701
    paths = map(lambda path: actionpath_to_local(req, str(path)), paths)
 
702
    logmsg = str(fields.getfirst('logmsg', DEFAULT_LOGMESSAGE))
663
703
    if logmsg == '': logmsg = DEFAULT_LOGMESSAGE
664
704
 
665
705
    try:
677
717
        raise ActionError("usage: svncheckout url local-path")
678
718
    url = ivle.conf.svn_addr + "/" + urllib.quote(paths[0])
679
719
    local_path = actionpath_to_local(req, str(paths[1]))
680
 
    url = url.decode('utf-8')
681
 
    local_path = local_path.decode('utf-8')
682
720
    try:
683
721
        svnclient.checkout(url, local_path, recurse=True)
684
722
    except pysvn.ClientError, e:
691
729
    """
692
730
    path = fields.getfirst('path')
693
731
    logmsg = fields.getfirst('logmsg')
694
 
    url = (ivle.conf.svn_addr + "/" + urllib.quote(path)).decode('utf-8')
 
732
    url = ivle.conf.svn_addr + "/" + urllib.quote(path)
695
733
    try:
696
734
        svnclient.mkdir(url, log_message=logmsg)
697
735
    except pysvn.ClientError, e:
705
743
    Reads fields: 'path'
706
744
    """
707
745
    path = fields.getfirst('path')
708
 
    url = (ivle.conf.svn_addr + "/" + urllib.quote(path)).decode('utf-8')
 
746
    url = ivle.conf.svn_addr + "/" + urllib.quote(path)
709
747
    svnclient.exception_style = 1
710
748
 
711
749
    try:
731
769
    path = fields.getfirst('path')
732
770
    if path is None:
733
771
        raise ActionError("Required field missing")
734
 
    path = actionpath_to_local(req, path).decode('utf-8')
 
772
    path = actionpath_to_local(req, path)
735
773
 
736
774
    try:
737
775
        svnclient.cleanup(path)
757
795
    "svnupdate" : action_svnupdate,
758
796
    "svnresolved" : action_svnresolved,
759
797
    "svnrevert" : action_svnrevert,
 
798
    "svnpublish" : action_svnpublish,
 
799
    "svnunpublish" : action_svnunpublish,
760
800
    "svncommit" : action_svncommit,
761
801
    "svncheckout" : action_svncheckout,
762
802
    "svnrepomkdir" : action_svnrepomkdir,