Subversion commit from Python?

Discussion in 'Python' started by Jack Trades, May 19, 2009.

  1. Jack Trades

    Jack Trades Guest

    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?
     
    Jack Trades, May 19, 2009
    #1
    1. Advertising

  2. In message <2904e7de-0a8d-4697-9c44-
    >, Jack Trades wrote:

    > 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?
     
    Lawrence D'Oliveiro, May 19, 2009
    #2
    1. Advertising

  3. Jack Trades

    Jack Trades Guest

    On May 19, 12:26 am, Lawrence D'Oliveiro <l...@geek-
    central.gen.new_zealand> wrote:
    > In message <2904e7de-0a8d-4697-9c44-
    >
    > >, Jack Trades wrote:
    > > 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?


    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.
     
    Jack Trades, May 19, 2009
    #3
  4. Jack Trades

    Tim Golden Guest

    Tim Golden, May 19, 2009
    #4
  5. In message <ac63e27e-2dd9-4c27-ace0-
    >, Jack Trades wrote:

    > On May 19, 12:26 am, Lawrence D'Oliveiro <l...@geek-
    > central.gen.new_zealand> wrote:
    >
    >> In message <2904e7de-0a8d-4697-9c44-
    >>
    >> >, Jack Trades wrote:
    >> > 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?

    >
    > 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.
     
    Lawrence D'Oliveiro, May 19, 2009
    #5
  6. Jack Trades

    Jack Trades Guest

    On May 19, 3:46 am, Duncan Booth <> wrote:
    > Jack Trades <> wrote:
    > > 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')
    >
    > --
    > Duncan Boothhttp://kupuguy.blogspot.com


    Thanks that's what I was looking for.
     
    Jack Trades, May 19, 2009
    #6
  7. Jack Trades

    Jack Trades Guest

    On May 19, 3:53 am, Lawrence D'Oliveiro <l...@geek-
    central.gen.new_zealand> wrote:
    > In message <ac63e27e-2dd9-4c27-ace0-
    >
    > >, Jack Trades wrote:
    > > On May 19, 12:26 am, Lawrence D'Oliveiro <l...@geek-
    > > central.gen.new_zealand> wrote:

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

    >
    > >> >, Jack Trades wrote:
    > >> > 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?

    >
    > > 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.


    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?
     
    Jack Trades, May 19, 2009
    #7
  8. Jack Trades wrote:

    > On May 19, 3:53 am, Lawrence D'Oliveiro <l...@geek-
    > central.gen.new_zealand> wrote:
    >> In message <ac63e27e-2dd9-4c27-ace0-
    >>
    >> >, Jack Trades wrote:
    >> > On May 19, 12:26 am, Lawrence D'Oliveiro <l...@geek-
    >> > central.gen.new_zealand> wrote:

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

    >>
    >> >> >, Jack Trades wrote:
    >> >> > 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?

    >>
    >> > 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.

    >
    > 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
     
    Diez B. Roggisch, May 19, 2009
    #8
  9. In message <>, Jack Trades wrote:

    > On May 19, 3:53 am, Lawrence D'Oliveiro <_zealand> wrote:
    >
    >> 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.

    >
    > If that is the case, would setuid be appropriate here?


    You mean suexec? Certainly, yes.
     
    Lawrence D'Oliveiro, May 20, 2009
    #9
  10. In message <-berlin.de>, Diez B. Roggisch wrote:

    > 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.
     
    Lawrence D'Oliveiro, May 20, 2009
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Thomas_Gagn=E9?=

    Connection auto commit - No begin?

    =?ISO-8859-1?Q?Thomas_Gagn=E9?=, Nov 19, 2003, in forum: Java
    Replies:
    1
    Views:
    2,826
    John C. Bollinger
    Nov 19, 2003
  2. evil tabby cat

    python svn pre-commit hook

    evil tabby cat, Jul 2, 2007, in forum: Python
    Replies:
    0
    Views:
    994
    evil tabby cat
    Jul 2, 2007
  3. Replies:
    5
    Views:
    795
    John B. Matthews
    Apr 30, 2010
  4. Replies:
    0
    Views:
    383
  5. Tom Copeland
    Replies:
    2
    Views:
    119
    Tom Copeland
    Feb 27, 2006
Loading...

Share This Page