How to programmatically get SVN revision number?

2024/10/4 5:36:53

Like this question, but without the need to actually query the SVN server. This is a web-based project, so I figure I'll just use the repository as the public view (unless someone can advise me why this is a bad idea). I assume this info is in a file in the .svn folder somewhere, but where, and how do I parse it? I want to do something like what SO does, having the revision in the bottom-right corner.

Code in Python or PHP appreciated if you have it on hand, or just a point in the right direction.

Answer

Subversion includes the svnversion tool for exactly this purpose. A working copy may actually have local modifications, or may consist of a mix of revisions. svnversion knows how to handle that; see the examples in the linked documentation.

You can invoke svnversion from python like this:

import subprocessdef svnversion():p = subprocess.Popen("svnversion", stdout=subprocess.PIPE, stderr=subprocess.PIPE)(stdout, stderr) = p.communicate()return stdout
https://en.xdnf.cn/q/70646.html

Related Q&A

Convert fractional years to a real date in Python

How do I convert fractional years to a real date by using Python? E. g. I have an array [2012.343, 2012.444, 2012.509] containing fractional years and I would like to get "yyyy-mm-dd hh:mm".

Django template: Translate include with variable

I have a template in which you can pass a text variable. I want to include this template into another one but with a translated text as its variable. How can you achieve this?I would like something li…

Pandas - Creating a New Column

I have always made new columns in pandas using the following:df[new_column] = valueI am using this method, however, am receiving the warning for setting a copy.What is the way to make a new column with…

Adding an extra column to (big) SQLite database from Pandas dataframe

I feel like Im overlooking something really simple, but I cant make it work. Im using SQLite now, but a solution in SQLAlchemy would also be very helpful.Lets create our original dataset:### This is ju…

error inserting values to db with psycopg2 module [duplicate]

This question already has answers here:psycopg2: cant adapt type numpy.int64(4 answers)Inserting records into postgreSQL database in Python(3 answers)Closed 3 months ago.I am attempting to insert a dat…

NaN values in pivot_table index causes loss of data

Here is a simple DataFrame:> df = pd.DataFrame({a: [a1, a2, a3],b: [optional1, None, optional3],c: [c1, c2, c3],d: [1, 2, 3]}) > dfa b c d 0 a1 optional1 c1 1 1 a2 None c2…

ModuleNotFoundError in Docker

I have imported my entire project into docker, and I am getting a ModuleNotFoundErrorfrom one of the modules I have created.FROM python:3.8 WORKDIR /workspace/ COPY . /workspace/ RUN pip install pipenv…

Can I use md5 authentication with psycopg2?

After two hours of reading documentation, source code and help-threads, Im giving up. I cant get psycopg2 to authenticate with a md5-string. According to this thread I dont have to anything besides ena…

Python checking __init__ parameter

Ive been trying to figuring this out for the last few hours, and Im about to give up.How do you make sure that in python only a matching specific criteria will create the object?For example, lets say …

Minidom getElementById not working

Minidoms getElementById function is returning None for any entry I pass to it.For example, this code:l = minidom.parseString(<node id="node">Node</node>) print(l.getElementById(&q…