Ejemplo n.º 1
0
 def to_archive(self, archive):
     '''Creates an archive header and writes it to the given archive.'''
     e = _libarchive.archive_entry_new()
     try:
         _libarchive.archive_entry_set_pathname(e, self.pathname.encode(self.encoding))
         _libarchive.archive_entry_set_filetype(e, stat.S_IFMT(self.mode))
         _libarchive.archive_entry_set_perm(e, stat.S_IMODE(self.mode))
         _libarchive.archive_entry_set_size(e, self.size)
         _libarchive.archive_entry_set_mtime(e, self.mtime, 0)
         call_and_check(_libarchive.archive_write_header, archive._a, archive._a, e)
         #self.hpos = archive.header_position
     finally:
         _libarchive.archive_entry_free(e)
Ejemplo n.º 2
0
 def to_archive(self, archive):
     '''Creates an archive header and writes it to the given archive.'''
     e = _libarchive.archive_entry_new()
     try:
         _libarchive.archive_entry_set_pathname(e, self.pathname.encode(self.encoding))
         _libarchive.archive_entry_set_filetype(e, stat.S_IFMT(self.mode))
         _libarchive.archive_entry_set_perm(e, stat.S_IMODE(self.mode))
         _libarchive.archive_entry_set_size(e, self.size)
         _libarchive.archive_entry_set_mtime(e, self.mtime, 0)
         call_and_check(_libarchive.archive_write_header, archive._a, archive._a, e)
         #self.hpos = archive.header_position
     finally:
         _libarchive.archive_entry_free(e)
Ejemplo n.º 3
0
    def create(container, archivepath, checked):
        if not isinstance(container, FileSystem):
            logging.info("container '{0}' is not FileSystem".format(container))
            return False

        archivepath = os.path.abspath(archivepath)
        BUFFER_SIZE = 2048

        with libarchive.Archive(archivepath, 'w') as larchive:
            a = larchive._a
            for node in checked:
                if node.is_dir():
                    continue
                path = s2u(node.get_path())
                pathname = os.path.join(*node.get_data_array()[1:])
                if isinstance(pathname, unicode):
                    pathname = pathname.encode('utf8', errors='replace')
                st = os.stat(path)
                entry = _libarchive.archive_entry_new()
                _libarchive.archive_entry_set_pathname(entry, pathname)
                _libarchive.archive_entry_set_size(entry, st.st_size)
                _libarchive.archive_entry_set_filetype(
                    entry, stat.S_IFMT(st.st_mode)
                )
                _libarchive.archive_entry_set_mtime(entry, st.st_mtime, 0)
                _libarchive.archive_entry_set_perm(entry, stat.S_IMODE(st.st_mode))
                _libarchive.archive_write_header(a, entry)

                f = open(path, 'r')

                data = f.read(BUFFER_SIZE)
                count = len(data)

                while count > 0:
                    _libarchive.archive_write_data_from_str(a, data)
                    data = f.read(BUFFER_SIZE)
                    count = len(data)

                f.close()

                _libarchive.archive_entry_free(entry)

            _libarchive.archive_write_close(a)
Ejemplo n.º 4
0
    def create(container, archivepath, checked):
        if not isinstance(container, FileSystem):
            logging.info("container '{0}' is not FileSystem".format(container))
            return False

        archivepath = os.path.abspath(u2s(archivepath))
        BUFFER_SIZE = 2048

        with libarchive.Archive(archivepath, 'w') as larchive:
            a = larchive._a
            for node in checked:
                if node.is_dir():
                    continue
                path = u2s(node.get_path())
                pathname = u2s(os.path.join(*node.get_data_array()[1:]))
                st = os.stat(path)
                entry = _libarchive.archive_entry_new()
                _libarchive.archive_entry_set_pathname(entry, pathname)
                _libarchive.archive_entry_set_size(entry, st.st_size)
                _libarchive.archive_entry_set_filetype(entry,
                                                       stat.S_IFMT(st.st_mode))
                _libarchive.archive_entry_set_mtime(entry, st.st_mtime, 0)
                _libarchive.archive_entry_set_perm(entry,
                                                   stat.S_IMODE(st.st_mode))
                _libarchive.archive_write_header(a, entry)

                f = open(path, 'r')

                data = f.read(BUFFER_SIZE)
                count = len(data)

                while count > 0:
                    _libarchive.archive_write_data_from_str(a, data)
                    data = f.read(BUFFER_SIZE)
                    count = len(data)

                f.close()

                _libarchive.archive_entry_free(entry)

            _libarchive.archive_write_close(a)