Bitnami Trac 0.11.6 Ошибка при фиксации после коммита SVN - PullRequest
0 голосов
/ 21 июля 2010

Я бьюсь головой об стену в течение дня, пытаясь заставить работать зацепки после коммита, чтобы я мог добавлять ссылки / закрывать заявки в trac из коммита SVN.Я использовал стек bitnami trac для установки и довольно доволен его установкой.

Каждый коммит, хотя и дает ошибку

svn: MERGE из "/ svn / Project":200 OK (http://10.0.0.204)

Из различных сообщений я вижу, что это происходит из-за сбоя перехвата после фиксации, но при успешной фиксации SVN. Я использовал стандартный скрипт с сайта edgewall и мои файлыВыглядит как ниже (извините за длину, которую они создают в посте, но я думаю, чем больше информации, тем лучше ..)

post-commit.cmd

@ECHO OFF 


:: POST-COMMIT HOOK 
:: 
:: The post-commit hook is invoked after a commit.  Subversion runs 
:: this hook by invoking a program (script, executable, binary, etc.) 
:: named 'post-commit' (for which this file is a template) with the  
:: following ordered arguments: 
:: 
::   [1] REPOS-PATH   (the path to this repository) 
::   [2] REV          (the number of the revision just committed) 
:: 
:: The default working directory for the invocation is undefined, so 
:: the program should set one explicitly if it cares. 
:: 
:: Because the commit has already completed and cannot be undone, 
:: the exit code of the hook program is ignored.  The hook program 
:: can use the 'svnlook' utility to help it examine the 
:: newly-committed tree. 
:: 
:: On a Unix system, the normal procedure is to have 'post-commit' 
:: invoke other programs to do the real work, though it may do the 
:: work itself too. 
:: 
:: Note that 'post-commit' must be executable by the user(s) who will 
:: invoke it (typically the user httpd runs as), and that user must 
:: have filesystem-level permission to access the repository. 
:: 
:: On a Windows system, you should name the hook program 
:: 'post-commit.bat' or 'post-commit.exe', 
:: but the basic idea is the same. 
::  
:: The hook program typically does not inherit the environment of 
:: its parent process.  For example, a common problem is for the 
:: PATH environment variable to not be set to its usual value, so 
:: that subprograms fail to launch unless invoked via absolute path. 
:: If you're having unexpected problems with a hook program, the 
:: culprit may be unusual (or missing) environment variables. 
::  
:: Here is an example hook script, for a Unix /bin/sh interpreter. 
:: For more examples and pre-written hooks, see those in 
:: the Subversion repository at 
:: http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/ and 
:: http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/ 


setlocal 


:: Debugging setup 
:: 1. Make a copy of this file. 
:: 2. Enable the command below to call the copied file. 
:: 3. Remove all other commands 
::call %~dp0post-commit-run.cmd %* > %1/hooks/post-commit.log 2>&1 


:: Call Trac post-commit hook 
call %~dp0trac-post-commit-hook.cmd %* || exit 1

trac-post-commit-hook.cmd

@ECHO OFF 
:: 
:: Trac post-commit-hook script for Windows 
:: 
:: Contributed by markus, modified by cboos. 


:: Usage: 
:: 
:: 1) Insert the following line in your post-commit.bat script 
:: 
:: call %~dp0\trac-post-commit-hook.cmd %1 %2 
:: 
:: 2) Check the 'Modify paths' section below, be sure to set at least TRAC_ENV 


setlocal 


:: ---------------------------------------------------------- 
:: Modify paths here: 


:: -- this one *must* be set 
SET TRAC_ENV=E:\Trac\Project\Project


:: -- set if Python is not in the system path 
:: SET PYTHON_PATH= 


:: -- set to the folder containing trac/ if installed in a non-standard location 
:: SET TRAC_PATH= "C:\Program Files\Bitnami Trac Stack\"
:: ---------------------------------------------------------- 


:: Do not execute hook if trac environment does not exist 
IF NOT EXIST %TRAC_ENV% GOTO :EOF 


set PATH=%PYTHON_PATH%;%PATH% 
set PYTHONPATH=%TRAC_PATH%;%PYTHONPATH% 


SET REV=%2 


:: Resolve ticket references (fixes, closes, refs, etc.) 
Python "%~dp0trac-post-commit-resolve-ticket-ref.py" -p "%TRAC_ENV%" -r "%REV%" 


endlocal 

не удалил комментарии из пути к траку, но не думаю, что это необходимо. Наконец, скрипт из edgewall..

trac-post-commit-resolve-ticket-ref.py

#!/usr/bin/env python

# trac-post-commit-hook
# ----------------------------------------------------------------------------
# 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)
#
# It searches commit messages for text in the form of:
#   command #1
#   command #1, #2
#   command #1 & #2 
#   command #1 and #2
#
# Instead of the short-hand syntax "#1", "ticket:1" can be used as well, e.g.:
#   command ticket:1
#   command ticket:1, ticket:2
#   command ticket:1 & ticket:2 
#   command ticket:1 and ticket:2
#
# In addition, the ':' character can be omitted and issue or bug can be used
# instead of ticket.
#
# You can have more than one command in a message. The following commands
# are supported. There is more than one spelling for each command, to make
# this as user-friendly as possible.
#
#   close, closed, closes, fix, fixed, fixes
#     The specified issue numbers are closed with the contents of this
#     commit message being added to it. 
#   references, refs, addresses, re, see 
#     The specified issue numbers are left in their current status, but 
#     the contents of this commit message are added to their notes. 
#
# A fairly complicated example of what you can do is with a commit message
# of:
#
#    Changed blah and foo to do this or that. Fixes #10 and #12, and refs #12.
#
# This will close #10 and #12, and add a note to #12.

import re
import os
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 = '(?:#|(?:ticket|issue|bug)[: ]?)'
ticket_reference = ticket_prefix + '[0-9]+'
ticket_command =  (r'(?P<action>[A-Za-z]*).?'
                   '(?P<ticket>%s(?:(?:[, &]*|[ ]?and[ ]?)%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',
                       'fix':        '_cmdClose',
                       'fixed':      '_cmdClose',
                       'fixes':      '_cmdClose',
                       'addresses':  '_cmdRefs',
                       're':         '_cmdRefs',
                       'references': '_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()

Если кто-нибудь может понять, почему скрипт Python каким-то образом не работает, он быдействительно помогите мне. Спасибо ... .WM

--- обновление

Отследил команду и получил следующеев файле журнала.

Traceback (most recent call last):
  File "E:\Repos\Project\hooks\trac-post-commit-resolve-ticket-ref.py", line 209, in <module>
    CommitHook()
  File "E:\Repos\Project\hooks\trac-post-commit-resolve-ticket-ref.py", line 144, in __init__
    repos = self.env.get_repository()
  File "c:\program files\bitnami trac stack\trac\lib\site-packages\Trac-0.11.6-py2.5.egg\trac\env.py", line 305, in get_repository
    return RepositoryManager(self).get_repository(authname)
  File "c:\program files\bitnami trac stack\trac\lib\site-packages\Trac-0.11.6-py2.5.egg\trac\versioncontrol\api.py", line 142, in get_repository
    error=to_unicode(connector.error)))
trac.core.TracError: Unsupported version control system "svn": "DLL load failed with error code 182" 

Поскольку я работал в какой-то момент перед тем, как связываться с SSL, мне интересно, было ли что-то перемещено или удалено по ошибке ... какие-либо подсказки?

1 Ответ

3 голосов
/ 26 июля 2010

Импорт работал из командной строки.Проблема оказалась в пути.Не работало задание пути python в файле скрипта или в качестве системной переменной PYTHON_PATH или PYTHONPATH.Он будет правильно запускать команду python, но тогда не будет использовать правильные привязки SVN.Добавление местоположения директории python в систему Path работало.все равно спасибо!

...