Changeset 3983


Ignore:
Timestamp:
Nov 14, 2006, 2:20:29 PM (18 years ago)
Author:
duncan
Message:

new function. Create a directory structure. Handy for writing data to.

Location:
anuga_core/source/anuga/abstract_2d_finite_volumes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_util.py

    r3931 r3983  
    55from Numeric import zeros, array, allclose, Float
    66from math import sqrt, pi
    7 import tempfile
     7import tempfile, os
     8from os import access, F_OK,sep, removedirs
    89
    910from anuga.abstract_2d_finite_volumes.util import *
     
    11541155        assert info.startswith('Revision')
    11551156                         
    1156                          
     1157       
     1158    def test_add_directories(self):
     1159       
     1160        import tempfile
     1161        root_dir = tempfile.mkdtemp('_test_util', 'test_util_')
     1162        directories = ['ja','ne','ke']
     1163        kens_dir = add_directories(root_dir, directories)
     1164        assert kens_dir == root_dir + sep + 'ja' + sep + 'ne' + \
     1165               sep + 'ke'
     1166        assert access(root_dir,F_OK)
     1167
     1168        #clean up!
     1169        os.rmdir(kens_dir)
     1170        os.rmdir(root_dir + sep + 'ja' + sep + 'ne')
     1171        os.rmdir(root_dir + sep + 'ja')
     1172        os.rmdir(root_dir)
    11571173
    11581174#-------------------------------------------------------------
    11591175if __name__ == "__main__":
    11601176    suite = unittest.makeSuite(Test_Util,'test')
    1161     #suite = unittest.makeSuite(Test_Util,'test_get_version_info')
     1177    #suite = unittest.makeSuite(Test_Util,'test_add_directories')
    11621178    runner = unittest.TextTestRunner()
    11631179    runner.run(suite)
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r3953 r3983  
    99
    1010from os import remove, mkdir, access, F_OK, sep
    11 from os.path import exists
     11from os.path import exists, basename
    1212from warnings import warn
    1313from shutil import copy
     
    11951195    return texfile2, elev_output
    11961196
    1197 from os.path import basename
    1198 
     1197# FIXME (DSG): Add unit test, make general, not just 2 files,
     1198# but any number of files.
    11991199def copy_code_files(dir_name, filename1, filename2):
    12001200    """Copies "filename1" and "filename2" to "dir_name". Very useful for
     
    12091209    print 'Files %s and %s copied' %(filename1, filename2)
    12101210
    1211 
    1212 
    1213 
    1214 
     1211def add_directories(root_directory, directories):
     1212    """
     1213    Add the first directory in directories to root_directory.  Then add the second
     1214    direcotory to the first directory and so on.
     1215
     1216    Return the path of the final directory.
     1217
     1218    This is handy for specifying and creating a directory where data will go.
     1219    """
     1220    dir = root_directory
     1221    for new_dir in directories:
     1222        dir = dir + sep + new_dir
     1223        if not access(dir,F_OK):
     1224            mkdir (dir)
     1225    return dir
     1226
     1227
     1228
Note: See TracChangeset for help on using the changeset viewer.