Exemplo n.º 1
0
class AllMarksGenerator:
    def __init__(self):
        curr_time = now()
        self.name = 'Marks--%s-%s-%s.zip' % (curr_time.day, curr_time.month,
                                             curr_time.year)
        self.stream = ZipStream()

    def generators(self):
        for mark in MarkSafe.objects.all():
            yield SafeMarkGenerator(mark)
        for mark in MarkUnsafe.objects.all():
            yield UnsafeMarkGenerator(mark)
        for mark in MarkUnknown.objects.all():
            yield UnknownMarkGenerator(mark)

    def __iter__(self):
        for markgen in self.generators():
            buf = b''
            for data in self.stream.compress_stream(markgen.name, markgen):
                buf += data
                if len(buf) > CHUNK_SIZE:
                    yield buf
                    buf = b''
            if len(buf) > 0:
                yield buf
        yield self.stream.close_stream()
Exemplo n.º 2
0
class SeveralMarksGenerator:
    def __init__(self, marks):
        self.marks = marks
        self.stream = ZipStream()
        self.name = 'KleverMarks.zip'

    def generate_mark(self, markgen):
        buf = b''
        for data in self.stream.compress_stream(markgen.name, markgen):
            buf += data
            if len(buf) > CHUNK_SIZE:
                yield buf
                buf = b''
        if len(buf) > 0:
            yield buf

    def __iter__(self):
        for mark in self.marks:
            if isinstance(mark, MarkSafe):
                markgen = SafeMarkGenerator(mark)
            elif isinstance(mark, MarkUnsafe):
                markgen = UnsafeMarkGenerator(mark)
            elif isinstance(mark, MarkUnknown):
                markgen = UnknownMarkGenerator(mark)
            else:
                continue
            yield from self.generate_mark(markgen)
        yield self.stream.close_stream()
Exemplo n.º 3
0
class AllMarksGen(object):
    def __init__(self):
        curr_time = now()
        self.name = 'Marks--%s-%s-%s.zip' % (curr_time.day, curr_time.month,
                                             curr_time.year)
        self.stream = ZipStream()

    def __iter__(self):
        for table in [MarkSafe, MarkUnsafe, MarkUnknown]:
            for mark in table.objects.filter(~Q(version=0)):
                markgen = MarkArchiveGenerator(mark)
                buf = b''
                for data in self.stream.compress_stream(markgen.name, markgen):
                    buf += data
                    if len(buf) > CHUNK_SIZE:
                        yield buf
                        buf = b''
                if len(buf) > 0:
                    yield buf
        yield self.stream.close_stream()
Exemplo n.º 4
0
class JobsArchivesGen:
    def __init__(self, jobs_to_download):
        self.jobs = jobs_to_download
        self.stream = ZipStream()
        self.name = 'KleverJobs.zip'

    def generate_job(self, jobgen):
        buf = b''
        for data in self.stream.compress_stream(jobgen.name, jobgen):
            buf += data
            if len(buf) > CHUNK_SIZE:
                yield buf
                buf = b''
        if len(buf) > 0:
            yield buf

    def __iter__(self):
        for job_id in self.jobs:
            jobgen = JobArchiveGenerator(
                self.jobs[job_id]['instance'],
                decisions_ids=self.jobs[job_id]['decisions'])
            yield from self.generate_job(jobgen)
        yield self.stream.close_stream()