diff --git a/comicarchive.py b/comicarchive.py index 54ec272..8a75b1e 100644 --- a/comicarchive.py +++ b/comicarchive.py @@ -93,7 +93,6 @@ class ZipArchiver: # zip helper func def rebuildZipFile( self, exclude_list ): - # TODO: use tempfile.mkstemp # this recompresses the zip archive, without the files in the exclude_list #print "Rebuilding zip {0} without {1}".format( self.path, exclude_list ) @@ -181,6 +180,26 @@ class ZipArchiver: return False else: return True + + def copyFromArchive( self, otherArchive ): + # Replace the current zip with one copied from another archive + try: + zout = zipfile.ZipFile (self.path, 'w') + for fname in otherArchive.getArchiveFilenameList(): + data = otherArchive.readArchiveFile( fname ) + zout.writestr( fname, data ) + zout.close() + + #preserve the old comment + comment = otherArchive.getArchiveComment() + if comment is not None: + if not self.writeZipComment( self.path, comment ): + return False + except: + return False + else: + return True + #------------------------------------------ # RAR implementation @@ -694,3 +713,12 @@ class ComicArchive: metadata.isEmpty = False return metadata + + def exportAsZip( self, zipfilename ): + if self.archive_type == self.ArchiveType.Zip: + # nothing to do, we're already a zip + return True + + zip_archiver = ZipArchiver( zipfilename ) + return zip_archiver.copyFromArchive( self.archiver ) + diff --git a/taggerwindow.py b/taggerwindow.py index c6daaa7..b0812ff 100644 --- a/taggerwindow.py +++ b/taggerwindow.py @@ -275,8 +275,21 @@ class TaggerWindow( QtGui.QMainWindow): self.toolBar.addAction( self.actionPageBrowser ) def repackageArchive( self ): - QtGui.QMessageBox.information(self, self.tr("Repackage Comic Archive"), self.tr("TBD")) - + if self.comic_archive is not None: + if self.comic_archive.isZip(): + QtGui.QMessageBox.information(self, self.tr("Export as Zip Archive"), self.tr("It's already a Zip Archive!")) + return + + #TODO get the new zip file name + export_name = "test.cbz" + + QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) + retcode = self.comic_archive.exportAsZip( "test.cbz") + QtGui.QApplication.restoreOverrideCursor() + + if not retcode: + QtGui.QMessageBox.information(self, self.tr("Export as Zip Archive"), self.tr("An error occure while exporting.")) + def aboutApp( self ): website = "http://code.google.com/p/comictagger" diff --git a/taggerwindow.ui b/taggerwindow.ui index 06eec8f..65d1eac 100644 --- a/taggerwindow.ui +++ b/taggerwindow.ui @@ -1146,7 +1146,7 @@ - Repackage + Export as Zip Archive