I'd like to submit the spanish localization of the post-commit-hook

This is the same file as trac-post-commit-hook but with Spanish
localization to allow messages like "arregla el bug 9"

A big thanks to Stephen Hansen for the original hook


Javier Parra
+--------------------------------------------------------+
Eccentricity is not, as dull people would have us believe, a form of
madness. It is often a kind of innocent pride, and the man of genius
and the aristocrat are frequently regarded as eccentrics because
genius and aristocrat are entirely unafraid of and uninfluenced by the
opinions and vagaries of the crowd.
- Edith Sitwell
+--------------------------------------------------------+
===BEGIN FILE===
#!/usr/bin/env python

# trac-post-commit-hoo
# Version en espaniol por Javier Parra Cervantes <javier
[email protected]>>
#
----------------------------------------------------------------------------
# Copyright (c) 2004 Stephen Hansen
#
# Permission is hereby granted, free of charge, to any person
obtaining a copy
# of this software and associated documentation files (the
"Software"), to
# deal in the Software without restriction, including without
limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or
# sell copies of the Software, and to permit persons to whom the
Software is
# furnished to do so, subject to the following conditions:
#
#   The above copyright notice and this permission notice shall be
included in
#   all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS
# IN THE SOFTWARE.
#
----------------------------------------------------------------------------

# This Subversion post-commit hook script is meant to interface to the
# Trac (http://www.edgewall.com/products/trac/) issue tracking/wiki/
etc
# system.
#
# It should be called from the 'post-commit' script in Subversion,
such as
# via:
#
# REPOS="$1"
# REV="$2"
# TRAC_ENV="/path/to/tracenv"
#
# /usr/bin/python /usr/local/src/trac/contrib/trac-post-commit-hook \
#  -p "$TRAC_ENV" -r "$REV"
#
# (all the other arguments are now deprecated and not needed anymore)
#
# Busca en los mensajes del commit texto en la siguiente forma:
#  * command #1
#  * command #1, #2
#  * command #1 & #2
#  * command #1 and #2
#  * command #1 y #2
#
#
#  en lugar de la sintaxis "#1", "ticket:1" puede ser usada y puedes
poner los articulos "a", "al" o "el" entre comando y ticket ejemplo:
#  * command ticket:1
#  * command ticket:1, ticket:2
#  * command ticket:1 & ticket:2
#  * command ticket:1 and ticket:2
#  * command el ticket:1 y al ticket:2
#
#
#  Se puede omitir ":" (pero no sale el link en trac) y cambiar ticket
por issue o bug.
#
#  Puedes tener m Re#
#
#   Comando para cerrar el ticket y agregar a sus notas el mensaje de
commit.
#    close
#    closed
#    closes
#    fix
#    fixed
#    fixes
#    cierra
#    arregla
#
#
#  Comando para dejar el ticket en su estatus original y agregar el
mensaje de commit a sus notas:
#
#    references
#    refs
#    addresses
#    re
#    see
#    referencia
#    ver
#    respecto
#
#
#  Un ejemplo de mensaje de commit avanzado:
#
#     Estoy probando el linkeo con los tickets, particularmente la
traduccion espaniol de los comandos.
#     Arregla al bug:5 y el ticket:9, y referencia a #1.
#
# Ese commit cerrara los tickets 5 y 9 y agregara una nota al 1
Import sys
from datetime import datetime
from optparse import OptionParser

parser = OptionParser()
depr = '(not used anymore)'
parser.add_option('-e', '--require-envelope', dest='envelope',
default='',
                  help="""
Require commands to be enclosed in an envelope.
If -e[], then commands must be in the form of [closes #4].
Must be two characters.""")
parser.add_option('-p', '--project', dest='project',
                  help='Path to the Trac project.')
parser.add_option('-r', '--revision', dest='rev',
                  help='Repository revision number.')
parser.add_option('-u', '--user', dest='user',
                  help='The user who is responsible for this action
'+depr)
parser.add_option('-m', '--msg', dest='msg',
                  help='The log message to search '+depr)
parser.add_option('-c', '--encoding', dest='encoding',
                  help='The encoding used by the log message '+depr)
parser.add_option('-s', '--siteurl', dest='url',
                  help=depr+' the base_url from trac.ini will always
be used.')

(options, args) = parser.parse_args(sys.argv[1:])

if not 'PYTHON_EGG_CACHE' in os.environ:
    os.environ['PYTHON_EGG_CACHE'] = os.path.join(options.project,
'.egg-cache')

from trac.env import open_environment
from trac.ticket.notification import TicketNotifyEmail
from trac.ticket import Ticket
from trac.ticket.web_ui import TicketModule
# TODO: move grouped_changelog_entries to model.py
from trac.util.text import to_unicode
from trac.util.datefmt import utc
from trac.versioncontrol.api import NoSuchChangeset

ticket_prefix = '(?:\s(?:al?|el)\s)?(?:#|(?:ticket|issue|bug)[: ]?)'
ticket_reference = ticket_prefix + '[0-9]+'
ticket_command =  (r'(?P<action>[A-Za-z]*).?'
                   '(?P<ticket>%s(?:(?:[, &y]*|[ ]?[(and)(y)][ ]?)%s)
*)' %
                   (ticket_reference, ticket_reference))

if options.envelope:
    ticket_command = r'\%s%s\%s' % (options.envelope[0],
ticket_command,
                                    options.envelope[1])

command_re = re.compile(ticket_command)
ticket_re = re.compile(ticket_prefix + '([0-9]+)')

class CommitHook:
    _supported_cmds = {'close':      '_cmdClose',
                       'closed':     '_cmdClose',
                       'closes':     '_cmdClose',
                       'cierra':     '_cmdClose',
                       'arregla':    '_cmdClose',
                       'fix':        '_cmdClose',
                       'fixed':      '_cmdClose',
                       'fixes':      '_cmdClose',
                       'addresses':  '_cmdRefs',
                       're':         '_cmdRefs',
                       'references': '_cmdRefs',
                       'refs':       '_cmdRefs',
                       'referencia': '_cmdRefs',
                       'ver':        '_cmdRefs',
                       'respecto':   '_cmdRefs',
                       'refs':       '_cmdRefs',
                       'see':        '_cmdRefs'}

    def __init__(self, project=options.project, author=options.user,
                 rev=options.rev, url=options.url):
        self.env = open_environment(project)
        repos = self.env.get_repository()
        repos.sync()

        # Instead of bothering with the encoding, we'll use unicode
data
        # as provided by the Trac versioncontrol API (#1310).
        try:
            chgset = repos.get_changeset(rev)
        except NoSuchChangeset:
            return # out of scope changesets are not cached
        self.author = chgset.author
        self.rev = rev
        self.msg = "(In [%s]) %s" % (rev, chgset.message)
        self.now = datetime.now(utc)

        cmd_groups = command_re.findall(self.msg)

        tickets = {}
        for cmd, tkts in cmd_groups:
            funcname = CommitHook._supported_cmds.get(cmd.lower(), '')
            if funcname:
                for tkt_id in ticket_re.findall(tkts):
                    func = getattr(self, funcname)
                    tickets.setdefault(tkt_id, []).append(func)

        for tkt_id, cmds in tickets.iteritems():
            try:
                db = self.env.get_db_cnx()

                ticket = Ticket(self.env, int(tkt_id), db)
                for cmd in cmds:
                    cmd(ticket)

                # determine sequence number...
                cnum = 0
                tm = TicketModule(self.env)
                for change in tm.grouped_changelog_entries(ticket,
db):
                    if change['permanent']:
                        cnum += 1

                ticket.save_changes(self.author, self.msg, self.now,
db, cnum+1)
                db.commit()

                tn = TicketNotifyEmail(self.env)
                tn.notify(ticket, newticket=0, modtime=self.now)
            except Exception, e:
                # import traceback
                # traceback.print_exc(file=sys.stderr)
                print>>sys.stderr, 'Unexpected error while processing
ticket ' \
                                   'ID %s: %s' % (tkt_id, e)


    def _cmdClose(self, ticket):
        ticket['status'] = 'closed'
        ticket['resolution'] = 'fixed'

    def _cmdRefs(self, ticket):
        pass


if __name__ == "__main__":
    if len(sys.argv) < 5:
        print "For usage: %s --help" % (sys.argv[0])
        print
        print "Note that the deprecated options will be removed in
Trac 0.12."
    else:
        CommitHook()
-- 
You received this message because you are subscribed to the Google Groups "Trac 
Development" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/trac-dev?hl=en.


Reply via email to