Module version
[hide private]
[frames] | no frames]

Source Code for Module version

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009-2013 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  # Dependencies. 
 26  import dep_check 
 27   
 28  # Python module imports. 
 29  from os import F_OK, access, sep 
 30  PIPE, Popen = None, None 
 31  if dep_check.subprocess_module: 
 32      from subprocess import PIPE, Popen 
 33   
 34  # relax module imports. 
 35  from status import Status; status = Status() 
 36   
 37   
 38  version = "3.0.2" 
 39   
 40   
41 -def revision():
42 """Attempt to retrieve the SVN revision number, if this is a checked out copy. 43 44 @return: The SVN revision number, or None if unsuccessful. 45 @rtype: None or str 46 """ 47 48 # Does the base directory exist (i.e. is this a checked out copy). 49 if not access(status.install_path+sep+'.svn', F_OK): 50 return 51 52 # Python 2.3 and earlier. 53 if Popen == None: 54 return 55 56 # Try to run 'svn info'. 57 pipe = Popen('svn info %s' % status.install_path, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) 58 59 # Errors. 60 if pipe.stderr.readlines(): 61 return 62 63 # Loop over the output lines. 64 for line in pipe.stdout.readlines(): 65 # Decode Python 3 byte arrays. 66 if hasattr(line, 'decode'): 67 line = line.decode() 68 69 # Split up the line. 70 row = line.split() 71 72 # The revision. 73 if len(row) and row[0] == 'Revision:': 74 return str(row[1])
75 76
77 -def url():
78 """Attempt to retrieve the SVN URL, if this is a checked out copy. 79 80 @return: The SVN URL, or None if unsuccessful. 81 @rtype: None or str 82 """ 83 84 # Does the base directory exist (i.e. is this a checked out copy). 85 if not access(status.install_path+sep+'.svn', F_OK): 86 return 87 88 # Python 2.3 and earlier. 89 if Popen == None: 90 return 91 92 # Try to run 'svn info'. 93 pipe = Popen('svn info %s' % status.install_path, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) 94 95 # Errors. 96 if pipe.stderr.readlines(): 97 return 98 99 # Loop over the output lines. 100 for line in pipe.stdout.readlines(): 101 # Decode Python 3 byte arrays. 102 if hasattr(line, 'decode'): 103 line = line.decode() 104 105 # Split up the line. 106 row = line.split() 107 108 # The revision. 109 if len(row) and row[0] == 'URL:': 110 return str(row[1])
111 112
113 -def version_full():
114 """Return the full relax version, including all SVN info for repository versions. 115 116 @return: The relax version string. 117 @rtype: str 118 """ 119 120 # The relax version. 121 ver = version 122 123 # Repository version. 124 if ver == 'repository checkout': 125 # Get the SVN revision and URL. 126 svn_rev = revision() 127 svn_url = url() 128 129 # Change the version string. 130 if svn_rev: 131 ver = version + " r" + svn_rev 132 if svn_url: 133 ver = ver + " " + svn_url 134 135 # Return the version. 136 return ver
137