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

Source Code for Module version

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009-2012 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 = "2.1.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 # Split up the line. 66 row = line.split() 67 68 # The revision. 69 if len(row) and row[0] == 'Revision:': 70 return row[1]
71 72
73 -def url():
74 """Attempt to retrieve the SVN URL, if this is a checked out copy. 75 76 @return: The SVN URL, or None if unsuccessful. 77 @rtype: None or str 78 """ 79 80 # Does the base directory exist (i.e. is this a checked out copy). 81 if not access(status.install_path+sep+'.svn', F_OK): 82 return 83 84 # Python 2.3 and earlier. 85 if Popen == None: 86 return 87 88 # Try to run 'svn info'. 89 pipe = Popen('svn info %s' % status.install_path, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) 90 91 # Errors. 92 if pipe.stderr.readlines(): 93 return 94 95 # Loop over the output lines. 96 for line in pipe.stdout.readlines(): 97 # Split up the line. 98 row = line.split() 99 100 # The revision. 101 if len(row) and row[0] == 'URL:': 102 return row[1]
103 104
105 -def version_full():
106 """Return the full relax version, including all SVN info for repository versions. 107 108 @return: The relax version string. 109 @rtype: str 110 """ 111 112 # The relax version. 113 ver = version 114 115 # Repository version. 116 if ver == 'repository checkout': 117 # Get the SVN revision and URL. 118 svn_rev = revision() 119 svn_url = url() 120 121 # Change the version string. 122 if svn_rev: 123 ver = version + " r" + svn_rev 124 if svn_url: 125 ver = ver + " " + svn_url 126 127 # Return the version. 128 return ver
129