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

Changeset 348

Show
Ignore:
Timestamp:
08/31/10 11:17:30
Author:
cbc
Message:

Rework line endings on combined XML documents.

Files:

Legend:

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

    r345 r348  
    244244def combine(xml_subdir, xmlfile_pattern): 
    245245    """ 
    246     Combine the xml sponge data files from a subdirectory. 
     246    Combine the XML sponge data files from a subdirectory. 
    247247 
    248248    Combine test subdirectory. 
     
    278278    """ 
    279279 
    280     # Find all the xml sponge data files. 
     280    # Find all the XML sponge data files. 
    281281    xmlfiles = glob.glob(os.path.join(xml_subdir, xmlfile_pattern)) 
    282282    xmlfiles = [xmlfile 
     
    284284                if os.path.isfile(xmlfile)] 
    285285 
    286     # Read all the xml sponge data files. 
     286    # Read all the XML sponge data files. 
    287287    files = fileinput.FileInput(xmlfiles) 
    288     header = files.readline() 
    289     lines = ["\r\n" if files.isfirstline() else line for line in files
    290  
    291     # Write a combined xml sponge data file. 
     288    header = files.readline().rstrip() + "\n" 
     289    lines = [line.rstrip() + "\n" for line in files if not files.isfirstline()
     290 
     291    # Write a combined XML sponge data file. 
    292292    path = xml_subdir + os.extsep + "xml" 
    293293    with open(path, "w") as handle: 
    294294        handle.write(header) 
    295         handle.write("<root>\r\n") 
     295        handle.write("<root>\n") 
    296296        handle.writelines(lines) 
    297         handle.write("\r\n</root>") 
    298  
    299     # Remove the xml sponge data file subdirectory. 
     297        handle.write("</root>\n") 
     298 
     299    # Remove the XML sponge data file subdirectory. 
    300300    shutil.rmtree(xml_subdir) 
    301301 
     
    374374            if not os.path.exists(xml_subdir): 
    375375                os.mkdir(xml_subdir, 0755) 
    376                 # Extract all the xml files in the zip file. 
     376                # Extract all the XML files in the zip file 
     377                # and combine into a single XML document. 
    377378                archive = zipfile.ZipFile(zip_file, "r") 
    378379                archive.extractall(xml_subdir)