def testGetCompressionFormat(self): for suffix in Compressor.compressionFormats: fname = "dummy.%s" % suffix self.assertEqual(Compressor.getCompressionFormat(fname), suffix) fname = "dummy.%s" % suffix.upper() self.assertEqual(Compressor.getCompressionFormat(fname), suffix) self.assertEqual(Compressor.getCompressionFormat("dummy"), "") self.assertEqual(Compressor.getCompressionFormat(""), "")
def checkOptions(self): if len(self.args) != 1: self.parser.error('Please specify an image') self.image = self.args[0] if not os.path.isfile(self.image): self.parser.error('Image does not exist: ' + self.image) if not self.options.locations: self.options.__dict__.update({'locations': []}) Util.printWarning("Image physical location (URL) was not provided. " "You'll have to set it manually in the resulting manifest.") else: self.options.__dict__.update({'locations': [self.options.__dict__['locations']]}) if not self.options.compression: # Guess compression from file name if not given explicitly. compression = Compressor.getCompressionFormat(self.image) self.options.__dict__.update({'compression': compression}) if self.options.disksbus not in VmManager.DISKS_BUS_AVAILABLE: self.parser.error("Unknown disks bus type %s. Available types: %s" % (self.options.disksbus, ', '.join(VmManager.DISKS_BUS_AVAILABLE)))
def _compressFile(self, filename, fmt): if fmt.lower() == 'none': return filename if Compressor.getCompressionFormat(filename) != '': Util.printWarning('skipping compression; file appears to already be compressed') return filename compressionCmd = Compressor._getCompressionCommandByFormat(fmt) compressedFilename = '%s.%s' % (filename, fmt) if os.path.isfile(compressedFilename): Util.printWarning('Compressed file %s already exists, skipping' % compressedFilename) return compressedFilename if not os.path.exists(filename): Util.printError('Missing file: ' + filename, exit=True) ret = self._execute([compressionCmd, filename]) if ret != 0: Util.printError('Error compressing file: %s' % compressedFilename, exit=True) return compressedFilename