Changeset 4977


Ignore:
Timestamp:
Jan 28, 2008, 10:46:34 AM (16 years ago)
Author:
steve
Message:

Problem with NamedTemporaryFile? in windows. Sometimes gives error
if trying to open already openned file. Can't close it, as it is
automatically deleted on closure. So went back to manual method using mkstemp

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

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/system_tools.py

    r4963 r4977  
    185185    fid = open(filename)
    186186    crcval = crc32(fid.read(max_length))
     187    fid.close()
    187188    return crcval
  • anuga_core/source/anuga/utilities/test_system_tools.py

    r4961 r4977  
    3434
    3535        import zlib
    36         from tempfile import NamedTemporaryFile, mktemp
     36        from tempfile import mkstemp, mktemp
    3737
    3838        # Generate a text file
    39         fid = NamedTemporaryFile(mode='w',
    40                                  suffix='.tmp',
    41                                  dir='.')
     39        tmp_fd , tmp_name = mkstemp(suffix='.tmp',dir='.')
     40        fid = os.fdopen(tmp_fd,'w')
    4241        string = 'My temp file with textual content. AAAABBBBCCCC1234'
    4342        fid.write(string)
     
    4645
    4746        ref_crc = zlib.crc32(string)
    48         checksum = compute_checksum(fid.name)
     47
     48
     49
     50        checksum = compute_checksum(tmp_name)
    4951
    5052        assert checksum == ref_crc
    5153
    52         # Close and remove temporary file
    5354        fid.close()
     55        os.remove(tmp_name)
     56       
    5457
    5558
    5659
    5760        # Binary file
    58         fid = NamedTemporaryFile(mode='w+b',
    59                                  suffix='.tmp',
    60                                  dir='.')
     61        tmp_fd , tmp_name = mkstemp(suffix='.tmp',dir='.')
     62        fid = os.fdopen(tmp_fd,'w+b')
     63       
     64
    6165        string = 'My temp file with binary content. AAAABBBBCCCC1234'
    6266        fid.write(string)
     
    6569
    6670        ref_crc = zlib.crc32(string)
    67         checksum = compute_checksum(fid.name)
     71        checksum = compute_checksum(tmp_name)
    6872
    6973        assert checksum == ref_crc
     
    7175        # Close and remove temporary file
    7276        fid.close()
    73        
     77        os.remove(tmp_name)       
    7478       
    7579        # Binary NetCDF File X 2 (use mktemp's name)
Note: See TracChangeset for help on using the changeset viewer.