Changeset 7486
- Timestamp:
- Sep 7, 2009, 12:15:04 PM (14 years ago)
- Location:
- anuga_core/source/anuga/utilities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/system_tools.py
r7483 r7486 56 56 return host 57 57 58 59 60 61 62 def __get_revision_from_svn_entries__(): 63 """Get a subversion revision number from the .svn/entries file.""" 64 65 66 msg = ''' 67 No version info stored and command 'svn' is not recognised on the system PATH. 68 69 If ANUGA has been installed from a distribution e.g. as obtained from SourceForge, 70 the version info should be available in the automatically generated file 71 'stored_version_info.py' in the anuga root directory. 72 73 If run from a Subversion sandpit, ANUGA will try to obtain the version info by 74 using the command 'svn info'. In this case, make sure the command line client 75 'svn' is accessible on the system path. Simply aliasing 'svn' to the binary will 76 not work. 77 78 If you are using Windows, you have to install the file svn.exe which can be 79 obtained from http://www.collab.net/downloads/subversion. 80 81 Good luck! 82 ''' 83 84 try: 85 fd = open(os.path.join('.svn', 'entries')) 86 except: 87 raise Exception, msg 88 89 line = fd.readlines()[3] 90 fd.close() 91 try: 92 revision_number = int(line) 93 except: 94 msg = ".svn/entries, line 4 was '%s'?" % line.strip() 95 raise Exception, msg 96 97 return revision_number 98 99 def __get_revision_from_svn_client__(): 100 """Get a subversion revision number from an svn client.""" 101 102 if sys.platform[0:3] == 'win': 103 try: 104 fid = os.popen(r'C:\Program Files\TortoiseSVN\bin\SubWCRev.exe') 105 except: 106 return __get_revision_from_svn_entries__() 107 else: 108 version_info = fid.read() 109 if version_info == '': 110 return __get_revision_from_svn_entries__() 111 112 # split revision number from data 113 for line in version_info.split('\n'): 114 if line.startswith('Updated to revision '): 115 break 116 117 fields = line.split(' ') 118 msg = 'Keyword "Revision" was not found anywhere in text: %s' % version_info 119 assert fields[0].startswith('Updated'), msg 120 121 try: 122 revision_number = int(fields[3]) 123 except: 124 msg = ('Revision number must be an integer. I got "%s" from ' 125 '"SubWCRev.exe".' % fields[3]) 126 raise Exception, msg 127 else: # assume Linux 128 try: 129 fid = os.popen('svn info . 2>/dev/null') 130 except: 131 return __get_revision_from_svn_entries__() 132 else: 133 version_info = fid.read() 134 if version_info == '': 135 return __get_revision_from_svn_entries__() 136 137 # Split revision number from data 138 for line in version_info.split('\n'): 139 if line.startswith('Revision:'): 140 break 141 142 fields = line.split(':') 143 msg = 'Keyword "Revision" was not found anywhere in text: %s' % version_info 144 assert fields[0].startswith('Revision'), msg 145 146 147 #if ':' in version_info: 148 # revision_number, _ = version_info.split(':', 1) 149 # msg = ('Some modules have not been checked in. ' 150 # 'Using last version from repository: %s' % revision_number) 151 # warnings.warn(msg) 152 #else: 153 # revision_number = version_info 154 155 try: 156 revision_number = int(fields[1]) 157 except: 158 msg = ("Revision number must be an integer. I got '%s' from " 159 "'svn'." % fields[1]) 160 raise Exception, msg 161 162 return revision_number 163 164 165 166 167 58 168 def get_revision_number(): 59 169 """Get the version number of this repository copy. … … 68 178 """ 69 179 70 def get_revision_from_svn_entries():71 '''Get a subversion revision number from the .svn/entries file.'''72 73 msg = '''74 No version info stored and command 'svn' is not recognised on the system PATH.75 76 If ANUGA has been installed from a distribution e.g. as obtained from SourceForge,77 the version info should be available in the automatically generated file78 'stored_version_info.py' in the anuga root directory.79 80 If run from a Subversion sandpit, ANUGA will try to obtain the version info by81 using the command 'svn info'. In this case, make sure the command line client82 'svn' is accessible on the system path. Simply aliasing 'svn' to the binary will83 not work.84 85 If you are using Windows, you have to install the file svn.exe which can be86 obtained from http://www.collab.net/downloads/subversion.87 88 Good luck!89 '''90 91 try:92 fd = open(os.path.join('.svn', 'entries'))93 except:94 raise Exception, msg95 96 line = fd.readlines()[3]97 fd.close()98 try:99 revision_number = int(line)100 except:101 msg = ".svn/entries, line 4 was '%s'?" % line.strip()102 raise Exception, msg103 104 return revision_number105 106 def get_revision_from_svn_client():107 '''Get a subversion revision number from an svn client.'''108 109 if sys.platform[0:3] == 'win':110 try:111 fid = os.popen(r'C:\Program Files\TortoiseSVN\bin\SubWCRev.exe')112 except:113 return get_revision_from_svn_entries()114 else:115 version_info = fid.read()116 if version_info == '':117 return get_revision_from_svn_entries()118 119 # split revision number from data120 for line in version_info.split('\n'):121 if line.startswith('Updated to revision '):122 break123 124 fields = line.split(' ')125 msg = 'Keyword "Revision" was not found anywhere in text: %s' % version_info126 assert fields[0].startswith('Updated'), msg127 128 try:129 revision_number = int(fields[3])130 except:131 msg = ("Revision number must be an integer. I got '%s' from "132 "'SubWCRev.exe'." % fields[3])133 raise Exception, msg134 else: # assume Linux135 try:136 fid = os.popen('svnversion -n . 2>/dev/null')137 except:138 return get_revision_from_svn_entries()139 else:140 version_info = fid.read()141 if version_info == '':142 return get_revision_from_svn_entries()143 144 # Split revision number from data145 if ':' in version_info:146 revision_number, _ = version_info.split(':',1)147 msg = ('Some modules have not been checked in. '148 'Using last version from repository: %s' % revision_number)149 warnings.warn(msg)150 else:151 revision_number = version_info152 153 try:154 revision_number = int(revision_number)155 except:156 msg = ("Revision number must be an integer. I got '%s' from "157 "'svn'." % version_info)158 raise Exception, msg159 160 return revision_number161 162 180 # try to get revision information from stored_version_info.py 163 181 try: 164 182 from anuga.stored_version_info import version_info 165 183 except: 166 return get_revision_from_svn_client()184 return __get_revision_from_svn_client__() 167 185 168 186 # split revision number from data -
anuga_core/source/anuga/utilities/test_system_tools.py
r7276 r7486 461 461 msg = 'Expected file_length() to return 1000, but got %d' % size4 462 462 self.failUnless(size4 == 1000, msg) 463 464 465 466 def test_get_revision_number(self): 467 """test_get_revision_number 468 469 Test that a revision number is returned. 470 This should work both from a sandpit with access to Subversion 471 and also in distributions where revision number has been stored 472 explicitly in anuga.stored_version_info.version_info 473 """ 474 475 x = get_revision_number() 476 assert int(x) 463 477 464 478 ################################################################################
Note: See TracChangeset
for help on using the changeset viewer.