Index: spongenet/trunk/mini_andi_expand_config.py =================================================================== --- spongenet/trunk/mini_andi_expand_config.py (revision 344) +++ spongenet/trunk/mini_andi_expand_config.py (revision 373) @@ -5,11 +5,11 @@ import os -zipdir = "/seacoos/data/nccoos/level0/largo/mini_andi/zip" -xmldir = "/seacoos/data/nccoos/level0/largo/mini_andi/xml" -zipdir_pattern = "[0-9][0-9][0-9][0-9]_[0-9][0-9]" -zipfile_pattern = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ +ZIPDIR = "/seacoos/data/nccoos/level0/largo/mini_andi/zip" +XMLDIR = "/seacoos/data/nccoos/level0/largo/mini_andi/xml" +ZIPDIR_PATTERN = "[0-9][0-9][0-9][0-9]_[0-9][0-9]" +ZIPFILE_PATTERN = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ "[0-9][0-9][0-9][0-9][0-9][0-9]-" \ "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ "[0-9][0-9][0-9][0-9][0-9][0-9].zip" -xmlfile_pattern = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ +XMLFILE_PATTERN = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ "[0-9][0-9][0-9][0-9][0-9][0-9].xml" Index: spongenet/trunk/spongenet/expand.py =================================================================== --- spongenet/trunk/spongenet/expand.py (revision 351) +++ spongenet/trunk/spongenet/expand.py (revision 373) @@ -290,6 +290,6 @@ # Write a combined XML sponge data file. - path = xml_subdir + os.extsep + "xml" - with open(path, "w") as handle: + xml_path = xml_subdir + os.extsep + "xml" + with open(xml_path, "w") as handle: handle.write(header) handle.write("\n") @@ -372,15 +372,27 @@ xml_subdir = os.path.splitext(os.path.basename(zip_file))[0] xml_subdir = os.path.join(xml_month, xml_subdir) - if not os.path.exists(xml_subdir): - os.mkdir(xml_subdir, 0755) - # Extract all the XML files in the zip file - # and combine into a single XML document. - archive = zipfile.ZipFile(zip_file, "r") - archive.extractall(xml_subdir) - combine(xml_subdir, xmlfile_pattern) - elif not os.path.isdir(xml_subdir): - raise IOError("XML file subdirectory name " + \ + xml_path = xml_subdir + os.extsep + "xml" + if not os.path.exists(xml_path): + if not os.path.exists(xml_subdir): + os.mkdir(xml_subdir, 0755) + # Extract all the XML files in the zip file + # and combine into a single XML document. + archive = zipfile.ZipFile(zip_file, "r") + archive.extractall(xml_subdir) + combine(xml_subdir, xmlfile_pattern) + elif not os.path.isdir(xml_subdir): + raise IOError("XML file subdirectory name " + \ + xml_subdir + \ + " exists and is not a directory.") + elif not os.path.isfile(xml_path): + raise IOError("XML file name " + \ + xml_path + \ + " exists and is not a file.") + elif os.path.exists(xml_subdir): + raise IOError("XML file name " + \ + xml_path + \ + "and XML file subdirectory name " + \ xml_subdir + \ - " exists and is not a directory.") + " both exist.") return @@ -391,7 +403,18 @@ Run module as script. - Test silent import. - - >>> from expand import _main + Supply incomplete config file. + + >>> save_stdout = sys.stdout + >>> temp_stdout = StringIO() + >>> sys.stdout = temp_stdout + >>> _config_path = os.path.join( + ... os.path.dirname( + ... os.path.abspath(__file__)), + ... TEST_PATH, "incomplete_config.py") + >>> sys.argv = ["", _config_path] + >>> _main() + >>> sys.stdout = save_stdout + >>> USAGE == temp_stdout.getvalue()[:-1] + True """ @@ -401,4 +424,6 @@ if all(_config): expand(*_config) + else: + print USAGE return Index: spongenet/trunk/spongenet/tests/expand/incomplete_config.py =================================================================== --- (revision ) +++ spongenet/trunk/spongenet/tests/expand/incomplete_config.py (revision 373) @@ -1,0 +1,19 @@ +#!/usr/bin/env python + +"""Incomplete test configuration for the expand module.""" + +import os + +EXPAND_TEST_PATH = os.path.join("tests", "expand") + +zipdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), + EXPAND_TEST_PATH, "zip") +xmldir = os.path.join(os.path.dirname(os.path.abspath(__file__)), + EXPAND_TEST_PATH, "xml") +zipdir_pattern = "[0-9][0-9][0-9][0-9]_[0-9][0-9]" +zipfile_pattern = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ + "[0-9][0-9][0-9][0-9][0-9][0-9]-" \ + "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ + "[0-9][0-9][0-9][0-9][0-9][0-9].zip" +xmlfile_pattern = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ + "[0-9][0-9][0-9][0-9][0-9][0-9].xml"