Changeset 4170
- Timestamp:
- Jan 11, 2007, 2:38:03 PM (18 years ago)
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/test_util.py
r4160 r4170 1153 1153 warnings.resetwarnings() 1154 1154 1155 def test_get_version_info(self): 1156 info = get_version_info() 1157 1158 fields = info.split(':') 1159 assert fields[0].startswith('Revision') 1160 1161 try: 1162 int(fields[1]) 1163 except: 1164 msg = 'Revision number must be an integer. I got %s' %fields[1] 1165 msg += 'Chech that the command svn is on the system path' 1166 raise Exception(msg) 1155 def test_get_revision_number(self): 1156 """test_get_revision_number(self): 1157 1158 Test that revision number can be retrieved. 1159 """ 1160 1161 n = get_revision_number() 1162 assert n>=0 1163 1164 1167 1165 1168 1166 def test_add_directories(self): … … 1207 1205 1208 1206 1207 def test_add_directories(self): 1208 1209 import tempfile 1210 root_dir = tempfile.mkdtemp('_test_util', 'test_util_') 1211 directories = ['ja','ne','ke'] 1212 kens_dir = add_directories(root_dir, directories) 1213 assert kens_dir == root_dir + sep + 'ja' + sep + 'ne' + \ 1214 sep + 'ke' 1215 assert access(root_dir,F_OK) 1216 1217 add_directories(root_dir, directories) 1218 assert access(root_dir,F_OK) 1219 1220 #clean up! 1221 os.rmdir(kens_dir) 1222 os.rmdir(root_dir + sep + 'ja' + sep + 'ne') 1223 os.rmdir(root_dir + sep + 'ja') 1224 os.rmdir(root_dir) 1225 1226 def test_add_directories_bad(self): 1227 1228 import tempfile 1229 root_dir = tempfile.mkdtemp('_test_util', 'test_util_') 1230 directories = ['/\/!@#@#$%^%&*((*:*:','ne','ke'] 1231 1232 try: 1233 kens_dir = add_directories(root_dir, directories) 1234 except OSError: 1235 pass 1236 else: 1237 msg = 'bad dir name should give OSError' 1238 raise Exception(msg) 1239 1240 #clean up! 1241 os.rmdir(root_dir) 1242 1243 def test_check_list(self): 1244 1245 check_list(['stage','xmomentum']) 1246 1209 1247 1210 1248 #------------------------------------------------------------- -
anuga_core/source/anuga/abstract_2d_finite_volumes/util.py
r4168 r4170 534 534 fid.write(stuff) 535 535 536 def get_ version_info():537 """ getsthe version number of the SVN536 def get_revision_number(): 537 """Get the version number of the SVN 538 538 NOTE: This requires that the command svn is on the system PATH 539 539 (simply aliasing svn to the binary will not work) 540 540 """ 541 541 542 # Create dummy info 543 #info = 'Revision: Version info could not be obtained.' 544 #info += 'A command line version of svn must be availbable ' 545 #info += 'on the system PATH, access to the subversion ' 546 #info += 'repository is necessary and the output must ' 547 #info += 'contain a line starting with "Revision:"' 548 549 542 550 #FIXME (Ole): Change this so that svn info is attempted first. 543 551 # 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. 544 552 545 546 import os, sys 547 548 # Create dummy info 549 info = 'Revision: Version info could not be obtained.' 550 info += 'A command line version of svn must be availbable ' 551 info += 'on the system PATH, access to the subversion ' 552 info += 'repository is necessary and the output must ' 553 info += 'contain a line starting with "Revision:"' 553 #FIXME (Ole): Move this and store_version_info to utilities 554 555 556 try: 557 from anuga.stored_version_info import version_info 558 except: 559 560 # No file available - try using Subversion 561 try: 562 fid = os.popen('svn info') 563 except: 564 msg = 'No version info stored and command "svn" is not ' 565 msg += 'recognised on the system PATH. What do you want me to do?' 566 raise Exception(msg) 567 else: 568 #print 'Got version from svn' 569 version_info = fid.read() 570 else: 571 pass 572 #print 'Got version from file' 573 574 575 for line in version_info.split('\n'): 576 if line.startswith('Revision:'): 577 break 578 579 fields = line.split(':') 580 msg = 'Keyword "Revision" was not found anywhere in text: %s' %version_info 581 assert fields[0].startswith('Revision'), msg 582 583 try: 584 revision_number = int(fields[1]) 585 except: 586 msg = 'Revision number must be an integer. I got %s' %fields[1] 587 msg += 'Check that the command svn is on the system path' 588 raise Exception(msg) 589 590 return revision_number 591 592 593 def store_version_info(destination_path='.', verbose=False): 594 """Obtain current version from Subversion and store it. 595 596 Title: store_version_info() 597 598 Author: Ole Nielsen (Ole.Nielsen@ga.gov.au) 599 600 CreationDate: January 2006 601 602 Description: 603 This function obtains current version from Subversion and stores it 604 is a Python file named 'stored_version_info.py' for use with 605 get_version_info() 606 607 If svn is not available on the system PATH, an Exception is thrown 608 """ 609 610 # Note (Ole): This function should not be unit tested as it will only 611 # work when running out of the sandpit. End users downloading the 612 # ANUGA distribution would see a failure. 613 # 614 # FIXME: This function should really only be used by developers ( 615 # (e.g. for creating new ANUGA releases), so maybe it should move 616 # to somewhere else. 617 618 import config 554 619 555 620 try: 556 621 fid = os.popen('svn info') 557 622 except: 558 msg = ' svnis not recognised on the system PATH'559 warn(msg, UserWarning)623 msg = 'Command "svn" is not recognised on the system PATH' 624 raise Exception(msg) 560 625 else: 561 lines = fid.readlines()626 txt = fid.read() 562 627 fid.close() 563 for line in lines: 564 if line.startswith('Revision:'): 565 info = line 566 break 567 568 return info 628 629 630 # Determine absolute filename 631 if destination_path[-1] != os.sep: 632 destination_path += os.sep 633 634 filename = destination_path + config.version_filename 635 636 fid = open(filename, 'w') 637 638 docstring = 'Stored version info.\n\n' 639 docstring += 'This file provides the version for distributions ' 640 docstring += 'that are not accessing Subversion directly.\n' 641 docstring += 'The file is automatically generated and should not ' 642 docstring += 'be modified manually.\n' 643 fid.write('"""%s"""\n\n' %docstring) 644 645 fid.write('version_info = """\n%s"""' %txt) 646 fid.close() 647 648 649 if verbose is True: 650 print 'Version info stored to %s' %filename 651 569 652 570 653 def sww2timeseries(swwfiles, -
anuga_core/source/anuga/config.py
r3876 r4170 89 89 90 90 pmesh_filename = '.\\pmesh' 91 version_filename = 'stored_version_info.py' 91 92 92 93 -
create_distribution.py
r4168 r4170 3 3 This script is assumed to be run in the root directory of anuga 4 4 from a working sandpit connected to svn 5 6 It will create a distribution of ANUGA from the version which is 7 currently checked out. 8 9 To use the latest version run 10 11 svn up 12 13 before running this script. To use a specific revision (2187, say) run 14 15 svn up -r 2187 16 17 first assuming that create_distribution.py (this script) and anything 18 it depends on still work for that revision. 5 19 6 20 This script works only on Linux … … 11 25 from sys import platform 12 26 from anuga.utilities.system_tools import get_user_name, get_host_name 27 from anuga.abstract_2d_finite_volumes.util import get_revision_number 28 from anuga.abstract_2d_finite_volumes.util import store_version_info 13 29 14 30 … … 23 39 24 40 25 # Refresh sand it and retrieve svn revision number41 # Refresh sandpit and retrieve svn revision number 26 42 # from last line in svn update output 27 28 # FIXME (Ole): Change this to use util.get_version_info() and create 43 #filename = mktemp() + '.txt' 44 #s = 'svn update > %s' %filename 45 #print s 46 #system(s) 47 # 48 #fid = open(filename) 49 #last_line = fid.readlines()[-1] 50 #remove(filename) 51 #if not (last_line.startswith('At revision') or\ 52 # last_line.startswith('Updated to revision')): 53 # msg = 'Unexpected output from svn up: %s' %last_line 54 # raise Exception, msg 55 # 56 #fields = last_line.split() 57 #svn_revision = fields[-1][:-1] 58 59 # Get revision number and create 29 60 # file with version info for release. 30 # This will alsomean that the version currently checked out is61 # This will mean that the version currently checked out is 31 62 # the one which will be released. 32 63 33 filename = mktemp() + '.txt' 34 35 s = 'svn update > %s' %filename 36 print s 37 system(s) 38 39 fid = open(filename) 40 last_line = fid.readlines()[-1] 41 remove(filename) 42 if not (last_line.startswith('At revision') or\ 43 last_line.startswith('Updated to revision')): 44 msg = 'Unexpected output from svn up: %s' %last_line 45 raise Exception, msg 46 47 fields = last_line.split() 48 svn_revision = fields[-1][:-1] 49 64 svn_revision = get_revision_number() 50 65 revision = '%s_%s' %(major_revision, svn_revision) 51 52 66 print 'Creating ANUGA revision %s' %revision 53 67 … … 58 72 s = 'mkdir %s' %release_dir 59 73 try: 74 print s 60 75 system(s) 61 76 except: … … 63 78 64 79 65 # Export a clean directory tree from the working copy 80 # Export a clean directory tree from the working copy to a temporary dir 66 81 distro_dir = mktemp() 67 82 s = 'mkdir %s' %distro_dir 68 print s 69 system(s) 70 71 s = 'svn export anuga_core/source/anuga %s/anuga' %(distro_dir) 72 print s 73 system(s) 83 print s 84 system(s) 85 86 87 88 s = 'svn export -r %d anuga_core/source/anuga %s/anuga' %(svn_revision, 89 distro_dir) 90 print s 91 system(s) 92 93 94 # Store file with revision info for use with get_revision_number 95 store_version_info(destination_path=distro_dir+'/anuga', verbose=True) 96 97 import sys; sys.exit() 98 99 74 100 75 101 # Zip it up
Note: See TracChangeset
for help on using the changeset viewer.