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

Source Code for Module version

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