Trees | Indices | Help |
|
---|
|
1 ############################################################################### 2 # # 3 # Copyright (C) 2006,2009,2012-2014,2017-2018 Edward d'Auvergne # 4 # # 5 # This file is part of the program relax (http://www.nmr-relax.com). # 6 # # 7 # This program is free software: you can redistribute it and/or modify # 8 # it under the terms of the GNU General Public License as published by # 9 # the Free Software Foundation, either version 3 of the License, or # 10 # (at your option) any later version. # 11 # # 12 # This program is distributed in the hope that it will be useful, # 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of # 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 15 # GNU General Public License for more details. # 16 # # 17 # You should have received a copy of the GNU General Public License # 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. # 19 # # 20 ############################################################################### 21 22 # Module docstring. 23 """Module for relax version information.""" 24 25 # Python module imports. 26 from os import F_OK, access, sep 27 try: 28 from subprocess import PIPE, Popen 29 except ImportError: 30 PIPE, Popen = None, None 31 32 # relax module imports. 33 from lib.compat import SYSTEM 34 import lib.structure.internal.object 35 from status import Status; status = Status() 36 37 38 version = "4.1.3" 39 repo_head = None 40 repo_type = None 41 repo_url = None 42 4345 """Determine the subversion revision number and URL from svn or git-svn copies of the repository.""" 46 47 # The global variables 48 global repo_head 49 global repo_type 50 global repo_url 51 52 # The variables are already set, so do nothing. 53 if repo_head != None or repo_type != None or repo_url != None: 54 return 55 56 # Python 2.3 and earlier. 57 if Popen == None: 58 return 59 60 # Command separator. 61 symbol = ";" 62 if SYSTEM == 'Windows' or SYSTEM == 'Microsoft': 63 symbol = "&&" 64 65 # The command to use. 66 cmd = None 67 if access(status.install_path+sep+'.git'+sep+'svn'+sep+'refs', F_OK): 68 cmd = 'cd %s %s git svn info' % (status.install_path, symbol) 69 repo_type = 'git-svn' 70 elif access(status.install_path+sep+'.git', F_OK): 71 cmd = 'cd %s %s git rev-parse HEAD %s git remote -v' % (status.install_path, symbol, symbol) 72 repo_type = 'git' 73 elif access(status.install_path+sep+'.svn', F_OK): 74 cmd = 'svn info %s' % status.install_path 75 repo_type = 'svn' 76 77 # Not a repository copy, so do nothing. 78 if not cmd: 79 return 80 81 # Open the pipe and run the command. 82 pipe = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) 83 84 # Loop over the output lines. 85 lines = pipe.stdout.readlines() 86 for i in range(len(lines)): 87 # Decode Python 3 byte arrays. 88 if hasattr(lines[i], 'decode'): 89 lines[i] = lines[i].decode() 90 91 # Git info. 92 if repo_type == 'git': 93 # Git hash. 94 if i == 0: 95 repo_head = lines[i].strip() 96 continue 97 98 # Remote URL. 99 if repo_url: 100 repo_url += '\n' 101 else: 102 repo_url = '' 103 remote_info = lines[i].split() 104 repo_url += "%s %s" % (remote_info[1], remote_info[2]) 105 106 # SVN and git-svn. 107 else: 108 # Split up the line. 109 row = lines[i].split() 110 111 # Store revision as the global variable. 112 if len(row) and row[0] == 'Revision:': 113 repo_head = str(row[1]) 114 115 # Store URL as the global variable. 116 if len(row) and row[0] == 'URL:': 117 repo_url = str(row[1])118 119121 """Return the full relax version, including all SVN info for repository versions. 122 123 @return: The relax version string. 124 @rtype: str 125 """ 126 127 # The relax version. 128 ver = version 129 130 # Repository version. 131 if ver == 'repository commit': 132 # The global variables 133 global repo_head 134 global repo_type 135 global repo_url 136 137 # Change the version string. 138 if repo_head != None: 139 if repo_type == 'git': 140 ver = version + " " + repo_head 141 else: 142 ver = version + " r" + repo_head 143 if repo_url != None: 144 ver += " " + repo_url.replace('\n', '; ') 145 146 # Return the version. 147 return ver148 149 150 # Fetch the repository information, if present. 151 repo_information() 152 153 # Set the version in the relax internal structural object. 154 lib.structure.internal.object.RELAX_VERSION = version_full() 155
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Fri Jun 14 11:30:43 2019 | http://epydoc.sourceforge.net |