ATLAS Offline Software
Loading...
Searching...
No Matches
python.utility.revision_checking Namespace Reference

Functions

 check_svn_revision (path)

Function Documentation

◆ check_svn_revision()

python.utility.revision_checking.check_svn_revision ( path)
Infer used SVN code revision.

@param path location of the code whose SVN revision will be checked.

If the target path is not an SVN repository, a manually maintained text file database of revisions will be
consulted as a fallback.

If neither the SVN check nor the fallback solution finds a revision, 'unknown' will be returned.

@author Stefan Richter  <stefan.richter@cern.ch>

Definition at line 6 of file revision_checking.py.

6def check_svn_revision(path):
7 """
8 Infer used SVN code revision.
9
10 @param path location of the code whose SVN revision will be checked.
11
12 If the target path is not an SVN repository, a manually maintained text file database of revisions will be
13 consulted as a fallback.
14
15 If neither the SVN check nor the fallback solution finds a revision, 'unknown' will be returned.
16
17 @author Stefan Richter <stefan.richter@cern.ch>
18 """
19 try:
20 # Try getting the revision hash from the SVN repository
21 command = "svn info {path}".format(path=os.path.realpath(path)) # expand symbolic links
22 p = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
23 (svninfo, _) = p.communicate()
24 for line in svninfo.split('\n'):
25 if "Revision:" in line:
26 return line.split()[-1]
27 except Exception:
28 # If it fails for whatever reason, ignore it
29 pass
30 try:
31 # As a fallback solution, try to read the revision from a text database
32 with open(os.path.join(os.environ["POWHEGPATH"], "ProcessRevisions.txt"), "r") as dbfile:
33 for line in dbfile:
34 tokens = line.split(" : ")
35 if tokens[0] == os.path.basename(path): # found the process of interest
36 return tokens[1][1:] # return the revision number without the leading 'r'
37 except Exception:
38 # If it fails for whatever reason, ignore it
39 pass
40 # Neither method of getting the revision hash worked, so it is marked as "unknown"
41 return "unknown"