Changeset 6859 for anuga_core/source
- Timestamp:
- Apr 21, 2009, 3:56:20 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/system_tools.py
r6852 r6859 49 49 50 50 def get_revision_number(): 51 """Get the version number of the SVN 51 """Get the version number of this repository copy. 52 53 Try getting data from stored_version_info.py first, otherwise 54 try using SubWCRev.exe (Windows) or svnversion (linux), otherwise 55 try reading file .svn/entries for version information, otherwise 56 throw an exception. 57 52 58 NOTE: This requires that the command svn is on the system PATH 53 59 (simply aliasing svn to the binary will not work) 54 60 """ 55 61 56 # Create dummy info 57 #info = 'Revision: Version info could not be obtained.' 58 #info += 'A command line version of svn must be availbable ' 59 #info += 'on the system PATH, access to the subversion ' 60 #info += 'repository is necessary and the output must ' 61 #info += 'contain a line starting with "Revision:"' 62 63 64 #FIXME (Ole): Change this so that svn info is attempted first. 65 # If that fails, try to read a stored file with that same info (this would be created by e.g. the release script). Failing that, throw an exception. 66 67 #FIXME (Ole): Move this and store_version_info to utilities 68 69 62 def get_revision_from_svn_entries(): 63 '''Get a subversion revision number from the .svn/entires file.''' 64 65 msg = ''' 66 No version info stored and command 'svn' is not recognised on the system PATH. 67 68 If ANUGA has been installed from a distribution e.g. as obtained from SourceForge, 69 the version info should be available in the automatically generated file 70 'stored_version_info.py' in the anuga root directory. 71 72 If run from a Subversion sandpit, ANUGA will try to obtain the version info by 73 using the command 'svn info'. In this case, make sure the command line client 74 'svn' is accessible on the system path. Simply aliasing 'svn' to the binary will 75 not work. 76 77 If you are using Windows, you have to install the file svn.exe which can be 78 obtained from http://www.collab.net/downloads/subversion. 79 80 Good luck! 81 ''' 82 83 try: 84 fd = open(os.path.join('.svn', 'entries')) 85 except: 86 raise Exception, msg 87 88 line = fd.readlines()[3] 89 fd.close() 90 try: 91 revision_number = int(line) 92 except: 93 msg = ".svn/entries, line 4 was '%s'?" % line.strip() 94 raise Exception, msg 95 96 return revision_number 97 98 def get_revision_from_svn_client(): 99 '''Get a subversion revision number from an svn client.''' 100 101 if sys.platform[0:3] == 'win': 102 try: 103 fid = os.popen(r'C:\Program Files\TortoiseSVN\bin\SubWCRev.exe') 104 except: 105 return get_revision_from_svn_entries() 106 else: 107 version_info = fid.read() 108 if version_info == '': 109 return get_revision_from_svn_entries() 110 111 # split revision number from data 112 for line in version_info.split('\n'): 113 if line.startswith('Updated to revision '): 114 break 115 116 fields = line.split(' ') 117 msg = 'Keyword "Revision" was not found anywhere in text: %s' % version_info 118 assert fields[0].startswith('Updated'), msg 119 120 try: 121 revision_number = int(fields[3]) 122 except: 123 msg = ("Revision number must be an integer. I got '%s' from " 124 "'SubWCRev.exe'." % fields[3]) 125 raise Exception, msg 126 else: # assume Linux 127 try: 128 fid = os.popen('svn info 2>/dev/null') 129 except: 130 return get_revision_from_svn_entries() 131 else: 132 version_info = fid.read() 133 if version_info == '': 134 return get_revision_from_svn_entries() 135 136 # split revision number from data 137 for line in version_info.split('\n'): 138 if line.startswith('Revision:'): 139 break 140 141 fields = line.split(':') 142 msg = 'Keyword "Revision" was not found anywhere in text: %s' % version_info 143 assert fields[0].startswith('Revision'), msg 144 145 try: 146 revision_number = int(fields[1]) 147 except: 148 msg = ("Revision number must be an integer. I got '%s' from " 149 "'svn'." % fields[1]) 150 raise Exception, msg 151 152 return revision_number 153 154 # try to get revision information from stored_version_info.py 70 155 try: 71 156 from anuga.stored_version_info import version_info 72 157 except: 73 msg = 'No version info stored and command "svn" is not ' 74 msg += 'recognised on the system PATH.\n\n' 75 msg += 'If ANUGA has been installed from a distribution e.g. as ' 76 msg += 'obtained from SourceForge,\n' 77 msg += 'the version info should be ' 78 msg += 'available in the automatically generated file ' 79 msg += 'stored_version_info.py\n' 80 msg += 'in the anuga root directory.\n' 81 msg += 'If run from a Subversion sandpit, ' 82 msg += 'ANUGA will try to obtain the version info ' 83 msg += 'by using the command: "svn info".\n' 84 msg += 'In this case, make sure the command line client ' 85 msg += 'svn is accessible on the system path. ' 86 msg += 'Simply aliasing svn to the binary will not work. ' 87 msg += 'If you are using Windows, you have to install the file svn.exe ' 88 msg += 'which can be obtained from e.g ' 89 msg += 'http://www.collab.net/downloads/subversion' 90 msg += 'Good luck!' 91 92 # No file available - try using Subversion 93 try: 94 # The null stuff is so this section fails quitly. 95 # This could cause the svn info command to fail due to 96 # the redirection being bad on some platforms. 97 # If that occurs then change this code. 98 if sys.platform[0:3] == 'win': 99 fid = os.popen('svn info 2> null') 100 else: 101 fid = os.popen('svn info 2>/dev/null') 102 103 except: 104 raise Exception(msg) 105 else: 106 #print 'Got version from svn' 107 version_info = fid.read() 108 109 if version_info == '': 110 raise Exception(msg) 111 else: 112 pass 113 #print 'Got version from file' 114 115 158 return get_revision_from_svn_client() 159 160 # split revision number from data 116 161 for line in version_info.split('\n'): 117 162 if line.startswith('Revision:'): … … 119 164 120 165 fields = line.split(':') 121 msg = 'Keyword "Revision" was not found anywhere in text: %s' % version_info122 assert fields[0].startswith('Revision'), msg 166 msg = 'Keyword "Revision" was not found anywhere in text: %s' % version_info 167 assert fields[0].startswith('Revision'), msg 123 168 124 169 try: 125 170 revision_number = int(fields[1]) 126 171 except: 127 msg = 'Revision number must be an integer. I got %s' %fields[1] 128 msg += 'Check that the command svn is on the system path' 129 raise Exception(msg) 130 172 msg = ("Revision number must be an integer. I got '%s'.\n" 173 'Check that the command svn is on the system path.' 174 % fields[1]) 175 raise Exception, msg 176 131 177 return revision_number 132 178
Note: See TracChangeset
for help on using the changeset viewer.