1

I'm automating project creation with a python script. I can create repositories, checkout, commit, and import directories, all from within python.

What it won't seem to do is set the svn:externals property. I can set this from command line but when I try to run the command with asubprocess.call it doesn't work.

Here's the command line (that works when in the checked-out project directory):

svn propset svn:externals "trunk/Source/Interactive/Flash.Externals https://server/svn/proj/" . 

Here's the script call (which runs after checking the repo out to gv.project_repo_dir):

# gv is a global variables object
odir = getcwd()
chdir(getcwd() + '/' + gv.project_repo_dir)
res = call(['svn', 'propset', 'svn:externals',                                                \
            '"'+ gv.interactive_subpath +'Flash.Externals '+ gv.mirror_project_repo_url +'"', \
            '.'])
chdir(odir)

Here's the error from the script run:

svn: Error parsing svn:externals property on '.': '"trunk/Source/Interactive/Flash.Externals https://server/svn/proj/"'

I've tried this with shell=True as an arg to the call and without; no dice.

Any ideas?

Stats:

  • Python 2.7
  • Windows Server 2003
  • VisualSVN
paul
  • 1,655
  • 11
  • 23

2 Answers2

1

I would recommend looking at the pysvn module vs. doing it through command line:

http://pysvn.tigris.org/

But if you have to do it through command line, can you use the os.system call instead of the subprocess?

os.system('svn propset svn:externals "trunk/Source/Interactive/Flash.Externals https://server/svn/proj/" . ')

should run "as shell", you just aren't able to get feedback from it - it will run the command and wait until the command is finished.

That, or you could try breaking the command up (not 100% sure if this works in Windows, but pretty sure):

import shlex
commands = shlex.split('svn propset svn:externals "trunk/Source/Interactive/Flash.Externals https://server/svn/proj/" .')
subprocess.call(commands)
Eric Hulser
  • 3,912
  • 21
  • 20
  • `os.system()` did the trick! The command runs fine now (though I think my target directory may be wrong because it's not actually linking to the external -- but that's another problem). Thanks! BTW, `os.system()` does return a return-code for the executed program on Windows NT, 2000, & XP. I *had* looked at pysvn but we'd have to remember to upgrade that should we upgrade our svn server in the future and that's just another thing to keep track of that could potentially break things. – paul Aug 03 '12 at 12:57
  • Sorry - yea, the os.system will return the return-code, but you can't PIPE the stdout/stdin/stderr like you can in subprocess if you wanted to say, log the output from the command to a file or anything. And I hear ya on keeping dependencies simple..all for that ;-) – Eric Hulser Aug 03 '12 at 16:49
  • As a side note though, I still have no idea why shell=True doesn't work on windows tho. Its documented on Python's page as not being supported for Windows...you'd just think it wouldn't be that hard to support... – Eric Hulser Aug 03 '12 at 16:49
  • But then, it *is* Windows after all.... I finally got the external to register properly -- I had to chdir into the full path `gv.project_repo_dir + 'trunk/Source/Interactive'` and make the command `svn propset svn:externals "Flash.Externals https://...`. Thanks again! – paul Aug 03 '12 at 17:31
0

I don't know I buy the "it doesn't work with shell=True" statement. The error shows that it interpreted the double quotation marks as literals, as in it's trying to use "trunk/Source/Interactive/Flash.Externals https://server/svn/proj/" as one of the execvp arguments. The double quotation marks only have special meaning to a shell.

Example:

>>> subprocess.call(["ls", '"."'], shell=False)
ls: ".": No such file or directory
2

With shell=True:

>>> subprocess.call(["ls", '"."'], shell=True)
metrics_poller.sock  OSL_PIPE_0_SingleOfficeIPC_b919ef148f655fcebc4bf633c062a098  sv9hg.tmp
metrics.sock         proc_mgr_stats                                               userinstall.mBa793
mysql_tzinfo_stderr  sess_716518f985ab8de017981347a8b61c611c9880bd                userinstall.omY802

Try removing the double quotes if the shell=True variation really doesn't help.

res = call(['svn', 'propset', 'svn:externals',                                                \
            gv.interactive_subpath +'Flash.Externals '+ gv.mirror_project_repo_url, \
            '.'])
Jeremy Brown
  • 17,880
  • 4
  • 35
  • 28