LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Zip a set of files to 1 file.zip

    Employee
    Posted 02-20-2014 15:39

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dkhuon@gogoair.com

    I am modifying someone code to zip multiple file to a single zip file. THe code works, however the output stream got more rows than the input:

    For instance, I have file1.csv, file2.csv, file3.csv. It creates a filez.zip containing just those 3 files. However, file1.csv appears 3 times in the output, file2.csv appears 2 times, and file3.csv appears just once.

    The following code fragment is from CloseArchive, where the output stream is being generated:

    if self.archiveType == 'zip':
    if os.access(self.archiveFile, os.F_OK) and zipfile.is_zipfile(self.archiveFile):
    self.archive = zipfile.ZipFile(self.archiveFile, "r")

    outRec = self.output.newRecord()

    # Archive file info

    for info in self.archive.infolist():
    outRec["FileName"] = info.filename
    outRec["ArchiveName"] = self.archiveFile
    outRec["DateTime"] = info.date_time
    outRec["FileSize"] = info.file_size
    self.output.write(outRec)

    # Check the Archive File for bad files
    badFile = self.archive.testzip()

    # Close the Archive File again
    self.archive.close()

    if badFile == None:
    pass
    else:
    raise braininfo.BrainNodeException, 'Archive contains bad file: "' + str(badFile) + '"'


  • 2.  RE: Zip a set of files to 1 file.zip

    Employee
    Posted 02-23-2014 07:16

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dkhuon@gogoair.com

    The for loop is the culprit. I misunderstood how the pump works with respect to the lavastorm input stream: the openarchive and closeArchive were performed for each of the input row. Removed the for loop, and tweaked some file (stat) attributes would meet my purposes.

    Originally posted by: dkhuon@gogoair.com
    					

    I am modifying someone code to zip multiple file to a single zip file. THe code works, however the output stream got more rows than the input:

    For instance, I have file1.csv, file2.csv, file3.csv. It creates a filez.zip containing just those 3 files. However, file1.csv appears 3 times in the output, file2.csv appears 2 times, and file3.csv appears just once.

    The following code fragment is from CloseArchive, where the output stream is being generated:

    if self.archiveType == 'zip':
    if os.access(self.archiveFile, os.F_OK) and zipfile.is_zipfile(self.archiveFile):
    self.archive = zipfile.ZipFile(self.archiveFile, "r")

    outRec = self.output.newRecord()

    # Archive file info

    for info in self.archive.infolist():
    outRec["FileName"] = info.filename
    outRec["ArchiveName"] = self.archiveFile
    outRec["DateTime"] = info.date_time
    outRec["FileSize"] = info.file_size
    self.output.write(outRec)

    # Check the Archive File for bad files
    badFile = self.archive.testzip()

    # Close the Archive File again
    self.archive.close()

    if badFile == None:
    pass
    else:
    raise braininfo.BrainNodeException, 'Archive contains bad file: "' + str(badFile) + '"'