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
21 command = "svn info {path}".format(path=os.path.realpath(path))
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
29 pass
30 try:
31
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):
36 return tokens[1][1:]
37 except Exception:
38
39 pass
40
41 return "unknown"