def copy_zip_input_stream(self, zip_input_stream, parent=None): """Given a `zip_input_stream`, copy all entries to the output jar""" chunk = jarray.zeros(8192, "b") while True: entry = zip_input_stream.getNextEntry() if entry is None: break try: # NB: cannot simply use old entry because we need # to recompute compressed size if parent: name = "/".join([parent, entry.name]) else: name = entry.name if name.startswith("META-INF/") and name.endswith(".SF"): # Skip signature files - by their nature, they do # not work when their source jars are copied log.debug("Skipping META-INF signature file %s", name) continue output_entry = JarEntry(name) output_entry.time = entry.time self.jar.putNextEntry(output_entry) while True: read = zip_input_stream.read(chunk, 0, 8192) if read == -1: break self.jar.write(chunk, 0, read) self.jar.closeEntry() except ZipException, e: if not "duplicate entry" in str(e): log.error("Problem in copying entry %r", output_entry, exc_info=True) raise
def copy_zip_input_stream(self, zip_input_stream, parent=None): """Given a `zip_input_stream`, copy all entries to the output jar""" chunk = jarray.zeros(8192, "b") while True: entry = zip_input_stream.getNextEntry() if entry is None: break try: # NB: cannot simply use old entry because we need # to recompute compressed size if parent: name = "/".join([parent, entry.name]) else: name = entry.name output_entry = JarEntry(name) output_entry.time = entry.time self.jar.putNextEntry(output_entry) while True: read = zip_input_stream.read(chunk, 0, 8192) if read == -1: break self.jar.write(chunk, 0, read) self.jar.closeEntry() except ZipException, e: if not "duplicate entry" in str(e): log.error("Problem in copying entry %r", output_entry, exc_info=True) raise
def write_class_bytes(self, package, classname, bytes): path_parts = self._canonical_path_parts(package, classname) self.create_ancestry(path_parts) entry = JarEntry("/".join(path_parts) + ".class") entry.time = self.build_time self.jar.putNextEntry(entry) self.jar.write(bytes.toByteArray()) self.jar.closeEntry()
def copy_file(self, relpath, path): path_parts = tuple(os.path.split(relpath)[0].split(os.sep)) self.create_ancestry(path_parts) chunk = jarray.zeros(8192, "b") with open(path) as f: with closing(BufferedInputStream(f)) as bis: output_entry = JarEntry(relpath) output_entry.time = os.path.getmtime(path) * 1000 self.jar.putNextEntry(output_entry) while True: read = bis.read(chunk, 0, 8192) if read == -1: break self.jar.write(chunk, 0, read) self.jar.closeEntry()
def create_ancestry(self, path_parts): for i in xrange(len(path_parts), 0, -1): # right to left ancestor = "/".join(path_parts[:-i]) + "/" if ancestor == "/": continue # FIXME shouldn't need to do this special casing if ancestor not in self.created_paths: entry = JarEntry(ancestor) entry.time = self.build_time try: self.jar.putNextEntry(entry) self.jar.closeEntry() except ZipException, e: if not "duplicate entry" in str(e): log.error("Problem in creating entry %r", entry, exc_info=True) raise self.created_paths.add(ancestor)
def copy_file(self, relpath, path): path_parts = tuple(os.path.split(relpath)[0].split(os.sep)) self.create_ancestry(path_parts) chunk = jarray.zeros(8192, "b") with open(path) as f: with closing(BufferedInputStream(f)) as bis: output_entry = JarEntry(relpath) output_entry.time = int(os.path.getmtime(path) * 1000) try: self.jar.putNextEntry(output_entry) while True: read = bis.read(chunk, 0, 8192) if read == -1: break self.jar.write(chunk, 0, read) self.jar.closeEntry() except ZipException, e: if not "duplicate entry" in str(e): log.error("Problem in creating entry %r", entry, exc_info=True) raise
def copy_file(self, relpath, path): path_parts = tuple(os.path.split(relpath)[0].split(os.sep)) self.create_ancestry(path_parts) chunk = jarray.zeros(8192, "b") with open(path) as f: with closing(BufferedInputStream(f)) as bis: output_entry = JarEntry(relpath) output_entry.time = os.path.getmtime(path) * 1000 try: self.jar.putNextEntry(output_entry) while True: read = bis.read(chunk, 0, 8192) if read == -1: break self.jar.write(chunk, 0, read) self.jar.closeEntry() except ZipException, e: if not "duplicate entry" in str(e): log.error("Problem in creating entry %r", entry, exc_info=True) raise
def addFile(self, file, parentDirName=None): buffer = jarray.zeros(self._bufsize, 'b') inputStream = FileInputStream(file) jarEntryName = file.getName() if parentDirName: jarEntryName = parentDirName + "/" + jarEntryName self.getJarOutputStream().putNextEntry(JarEntry(jarEntryName)) read = inputStream.read(buffer) while read <> -1: self.getJarOutputStream().write(buffer, 0, read) read = inputStream.read(buffer) self.getJarOutputStream().closeEntry() inputStream.close()
def copy_zip_input_stream(self, zip_input_stream): """Given a `zip_input_stream`, copy all entries to the output jar""" chunk = jarray.zeros(8192, "b") while True: entry = zip_input_stream.getNextEntry() if entry is None: break try: # NB: cannot simply use old entry because we need # to recompute compressed size output_entry = JarEntry(entry.name) output_entry.time = entry.time self.jar.putNextEntry(output_entry) while True: read = zip_input_stream.read(chunk, 0, 8192) if read == -1: break self.jar.write(chunk, 0, read) self.jar.closeEntry() except ZipException, e: if not "duplicate entry" in str(e): print "Problem in copying entry", output_entry raise