Subversion commit from Python?

J

Jack Trades

I'm wondering if there's an easy way to do a 'svn commit' on a
directory from Python.

More Details:
I have a wiki-like program that stores its data in a directory that I
would like to put under version control to be able to roll back
unwanted changes. The program is stored in two directories, a 'cgi'
directory which displays the data and allows user editing and a 'data'
directory. The 'data' directory is a checked-out version of the
repository.
Originally I had the 'data' directory in the same directory as the cgi
scripts and was using os.system("svn commit"), however I kept running
into weird bugs with this method. So I moved the data directory out
of the cgi directory and plan to use a separate repository. So is
there a prefered way to commit this directory to a subversion
repository from a Python script?
 
L

Lawrence D'Oliveiro

In message <2904e7de-0a8d-4697-9c44-
Originally I had the 'data' directory in the same directory as the cgi
scripts and was using os.system("svn commit"), however I kept running
into weird bugs with this method.

What bugs?
 
J

Jack Trades

In message <2904e7de-0a8d-4697-9c44-



What bugs?

I'm not 100% sure, but I think it had to do with executable
permissions on the cgi scripts. I would click on a link in the main
document (named 'add section') and it worked as expected. After
inserting the information for 'add section' and submitting it (info
was saved in the data folder, then a commit was done on the whole
project), clicking on the same 'add section' link would produce an
error (going back to the 'add section' script asked me to download it
instead of displaying it).

I'm using a very simple server to develop this on my computer...

import BaseHTTPServer
import CGIHTTPServer
import cgitb; cgitb.enable() ## This line enables CGI error reporting

server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", 8000)
handler.cgi_directories = [""]

httpd = server(server_address, handler)
httpd.serve_forever()

I got no information about the error at all, and after some time
completely gave up on it. I'm only guessing that it was a permissions
problem. I have made a huge number of modifications to the program
since then (about 2 days ago), and am unable to investigate it
further. I was just wondering if using os.system('svn commit') was
the right approach, or if there was a "more Pythonic" way of doing
this.
 
L

Lawrence D'Oliveiro

In message <ac63e27e-2dd9-4c27-ace0-
I'm not 100% sure, but I think it had to do with executable
permissions on the cgi scripts.

Possibly your CGI scripts are running as some user like "nobody", which
doesn't have the right access to the files/directories. Changing APIs won't
help here.
 
J

Jack Trades

Jack Trades said:
Originally I had the 'data' directory in the same directory as the cgi
scripts and was using os.system("svn commit"), however I kept running
into weird bugs with this method.  So I moved the data directory out
of the cgi directory and plan to use a separate repository.  So is
there a prefered way to commit this directory to a subversion
repository from a Python script?

Subversion has Python bindings, but for a friendlier interface have a look
athttp://pysvn.tigris.org/

An example from the docs athttp://pysvn.tigris.org/docs/pysvn_prog_guide.html:

Commit changes to the repository

import pysvn
# edit the file foo.txt
f = open('./examples/pysvn/foo.txt', 'w')
f.write('Sample versioned file via python\n')
f.close()
# checkin the change with a log message
client = pysvn.Client()
client.checkin(['./examples/pysvn'], 'Corrected spelling of python in foo..txt')

Thanks that's what I was looking for.
 
J

Jack Trades

In message <ac63e27e-2dd9-4c27-ace0-




Possibly your CGI scripts are running as some user like "nobody", which
doesn't have the right access to the files/directories. Changing APIs won't
help here.

Thanks for the help, I'll have to look into that further. If that is
the case, would setuid be appropriate here? Or is there a better way
to give the script the appropriate permissions?
The only thing that baffles me is that the script works before a
commit and only sometimes after a commit, if it were an access problem
wouldn't it fail before the commit as well?
 
D

Diez B. Roggisch

Jack said:
Thanks for the help, I'll have to look into that further. If that is
the case, would setuid be appropriate here? Or is there a better way
to give the script the appropriate permissions?
The only thing that baffles me is that the script works before a
commit and only sometimes after a commit, if it were an access problem
wouldn't it fail before the commit as well?

I have had many troubles with SVN + permissions.

My recipe is the following:

- create (or use) a "subversion"-group
- make all users (including e.g. www-data) that shall access the SVN
members of this group
- chown -R the svn-repository so that it belongs to this group
- chmod g+s -R to the svn-repository, so that the sticky group bit is set.

THis solves the problems for me usually.

Diez
 
L

Lawrence D'Oliveiro

I have had many troubles with SVN + permissions.

I create a custom captive user to own write access to the repository, with
access only to keys belonging to authorized users via svn+ssh. Problem
solved.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top