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.                                     # 
  6  #                                                                             # 
  7  # relax 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 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax 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 relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """Module for relax version information.""" 
 25   
 26  # Python module imports. 
 27  from os import F_OK, access, sep 
 28  from string import split 
 29  from subprocess import PIPE, Popen 
 30   
 31  # relax module imports. 
 32  from status import Status; status = Status() 
 33   
 34   
 35  version = "2.0.0" 
 36   
 37   
38 -def revision():
39 """Attempt to retrieve the SVN revision number, if this is a checked out copy. 40 41 @return: The SVN revision number, or None if unsuccessful. 42 @rtype: None or str 43 """ 44 45 # Does the base directory exist (i.e. is this a checked out copy). 46 if not access(status.install_path+sep+'.svn', F_OK): 47 return 48 49 # Try to run 'svn info'. 50 pipe = Popen('svn info %s' % status.install_path, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) 51 52 # Errors. 53 if pipe.stderr.readlines(): 54 return 55 56 # Loop over the output lines. 57 for line in pipe.stdout.readlines(): 58 # Split up the line. 59 row = split(line) 60 61 # The revision. 62 if row[0] == 'Revision:': 63 return row[1]
64 65
66 -def url():
67 """Attempt to retrieve the SVN URL, if this is a checked out copy. 68 69 @return: The SVN URL, or None if unsuccessful. 70 @rtype: None or str 71 """ 72 73 # Does the base directory exist (i.e. is this a checked out copy). 74 if not access(status.install_path+sep+'.svn', F_OK): 75 return 76 77 # Try to run 'svn info'. 78 pipe = Popen('svn info %s' % status.install_path, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False) 79 80 # Errors. 81 if pipe.stderr.readlines(): 82 return 83 84 # Loop over the output lines. 85 for line in pipe.stdout.readlines(): 86 # Split up the line. 87 row = split(line) 88 89 # The revision. 90 if row[0] == 'URL:': 91 return row[1]
92 93
94 -def version_full():
95 """Return the full relax version, including all SVN info for repository versions. 96 97 @return: The relax version string. 98 @rtype: str 99 """ 100 101 # The relax version. 102 ver = version 103 104 # Repository version. 105 if ver == 'repository checkout': 106 # Get the SVN revision and URL. 107 svn_rev = revision() 108 svn_url = url() 109 110 # Change the version string. 111 if svn_rev: 112 ver = version + " r" + svn_rev 113 if svn_url: 114 ver = ver + " " + svn_url 115 116 # Return the version. 117 return ver
118