NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

Changeset 373

Show
Ignore:
Timestamp:
09/10/10 17:28:29
Author:
cbc
Message:

Add file skipping capability to the expand module.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spongenet/trunk/mini_andi_expand_config.py

    r344 r373  
    55import os 
    66 
    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" \ 
     7ZIPDIR = "/seacoos/data/nccoos/level0/largo/mini_andi/zip" 
     8XMLDIR = "/seacoos/data/nccoos/level0/largo/mini_andi/xml" 
     9ZIPDIR_PATTERN = "[0-9][0-9][0-9][0-9]_[0-9][0-9]" 
     10ZIPFILE_PATTERN = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ 
    1111                  "[0-9][0-9][0-9][0-9][0-9][0-9]-" \ 
    1212                  "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ 
    1313                  "[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" \ 
     14XMLFILE_PATTERN = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T" \ 
    1515                  "[0-9][0-9][0-9][0-9][0-9][0-9].xml" 
  • spongenet/trunk/spongenet/expand.py

    r351 r373  
    290290 
    291291    # 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: 
    294294        handle.write(header) 
    295295        handle.write("<root>\n") 
     
    372372            xml_subdir = os.path.splitext(os.path.basename(zip_file))[0] 
    373373            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 " + \ 
    383395                              xml_subdir + \ 
    384                               " exists and is not a directory.") 
     396                              " both exist.") 
    385397 
    386398    return 
     
    391403    Run module as script. 
    392404 
    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 
    396419    """ 
    397420 
     
    401424        if all(_config): 
    402425            expand(*_config) 
     426        else: 
     427            print USAGE 
    403428    return 
    404429