Changeset 6613
- Timestamp:
- Mar 25, 2009, 2:35:26 PM (15 years ago)
- Location:
- anuga_core/source/anuga/utilities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/system_tools.py
r6612 r6613 9 9 import urllib2 10 10 import getpass 11 import tarfile 11 12 12 13 … … 359 360 360 361 362 ## 363 # @brief Tar a file (or directory) into a tarfile. 364 # @param files A list of files (or directories) to tar. 365 # @param tarfile The created tarfile name. 366 def tar_file(files, tarname): 367 '''Compress a file or directory into a tar file.''' 368 369 o = tarfile.open(tarname, 'w:gz') 370 for file in files: 371 o.add(file) 372 o.close() 373 374 375 ## 376 # @brief Untar a file into an optional target directory. 377 # @param tarname Name of the file to untar. 378 # @param target_dir Directory to untar into. 379 def untar_file(tarname, target_dir='.'): 380 '''Uncompress a tar file.''' 381 382 o = tarfile.open(tarname, 'r:gz') 383 members = o.getmembers() 384 for member in members: 385 o.extract(member, target_dir) 386 o.close() -
anuga_core/source/anuga/utilities/test_system_tools.py
r6556 r6613 3 3 4 4 import unittest 5 import tempfile 5 6 import Numeric as num 6 7 import zlib … … 162 163 test_it(source, expected) 163 164 165 def test_tar_untar_files(self): 166 '''Test that tarring & untarring files is OK.''' 167 168 # these test files must exist in the current directory 169 files = ('test_system_tools.py', 'system_tools.py') 170 171 # name of tar file and test (temp) directory 172 tar_filename = 'test.tgz' 173 tmp_dir = tempfile.mkdtemp() 174 175 # tar and untar the test files into a temporary directory 176 tar_file(files, tar_filename) 177 untar_file(tar_filename, tmp_dir) 178 179 # see if original files and untarred ones are the same 180 for file in files: 181 fd = open(file, 'r') 182 orig = fd.readlines() 183 fd.close() 184 185 fd = open(os.path.join(tmp_dir, file), 'r') 186 copy = fd.readlines() 187 fd.close() 188 189 msg = "Original file %s isn't the same as untarred copy?" % file 190 self.failUnless(orig == copy, msg) 191 192 164 193 #------------------------------------------------------------- 165 194 if __name__ == "__main__": … … 168 197 runner.run(suite) 169 198 170 171 172
Note: See TracChangeset
for help on using the changeset viewer.