views:

338

answers:

1

Trying to set up the svn commit with trac using this script.

It is being called without issue, but the problem is this line here:

144 repos = self.env.get_repository()

Because I am calling this remotely self.env_get_repository() looks for the repository using the server drive and not the local drive mapping. That is, it is looking for E:/Projects/svn/InfoProj and not Y:/Projects/sv/InfoProj

I noticed a changeset on the trac set for being able to call get_repository() and passing in the path as the variable, but it seems this hasn't made it into the latest stable release yet.

This version of the script (the one submitted by code monkey) appears to do things differently, but is throwing an error that seems related:

154         if url is None:
155             url = self.env.config.get('project', 'url')
156         self.env.href = Href(url)
157         self.env.abs_href = Href(url)

Lines 156 / 157 throw error: Warning: TypeError: 'str' object is not callable

The 10.3 stable version of the script throws a completely different error: Warning: NameError: global name 'core' is not defined

I'm setting up trac for the first time on a Windows box with a remote repository. I'm using trac 0.11 stable with Python 2.6.

I thought there would have been a lot more people out there trying to commit across servers who had come across this problem. I've looked around and couldn't find a solution. I'm supposing Linux has a more graceful way of handling this.

Thanks in advance.

A: 

This is totally do-able and just requires a couple of small hacks... woo hoo!

The problem I was having is that get_repository reads the value of the svn repository from the trac.ini file. This was pointing at E:/ and not at Y:/. The simple fix involves a check to see if the repository is at *repository_dir* and if not, then check at a new variable *remote_repository_dir*. The second part of the fix involves removing the error message from cache.py that checks to see if the current repository address matches the one being passed in.

As always, use this at your own risk and back everything up before hand!!!

First open you trac.ini file and add a new variable 'remote_repository_dir' underneath the 'repository_dir' variable. Remote repository dir will point to the mapped drive on your local machine. It should now look something like this:

repository_dir = E:/Projects/svn/InfoProj
remote_repository_dir = Y:/Projects/svn/InfoProj

Next we will modify the api.py file to check for the new variable if it can't find the repository at the *repository_dir* location. Around :71 you should have something like this:

repository_dir = Option('trac', 'repository_dir', '',
    """Path to local repository. This can also be a relative path
    (''since 0.11'').""")

Underneath this line add:

remote_repository_dir = Option('trac', 'remote_repository_dir', '',
    """Path to remote repository.""")

Next near :156 you will have this:

            rtype, rdir = self.repository_type, self.repository_dir
            if not os.path.isabs(rdir):
                rdir = os.path.join(self.env.path, rdir)

Change that to this:

            rtype, rdir = self.repository_type, self.repository_dir
            if not os.path.isdir(rdir):
                rdir = self.remote_repository_dir
            if not os.path.isabs(rdir):
                rdir = os.path.join(self.env.path, rdir)

Finally you will need to remove the alert in the cache.py file (note this is not the best way to do this, you should be able to include the remote variable as part of the check, but for now it works).

In cache.py near :97 it should look like this:

    if repository_dir:
        # directory part of the repo name can vary on case insensitive fs
        if os.path.normcase(repository_dir) != os.path.normcase(self.name):
            self.log.info("'repository_dir' has changed from %r to %r"
                          % (repository_dir, self.name))
            raise TracError(_("The 'repository_dir' has changed, a "
                              "'trac-admin resync' operation is needed."))
    elif repository_dir is None: # 
        self.log.info('Storing initial "repository_dir": %s' % self.name)
        cursor.execute("INSERT INTO system (name,value) VALUES (%s,%s)",
                       (CACHE_REPOSITORY_DIR, self.name,))
    else: # 'repository_dir' cleared by a resync
        self.log.info('Resetting "repository_dir": %s' % self.name)
        cursor.execute("UPDATE system SET value=%s WHERE name=%s",
                       (self.name, CACHE_REPOSITORY_DIR))

We are going to remove the first part of the if statement so it now should look like this:

    if repository_dir is None: # 
        self.log.info('Storing initial "repository_dir": %s' % self.name)
        cursor.execute("INSERT INTO system (name,value) VALUES (%s,%s)",
                       (CACHE_REPOSITORY_DIR, self.name,))
    else: # 'repository_dir' cleared by a resync
        self.log.info('Resetting "repository_dir": %s' % self.name)
        cursor.execute("UPDATE system SET value=%s WHERE name=%s",
                       (self.name, CACHE_REPOSITORY_DIR))

Warning! Doing this will mean that it no longer gives you an error if your directory has changed and you need a resync.

Hope this helps someone.

xiaohouzi79