(self)
| 277 | self.archive() |
| 278 | |
| 279 | def archive(self): |
| 280 | import tarfile |
| 281 | arch_name = self.get_arch_name() |
| 282 | try: |
| 283 | self.base_path |
| 284 | except AttributeError: |
| 285 | self.base_path = self.path |
| 286 | node = self.base_path.make_node(arch_name) |
| 287 | try: |
| 288 | node.delete() |
| 289 | except OSError: |
| 290 | pass |
| 291 | files = self.get_files() |
| 292 | if self.algo.startswith('tar.'): |
| 293 | tar = tarfile.open(node.abspath(), 'w:' + self.algo.replace('tar.', '')) |
| 294 | for x in files: |
| 295 | self.add_tar_file(x, tar) |
| 296 | tar.close() |
| 297 | elif self.algo == 'zip': |
| 298 | import zipfile |
| 299 | zip = zipfile.ZipFile(node.abspath(), 'w', compression=zipfile.ZIP_DEFLATED) |
| 300 | for x in files: |
| 301 | archive_name = self.get_base_name() + '/' + x.path_from(self.base_path) |
| 302 | zip.write(x.abspath(), archive_name, zipfile.ZIP_DEFLATED) |
| 303 | zip.close() |
| 304 | else: |
| 305 | self.fatal('Valid algo types are tar.bz2, tar.gz, tar.xz or zip') |
| 306 | try: |
| 307 | from hashlib import sha256 |
| 308 | except ImportError: |
| 309 | digest = '' |
| 310 | else: |
| 311 | digest = ' (sha256=%r)' % sha256(node.read(flags='rb')).hexdigest() |
| 312 | Logs.info('New archive created: %s%s', self.arch_name, digest) |
| 313 | |
| 314 | def get_tar_path(self, node): |
| 315 | return node.abspath() |
no test coverage detected