You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Yves Bergeron <yv...@shq.gouv.qc.ca> on 2005/10/06 18:29:53 UTC

How to get proplist for a file in a python script

Hi,

Using contrib/hook-scripts/pre-commit-check.py as a base script, I'm
trying to inspect the properties and check if svn:eol-style is set in
certain situations (depending on file extension).  I know there is a
perl script doing this thing (contrib/hook-scripts/check-mime-type.pl)
but I prefer python since I already done a lot of job in that language.

So, how can I get the property list for a file from a Python script ?

Thank you.


� Le pr�sent courriel peut contenir des renseignements confidentiels et ne s'adresse qu'au destinataire dont le nom appara�t ci-dessus. Si ce courriel vous est parvenu par m�garde, veuillez le supprimer et nous en aviser aussit�t. Merci. �


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: How to get proplist for a file in a python script

Posted by Stephane Bortzmeyer <bo...@nic.fr>.
On Thu, Oct 06, 2005 at 02:29:53PM -0400,
 Yves Bergeron <yv...@shq.gouv.qc.ca> wrote 
 a message of 19 lines which said:

> Hi,

Bonjour,
 
> I know there is a perl script doing this thing
> (contrib/hook-scripts/check-mime-type.pl) but I prefer python since
> I already done a lot of job in that language.

Here is how I do it:

#!/usr/bin/python

import pysvn
import getopt
import sys
import string
import time

# Options by default
path = "." # Current directory
recurse = False
MAX = 60

try:
    optlist, args = getopt.getopt (sys.argv[1:], "p:r",
                                   ["path=", "recurse!"])
    for option, value in optlist:
        if option == "--path" or option == "-p":
            path = value
        elif option == "--recurse" or option == "-r":
            recurse = True
        else:
            raise Exception ("Unknown option " + str(option))
except getopt.error, reason:
    raise Exception ("Usage: " + sys.argv[0] + ": " + str(reason))
if len(args) > 0:
    raise Exception ("Usage: " + sys.argv[0] + ": no arguments expected")
client = pysvn.Client()
files = client.ls(path, recurse=recurse)
for file in files:
    property = client.propget("svn:eol-style", "%s" % file['name'])
    if len(property) > 0:
        print file['name']

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org