def extract(self, filename, destination_dir): """ Extract <filename> from the archive to <destination_dir>. """ assert isinstance(filename, unicode) and \ isinstance(destination_dir, unicode) if not self._get_executable(): return if not self.filenames_initialized: self.list_contents() tmplistfile = tempfile.NamedTemporaryFile(prefix='mcomix.7z.', delete=False) try: desired_filename = self._original_filename(filename) if isinstance(desired_filename, unicode): desired_filename = desired_filename.encode('utf-8') tmplistfile.write(desired_filename + os.linesep) tmplistfile.close() output = self._create_file(os.path.join(destination_dir, filename)) try: process.call( self._get_extract_arguments(list_file=tmplistfile.name), stdout=output) finally: output.close() finally: os.unlink(tmplistfile.name)
def extract(self, filename, destination_dir): """ Extract <filename> from the archive to <destination_dir>. """ assert isinstance(filename, unicode) and \ isinstance(destination_dir, unicode) if not self._get_executable(): return if not self.filenames_initialized: self.list_contents() tmplistfile = tempfile.NamedTemporaryFile(prefix='mcomix.7z.', delete=False) try: desired_filename = self._original_filename(filename) if isinstance(desired_filename, unicode): desired_filename = desired_filename.encode('utf-8') tmplistfile.write(desired_filename + os.linesep) tmplistfile.close() output = self._create_file(os.path.join(destination_dir, filename)) try: process.call(self._get_extract_arguments(list_file=tmplistfile.name), stdout=output) finally: output.close() finally: os.unlink(tmplistfile.name)
def extract(self, filename, destination_dir): self._create_directory(destination_dir) destination_path = os.path.join(destination_dir, filename) page_num = int(filename[0:-4]) # Try to find optimal DPI. cmd = _mudraw_exec + _mudraw_trace_args + ["--", self.archive, str(page_num)] log.debug("finding optimal DPI for %s: %s", filename, " ".join(cmd)) proc = process.popen(cmd) try: max_size = 0 max_dpi = PDF_RENDER_DPI_DEF for line in proc.stdout: match = self._fill_image_regex.match(line) if not match: continue matrix = [float(f) for f in match.group("matrix").split()] for size, coeff1, coeff2 in ( (int(match.group("width")), matrix[0], matrix[1]), (int(match.group("height")), matrix[2], matrix[3]), ): if size < max_size: continue render_size = math.sqrt(coeff1 * coeff1 + coeff2 * coeff2) dpi = int(size * 72 / render_size) if dpi > PDF_RENDER_DPI_MAX: dpi = PDF_RENDER_DPI_MAX max_size = size max_dpi = dpi finally: proc.stdout.close() proc.wait() # Render... cmd = _mudraw_exec + ["-r", str(max_dpi), "-o", destination_path, "--", self.archive, str(page_num)] log.debug("rendering %s: %s", filename, " ".join(cmd)) process.call(cmd)
def extract(self, filename, destination_dir): """ Extract <filename> from the archive to <destination_dir>. """ assert isinstance(filename, str) and \ isinstance(destination_dir, str) if not self._get_executable(): return if not self.filenames_initialized: self.list_contents() desired_filename = self._original_filename(filename) cmd = self._get_extract_arguments() + [desired_filename] with self._create_file(os.path.join(destination_dir, filename)) as output: process.call(cmd, stdout=output)
def extract(self, filename, destination_dir): """ Extract <filename> from the archive to <destination_dir>. """ assert isinstance(filename, unicode) and \ isinstance(destination_dir, unicode) if not self._get_executable(): return if not self.filenames_initialized: self.list_contents() output = self._create_file(os.path.join(destination_dir, filename)) try: process.call( [self._get_executable()] + self._get_extract_arguments() + [self.archive, self._original_filename(filename)], stdout=output) finally: output.close()
def extract(self, filename, destination_dir): ''' Extract <filename> from the archive to <destination_dir>. ''' assert isinstance(filename, str) and \ isinstance(destination_dir, str) if not self._get_executable(): return if not self.filenames_initialized: self.list_contents() destination_path = os.path.join(destination_dir, filename) with self._create_file(destination_path) as output: process.call( [self._get_executable()] + self._get_extract_arguments() + [self.archive, self._original_filename(filename)], stdout=output) return destination_path
def extract(self, filename, destination_dir): """ Extract <filename> from the archive to <destination_dir>. """ assert isinstance(filename, unicode) and \ isinstance(destination_dir, unicode) if not self._get_executable(): return if not self.filenames_initialized: self.list_contents() output = self._create_file(os.path.join(destination_dir, filename)) try: process.call([self._get_executable()] + self._get_extract_arguments() + [self.archive, self._original_filename(filename)], stdout=output) finally: output.close()
def extract(self, filename, destination_dir): ''' Extract <filename> from the archive to <destination_dir>. ''' assert isinstance(filename, str) and \ isinstance(destination_dir, str) if not self._get_executable(): return if not self.filenames_initialized: self.list_contents() destination_path = os.path.join(destination_dir, filename) with tempfile.NamedTemporaryFile(mode='wt', prefix='mcomix.7z.') as tmplistfile: desired_filename = self._original_filename(filename) tmplistfile.write(desired_filename + os.linesep) tmplistfile.flush() with self._create_file(destination_path) as output: process.call(self._get_extract_arguments(list_file=tmplistfile.name), stdout=output) return destination_path
def extract(self, filename, destination_dir): self._create_directory(destination_dir) destination_path = os.path.join(destination_dir, filename) page_num = int(filename[0:-4]) # Try to find optimal DPI. cmd = _mudraw_exec + _mudraw_trace_args + [ '--', self.archive, str(page_num) ] log.debug('finding optimal DPI for %s: %s', filename, ' '.join(cmd)) proc = process.popen(cmd) try: max_size = 0 max_dpi = PDF_RENDER_DPI_DEF for line in proc.stdout: match = self._fill_image_regex.match(line) if not match: continue matrix = [float(f) for f in match.group('matrix').split()] for size, coeff1, coeff2 in ( (int(match.group('width')), matrix[0], matrix[1]), (int(match.group('height')), matrix[2], matrix[3]), ): if size < max_size: continue render_size = math.sqrt(coeff1 * coeff1 + coeff2 * coeff2) dpi = int(size * 72 / render_size) if dpi > PDF_RENDER_DPI_MAX: dpi = PDF_RENDER_DPI_MAX max_size = size max_dpi = dpi finally: proc.stdout.close() proc.wait() # Render... cmd = _mudraw_exec + [ '-r', str(max_dpi), '-o', destination_path, '--', self.archive, str(page_num) ] log.debug('rendering %s: %s', filename, ' '.join(cmd)) process.call(cmd)