0

I have a program written in Python. I deploy changes to the users using SVN. In some cases the SVN get stuck and the changes are not downloaded to the user computer. In such case I need to perform SVN CLEANUP manually. The problem is that I don't know which station has which revision. so the users continue to work on older revisions which causes problems.

I want to write a code that on program lunch it will compare the local SVN revision with the server and if it doesn't match a message will appear.

I have managed to write the code which gets the revision of the server:

import re,subprocess
svn_info = subprocess.check_output("svn info svn_address")
print (re.search(ur"Revision:\s\d+", svn_info)).group() 

But I don't understand how do I get the local revision in order to compare.

If I go to the SVN local folder and do:

svn info

I see the local revision. But I don't know how to access this data inside the python code.

Any idea?

avi
  • 1,626
  • 3
  • 27
  • 45

2 Answers2

1

I would recommend to use a "maintained" python SVN wrapper instead of trying to parse text results of an external command yourself. Have a look here.

Nicolas Garnier
  • 436
  • 3
  • 9
  • I don't think it's needed to install a package for just two integers. the print is just for me.. it won't be in the code itself.... I need a way to know the local svn revision. Can you help with that? :) – avi Feb 21 '17 at 11:41
  • Yes you're right, that was just a personal point of view, no need to an endless debate about such a tiny design issue ;-) To answer your question, I believe svn info (without svn address) gives the local revision. But I didn't use it for a while now, so I may be mistaken. EDIT Sorry, just saw you edited your question... – Nicolas Garnier Feb 21 '17 at 11:56
  • it is true that svn info gives the answer but it works when I do it manualy as i'm in the correct directory... if I do it in the python it tells me : svn: warning: '.' is not a working copy – avi Feb 21 '17 at 12:00
  • Ok. So you can try os.chdir(). Alternatively, you could try to pipe cd /youpath with svn info subprocessees : http://stackoverflow.com/questions/13332268/python-subprocess-command-with-pipe I find the first one cleaner. – Nicolas Garnier Feb 21 '17 at 12:10
  • os.chdir() won't help me... I don't want to change any path... Everything works as it should I simply try to access information... Regarding the link i'm not sure how do I use it? – avi Feb 21 '17 at 12:17
  • Are you sure that won't help you ? If you change cwd to the root of your local svn folder, svn info should respond. For the second solution, you are right, I went too fast. You just need to execute in sequence two commands: subprocess.check_output("cd /yourpath && svn info", shell=True). – Nicolas Garnier Feb 21 '17 at 12:45
  • But this is the thing... each user installed the program on different location, upon installtion it does svn checkout on the selected folder. When the program lunches it checks for the updates in the SVN and it there are it does SVN UPDATE. it works... but sometimes stuck.. I simply want to access the revision number. Why do I need to specify the path? the program should have it somewhere.. otherwise nothing would work. – avi Feb 21 '17 at 12:55
  • Oh right! That's why I was struggling to understand the problem... There is a beginning of explanation in the official svn client documentation (scroll down) : http://svnbook.red-bean.com/en/1.7/svn.ref.svn.c.update.html. Nothing of the like mentioned for svn info, but you can try. – Nicolas Garnier Feb 21 '17 at 13:05
  • couldn't find any answer there. – avi Feb 21 '17 at 13:48
0

2 years after I want the same things. I produce this to get the local SVN version in python:

import os
getSVNversion=os.popen('svnversion .').read()
revision=''.join(c for c in getSVNversion if c.isdigit())
print(revision)

Clearly not the best solution or "maintained" solution but it work.

daday001
  • 91
  • 1
  • 9