Changeset 373
- Timestamp:
- 09/10/10 17:28:29
- Files:
-
- spongenet/trunk/mini_andi_expand_config.py (modified) (1 diff)
- spongenet/trunk/spongenet/expand.py (modified) (4 diffs)
- spongenet/trunk/spongenet/tests/expand/incomplete_config.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spongenet/trunk/mini_andi_expand_config.py
r344 r373 5 5 import os 6 6 7 zipdir= "/seacoos/data/nccoos/level0/largo/mini_andi/zip"8 xmldir= "/seacoos/data/nccoos/level0/largo/mini_andi/xml"9 zipdir_pattern= "[0-9][0-9][0-9][0-9]_[0-9][0-9]"10 zipfile_pattern= "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \7 ZIPDIR = "/seacoos/data/nccoos/level0/largo/mini_andi/zip" 8 XMLDIR = "/seacoos/data/nccoos/level0/largo/mini_andi/xml" 9 ZIPDIR_PATTERN = "[0-9][0-9][0-9][0-9]_[0-9][0-9]" 10 ZIPFILE_PATTERN = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ 11 11 "[0-9][0-9][0-9][0-9][0-9][0-9]-" \ 12 12 "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ 13 13 "[0-9][0-9][0-9][0-9][0-9][0-9].zip" 14 xmlfile_pattern= "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \14 XMLFILE_PATTERN = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ 15 15 "[0-9][0-9][0-9][0-9][0-9][0-9].xml" spongenet/trunk/spongenet/expand.py
r351 r373 290 290 291 291 # Write a combined XML sponge data file. 292 path = xml_subdir + os.extsep + "xml"293 with open( path, "w") as handle:292 xml_path = xml_subdir + os.extsep + "xml" 293 with open(xml_path, "w") as handle: 294 294 handle.write(header) 295 295 handle.write("<root>\n") … … 372 372 xml_subdir = os.path.splitext(os.path.basename(zip_file))[0] 373 373 xml_subdir = os.path.join(xml_month, xml_subdir) 374 if not os.path.exists(xml_subdir): 375 os.mkdir(xml_subdir, 0755) 376 # Extract all the XML files in the zip file 377 # and combine into a single XML document. 378 archive = zipfile.ZipFile(zip_file, "r") 379 archive.extractall(xml_subdir) 380 combine(xml_subdir, xmlfile_pattern) 381 elif not os.path.isdir(xml_subdir): 382 raise IOError("XML file subdirectory name " + \ 374 xml_path = xml_subdir + os.extsep + "xml" 375 if not os.path.exists(xml_path): 376 if not os.path.exists(xml_subdir): 377 os.mkdir(xml_subdir, 0755) 378 # Extract all the XML files in the zip file 379 # and combine into a single XML document. 380 archive = zipfile.ZipFile(zip_file, "r") 381 archive.extractall(xml_subdir) 382 combine(xml_subdir, xmlfile_pattern) 383 elif not os.path.isdir(xml_subdir): 384 raise IOError("XML file subdirectory name " + \ 385 xml_subdir + \ 386 " exists and is not a directory.") 387 elif not os.path.isfile(xml_path): 388 raise IOError("XML file name " + \ 389 xml_path + \ 390 " exists and is not a file.") 391 elif os.path.exists(xml_subdir): 392 raise IOError("XML file name " + \ 393 xml_path + \ 394 "and XML file subdirectory name " + \ 383 395 xml_subdir + \ 384 " exists and is not a directory.")396 " both exist.") 385 397 386 398 return … … 391 403 Run module as script. 392 404 393 Test silent import. 394 395 >>> from expand import _main 405 Supply incomplete config file. 406 407 >>> save_stdout = sys.stdout 408 >>> temp_stdout = StringIO() 409 >>> sys.stdout = temp_stdout 410 >>> _config_path = os.path.join( 411 ... os.path.dirname( 412 ... os.path.abspath(__file__)), 413 ... TEST_PATH, "incomplete_config.py") 414 >>> sys.argv = ["", _config_path] 415 >>> _main() 416 >>> sys.stdout = save_stdout 417 >>> USAGE == temp_stdout.getvalue()[:-1] 418 True 396 419 """ 397 420 … … 401 424 if all(_config): 402 425 expand(*_config) 426 else: 427 print USAGE 403 428 return 404 429