-
Notifications
You must be signed in to change notification settings - Fork 1
/
version.py
119 lines (92 loc) · 4.04 KB
/
version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
###############################################################################
# #
# Copyright (C) 2009-2014 Edward d'Auvergne #
# #
# This file is part of the program relax (http://www.nmr-relax.com). #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
# Module docstring.
"""Module for relax version information."""
# Python module imports.
from os import F_OK, access, sep
try:
from subprocess import PIPE, Popen
except ImportError:
PIPE, Popen = None, None
# relax module imports.
import lib.structure.internal.object
from status import Status; status = Status()
version = "repository checkout"
repo_revision = None
repo_url = None
def repo_information():
"""Determine the subversion revision number and URL from svn or git-svn copies of the repository."""
# The global variables
global repo_revision
global repo_url
# The variables are already set, so do nothing.
if repo_revision != None or repo_url != None:
return
# Python 2.3 and earlier.
if Popen == None:
return
# The command to use.
cmd = None
if access(status.install_path+sep+'.svn', F_OK):
cmd = 'svn info %s' % status.install_path
elif access(status.install_path+sep+'.git', F_OK):
cmd = 'cd %s; git svn info' % status.install_path
# Not a repository copy, so do nothing.
if not cmd:
return
# Open the pipe and run the command.
pipe = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False)
# Loop over the output lines.
for line in pipe.stdout.readlines():
# Decode Python 3 byte arrays.
if hasattr(line, 'decode'):
line = line.decode()
# Split up the line.
row = line.split()
# Store revision as the global variable.
if len(row) and row[0] == 'Revision:':
repo_revision = str(row[1])
# Store URL as the global variable.
if len(row) and row[0] == 'URL:':
repo_url = str(row[1])
def version_full():
"""Return the full relax version, including all SVN info for repository versions.
@return: The relax version string.
@rtype: str
"""
# The relax version.
ver = version
# Repository version.
if ver == 'repository checkout':
# The global variables
global repo_revision
global repo_url
# Change the version string.
if repo_revision != None:
ver = version + " r" + repo_revision
if repo_url != None:
ver = ver + " " + repo_url
# Return the version.
return ver
# Fetch the repository information, if present.
repo_information()
# Set the version in the relax internal structural object.
lib.structure.internal.object.RELAX_VERSION = version_full()