コード例 #1
0
ファイル: transfer.py プロジェクト: eblade/images7
        transcoder = get_transcoder(entry.type.value + '-proxy')

        targets = [
            transcoder.Options(entry=entry,
                               cut_source=self.cut_path,
                               purpose=FilePurpose.proxy),
            transcoder.Options(entry=entry,
                               cut_source=self.cut_path,
                               purpose=FilePurpose.thumb),
            transcoder.Options(entry=entry,
                               cut_source=self.cut_path,
                               purpose=FilePurpose.check),  # clean_up=True
        ]

        filerefs = []
        for target in targets:
            f = transcoder.run(target)
            filerefs.append(
                FileReference(
                    purpose=target.purpose,
                    version=self.source.version,
                    reference=f.reference,
                    mime_type=f.mime_type,
                ))

        logging.info(filerefs)
        # Sen kanske bra att spara dem...


register_job_handler(TransferJobHandler)
コード例 #2
0
            path = cut.result.path

        analyse = get_analyser(step.options.mime_type)

        if analyse is None:
            logging.info("Found no metadata analyser for %s",
                         step.options.mime_type)
            step.status = StepStatus.done
            return

        metadata = analyse(path)

        if metadata is not None and step.options.entry_id is not None:

            @retry()
            def update():
                entry = get_entry_by_id(step.options.entry_id)
                if entry.metadata is None:
                    entry.metadata = metadata
                else:
                    entry.metadata.merge(metadata)
                update_entry_by_id(entry.id, entry)

            update()

        step.result = ReadMetadataResult(metadata=metadata)
        step.status = StepStatus.done


register_job_handler(ReadMetadata)
コード例 #3
0
ファイル: to_cut.py プロジェクト: eblade/images7
        system = current_system()

        source = get_file_by_url(step.options.source_url)
        source_url = source.parsed_url
        source_path = source_url.path

        cut = system.cut_storage
        cut_filename = uuid.uuid4().hex
        cut_path = os.path.join(resolve_path(cut.root_path), cut_filename)

        if source_url.scheme == 'card':
            if step.options.source_root_path is not None:
                source_path = os.path.join(step.options.source_root_path,
                                           source_path[1:])
        else:
            raise Exception("Only support card here")

        filecopy = FileCopy(
            source=source_path,
            destination=cut_path,
            link=False,
            remove_source=False,
        )
        filecopy.run()

        step.result = ToCutResult(path=cut_path)
        step.status = StepStatus.done


register_job_handler(ToCut)
コード例 #4
0
ファイル: calculate_hash.py プロジェクト: eblade/images7
class CalculateHashResult(PropertySet):
    calculated_hash = Property()


register_schema(CalculateHashResult)


class CalculateHash(JobHandler):
    method = 'calculate_hash'
    Options = CalculateHashOptions

    def run(self, job: Job):
        logging.debug(job.to_json())

        step = job.get_current_step()

        if step.options.path is not None:
            path = step.options.path
        else:
            cut = job.get_step('to_cut')
            path = cut.result.path

        ref = calculate_hash(path)

        step.result = CalculateHashResult(calculated_hash=ref)
        step.status = StepStatus.done


register_job_handler(CalculateHash)
コード例 #5
0
ファイル: to_main.py プロジェクト: eblade/images7
        )
        filecopy.run()

        @retry()
        def push():
            entry = get_entry_by_id(step.options.entry_id)
            new_file_ref = FileReference(
                purpose=file_ref.purpose,
                version=file_ref.version,
                reference=reference,
                mime_type=file_ref.mime_type,
            )
            new_file = File(
                reference=reference,
                url=system.main_storage.get_file_url(main_path),
                mime_type=source.mime_type,
                status=FileStatus.managed,
            )
            create_file(new_file)

            entry.files.append(new_file_ref)
            update_entry_by_id(entry.id, entry)

        push()

        step.result = ToMainResult()
        step.status = StepStatus.done


register_job_handler(ToMain)
コード例 #6
0
ファイル: create_proxy.py プロジェクト: eblade/images7
                    purpose=target.purpose,
                    version=source_ref.version,
                    reference=f.reference,
                    mime_type=f.mime_type,
                ))

        logging.info(filerefs)

        @retry()
        def push():
            entry = get_entry_by_id(step.options.entry_id)

            for file_ref in filerefs:
                new_file_ref = FileReference(
                    purpose=file_ref.purpose,
                    version=file_ref.version,
                    reference=file_ref.reference,
                    mime_type=file_ref.mime_type,
                )
                entry.files.append(new_file_ref)

            update_entry_by_id(entry.id, entry)

        push()

        step.result = CreateProxyResult()
        step.status = StepStatus.done


register_job_handler(CreateProxy)
コード例 #7
0
                jobs.append(
                    Job(steps=[
                        ToCut.AsStep(
                            source_root_path=root_path,
                            source_url=f.url,
                        ),
                        CalculateHash.AsStep(),
                        ReadMetadata.AsStep(
                            entry_id=entry.id,
                            mime_type=f.mime_type,
                        ),
                        ToMain.AsStep(
                            entry_id=entry.id,
                            source_url=f.url,
                        ),
                        CreateProxy.AsStep(
                            entry_id=entry.id,
                            source_url=f.url,
                        ),
                        CleanCut.AsStep(),
                    ]))

            update_entry_by_id(entry.id, entry)

            with QueueClient('ipc://job_queue') as q:
                for job in jobs:
                    q.send(job)


register_job_handler(Register)
コード例 #8
0
ファイル: clean_cut.py プロジェクト: eblade/images7

class CleanCutResult(PropertySet):
    pass


register_schema(CleanCutResult)


class CleanCut(JobHandler):
    method = 'clean_cut'
    Options = CleanCutOptions

    def run(self, job: Job):
        logging.debug(job.to_json())

        step = job.get_current_step()

        cut = job.get_step('to_cut')

        if cut is not None:
            source_path = cut.result.path
            if os.path.exists(source_path):
                os.remove(source_path)

        step.result = CleanCutResult()
        step.status = StepStatus.done


register_job_handler(CleanCut)