summaryrefslogtreecommitdiff
path: root/lib/archive.py
blob: c8203c9fb516224034e9079db2e55f2f8b721a17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import tarfile
import sys
import parser
import mat

class TarStripper(parser.Generic_parser):
    def remove_all(self):
        if not tarfile.is_tarfile(self.filename):
            print('%s is not a valid tar file' % self.filename)
            sys.exit(1)

        tarin = tarfile.open(self.filename, 'r')
        tarout = tarfile.open(self.filename + parser.POSTFIX, 'w')

        for current_file in tarin.getmembers():
            tarin.extract(current_file)
            if current_file.type is '0': #is current_file a regular file ?
                #no backup file
                class_file = mat.create_class_file(current_file.name, False)
                class_file.remove_all()
                tarout.add(current_file.name)

        #meta from the tar itself
        tarout.mtime = None

        tarout.close()
        tarin.close()

    def is_clean(self):
        return False