from ..importer import register_import_module from ..entry import get_entry_by_id, update_entry_by_id, Purpose, Variant, State from ..localfile import FileCopy, FolderScanner ############ # RAW IMPORT class RawImportOptions(PropertySet): entry_id = Property(int) source_path = Property() folder = Property() mime_type = Property() register_schema(RawImportOptions) class RawImportJobHandler(JobHandler): Options = RawImportOptions method = 'raw_import' def run(self, job): logging.info('Starting raw import.') assert job is not None, "Job can't be None" assert job.options is not None, "Job Options can't be None" logging.info('Job\n%s', job.to_json()) self.system = current_system() self.options = job.options self.folder = self.system.import_folders[self.options.folder]
from ..job import JobHandler, Job, create_job, register_job_handler from ..job.imageproxy import ImageProxyOptions, ImageProxyJobHandler class JPEGImportOptions(PropertySet): entry_id = Property(int) source_path = Property() folder = Property() mime_type = Property() analyse = Property(bool) is_derivative = Property(bool, default=False) source_purpose = Property(enum=Purpose, default=Purpose.raw) source_version = Property(int) register_schema(JPEGImportOptions) class JPEGImportJobHandler(JobHandler): Options = JPEGImportOptions method = 'jpeg_import' def run(self, job): logging.info('Starting jpg generation.') assert job is not None, "Job can't be None" assert job.options is not None, "Job Options can't be None" logging.info('Job\n%s', job.to_json()) self.system = current_system() self.options = job.options self.folder = self.system.import_folders[self.options.folder]
from jsonobject import PropertySet, Property, register_schema from images7.job import JobHandler, Job, StepStatus, register_job_handler from images7.analyse import get_analyser from images7.retry import retry from images7.entry import get_entry_by_id, update_entry_by_id class ReadMetadataOptions(PropertySet): path = Property() mime_type = Property() entry_id = Property() register_schema(ReadMetadataOptions) class ReadMetadataResult(PropertySet): metadata = Property(wrap=True) register_schema(ReadMetadataResult) class ReadMetadata(JobHandler): method = 'read_metadata' Options = ReadMetadataOptions def run(self, job: Job): logging.debug(job.to_json())
from ..job import JobHandler, register_job_handler from ..system import current_system from ..entry import get_entry_by_id, update_entry_by_id, Purpose, Backup class FlickrOptions(PropertySet): entry_id = Property(int) source_purpose = Property(enum=Purpose, default=Purpose.original) source_version = Property(int) title = Property() description = Property() tags = Property(list) is_public = Property(bool, default=True) register_schema(FlickrOptions) class FlickrJobHandler(JobHandler): method = 'flickr' Options = FlickrOptions def run(self, job): logging.info('Starting flickr export.') assert job is not None, "Job can't be None" assert job.options is not None, "Job Options can't be None" logging.info('Job\n%s', job.to_json()) options = job.options entry = get_entry_by_id(options.entry_id)
Purpose, get_entry_by_id, update_entry_by_id, delete_entry_by_id, ) class ImageProxyOptions(PropertySet): entry_id = Property(int) angle = Property(int) mirror = Property(int) source_purpose = Property(enum=Purpose, default=Purpose.original) source_version = Property(int) register_schema(ImageProxyOptions) class ImageProxyJobHandler(JobHandler): Options = ImageProxyOptions method = 'imageproxy' def run(self, job): logging.info('Starting image proxy generation.') assert job is not None, "Job can't be None" assert job.options is not None, "Job Options can't be None" logging.info('Job\n%s', job.to_json()) options = job.options self.entry = get_entry_by_id(options.entry_id) logging.info('Entry\n%s', self.entry.to_json())
description = Property() author = Property() copyright = Property() source = Property() original_filename = Property() taken_ts = Property() orientation = Property() mirror = Property() angle = Property(int, default=0) def merge(self, other): for k, v in other.to_dict().items(): if hasattr(self, k): setattr(self, k, v) register_schema(DefaultEntryMetadata) class EntryFeed(PropertySet): count = Property(int) total_count = Property(int) offset = Property(int) date = Property() state = Property(enum=State) entries = Property(Entry, is_list=True) class EntryQuery(Query): prev_offset = Property(int) offset = Property(int, default=0) page_size = Property(int, default=25, required=True)
from ..system import current_system from ..entry import ( Variant, get_entry_by_id, update_entry_by_id, ) from ..job import JobHandler, Job, create_job, register_job_handler from .remote import RemoteOptions, RemoteJobHandler class RulesOptions(PropertySet): entry_id = Property(int) entry_ids = Property(list) register_schema(RulesOptions) class RulesJobHandler(JobHandler): Options = RulesOptions method = 'rules' def run(self, job): logging.info('Starting rules check.') assert job is not None, "Job can't be None" assert job.options is not None, "Job Options can't be None" logging.info('Job\n%s', job.to_json()) system = current_system() options = job.options rules = system.rules.values()
method = None Options = lambda: None def __init__(self, **kwargs): for key, value in kwargs.items(): setattr(self, key.replace(' ', '_'), value) def run(self, *args, **kwargs): raise NotImplementedError @classmethod def AsStep(cls, **kwargs): return Step(method=cls.method, options=cls.Options(**kwargs)) class DummyOptions(PropertySet): time = Property(float, default=1.0) class DummyJobHandler(JobHandler): method = 'dummy' Options = DummyOptions def run(self, job): options = job.options time.sleep(options.time) register_job_handler(DummyJobHandler) register_schema(DummyOptions)
import uuid from jsonobject import PropertySet, Property, register_schema from images7.system import current_system from images7.config import resolve_path from images7.job import JobHandler, Job, register_job_handler, StepStatus from images7.files import get_file_by_url from images7.localfile import FileCopy class CleanCutOptions(PropertySet): pass register_schema(CleanCutOptions) 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())
from jsonobject import PropertySet, Property, register_schema from ..system import current_system from ..localfile import FileCopy, mangle from ..job import JobHandler, Job, register_job_handler from ..entry import Variant LOCAL_STORES = ('original', 'derivative', 'thumb', 'proxy', 'check', 'raw') class DeleteOptions(PropertySet): entry_id = Property(int) variant = Property(Variant) register_schema(DeleteOptions) class DeleteJobHandler(JobHandler): Options = DeleteOptions method = 'delete' def run(self, job): logging.info('Starting delete job.') assert job is not None, "Job can't be None" assert job.options is not None, "Job Options can't be None" logging.info('Job\n%s', job.to_json()) self.system = current_system() self.options = job.options self.variant = job.options.variant
flash = Property() focal_length = Property(tuple) focal_length_in_35_mm_film = Property(int) geometry = Property(tuple) iso_speed_ratings = Property(int) make = Property() model = Property() saturation = Property() software = Property() subject_distance_range = Property(int) white_balance = Property() latitude = Property() longitude = Property() register_schema(ExifMetadata) # Helper functions to convert exif data into better formats orientation2angle = { 'Horizontal (normal)': (None, 0), 'Mirrored horizontal': ('H', 0), 'Rotated 180': (None, 180), 'Mirrored vertical': ('V', 0), 'Mirrored horizontal then rotated 90 CCW': ('H', -90), 'Rotated 90 CCW': (None, -90), 'Mirrored horizontal then rotated 90 CW': ('H', 90), 'Rotated 90 CW': (None, 90), }
class ElementType(EnumProperty): image = 'image' text = 'text' heading = 'heading' class Element(PropertySet): type = Property(enum=ElementType, default=ElementType.image) src = Property() content = Property() entry_id = Property() class Page(PropertySet): number = Property(int) show = Property(bool, default=True) width = Property(int) height = Property(int) elements = Property(type=Element, is_list=True) class Publication(PropertySet): author = Property() publish_ts = Property() title = Property() comment = Property() pages = Property(type=Page, is_list=True) register_schema(Publication)
import logging from jsonobject import register_schema, PropertySet, Property from ..system import current_system from ..job import JobHandler, register_job_handler from ..entry import get_entry_by_id, update_entry_by_id, Purpose, Variant from ..localfile import FileCopy, FolderScanner class AmendOptions(PropertySet): entry_id = Property(int) amend_metadata = Property(bool, default=True) amend_variants = Property(bool, default=True) register_schema(AmendOptions) class AmendJobHandler(JobHandler): method = 'amend' Options = AmendOptions def run(self, job): logging.info('Starting amending.') assert job is not None, "Job can't be None" assert job.options is not None, "Job Options can't be None" logging.info('Job\n%s', job.to_json()) options = job.options entry = get_entry_by_id(options.entry_id) before = entry.to_json()
from ..entry import ( Variant, Backup, get_entry_by_id, update_entry_by_id, ) from ..job import JobHandler, Job, create_job, register_job_handler class RemoteOptions(PropertySet): entry_id = Property(int) variant = Property(type=Variant) remote = Property() register_schema(RemoteOptions) class RemoteJobHandler(JobHandler): Options = RemoteOptions method = 'remote' def run(self, job): logging.info('Starting remote transfer.') assert job is not None, "Job can't be None" assert job.options is not None, "Job Options can't be None" logging.info('Job\n%s', job.to_json()) system = current_system() options = job.options remote = system.remotes[options.remote] rules = system.rules.values()
from images7.system import current_system from images7.files import File, FileStatus, create_file from images7.entry import ( Entry, FilePurpose, ) from images7.job.transcode import Transcoder, DefaultTranscodeOptions, register_transcoder from images7.localfile import FileCopy, calculate_hash from images7.retry import retry class ImageProxyOptions(DefaultTranscodeOptions): entry = Property(type=Entry) register_schema(ImageProxyOptions) class ImageTranscoder(Transcoder): Options = ImageProxyOptions def run(self, options: ImageProxyOptions): logging.info('Starting image transaction.') assert options is not None, "Options can't be None" logging.info('Options\n%s', options.to_json()) entry = options.entry logging.info('Entry\n%s', entry.to_json()) self.system = current_system() self.full_original_file_path = options.cut_source
return inst class ImportJobSettings(PropertySet): proxy_size = Property(int) thumb_size = Property(int) check_size = Property(int) class FlickrJobSettings(PropertySet): username = Property() secret = Property() key = Property() register_schema(ImportJobSettings) register_schema(FlickrJobSettings) class Config(PropertySet): system = Property(type=SystemConfig) https = Property(type=HttpConfig, is_list=True) zmqs = Property(type=ZeroMQConfig, is_list=True) databases = Property(type=DatabaseConfig, is_list=True) servers = Property(type=ServerConfig, is_list=True) storages = Property(type=StorageConfig, is_list=True) cards = Property(type=CardConfig, is_list=True) drops = Property(type=DropConfig, is_list=True) exports = Property(type=ExportConfig, is_list=True) jobs = Property(type=JobConfig, is_list=True) import_settings = Property(type=ImportJobSettings)
from images7.config import resolve_path from images7.job import JobHandler, Job, StepStatus, register_job_handler from images7.retry import retry from images7.entry import get_entry_by_id, update_entry_by_id, FilePurpose, FileReference from images7.files import get_file_by_url, create_file, File, FileStatus from images7.localfile import FileCopy class ToMainOptions(PropertySet): path = Property() entry_id = Property() source_url = Property() reference = Property() register_schema(ToMainOptions) class ToMainResult(PropertySet): pass register_schema(ToMainResult) class ToMain(JobHandler): method = 'to_main' Options = ToMainOptions def run(self, job: Job): logging.debug(job.to_json())
from . import JobHandler, register_job_handler from ..system import current_system from ..entry import get_entry_by_id, update_entry_by_id, Purpose, Variant, State ################# # TAG BULK UPDATE class TagBulkUpdateOptions(PropertySet): entry_ids = Property(list) add_tags = Property(list) remove_tags = Property(list) register_schema(TagBulkUpdateOptions) class TagBulkUpdateJobHandler(JobHandler): Options = TagBulkUpdateOptions method = 'tag_update' def run(self, job): logging.info('Starting tag update.') assert job is not None, "Job can't be None" assert job.options is not None, "Job Options can't be None" logging.info('Job\n%s', job.to_json()) system = current_system() options = job.options if len(options.add_tags) == 0 and len(options.remove_tags) == 0:
root_path = Property() path = Property() is_raw = Property(bool) mime_type = Property() def get_url(self, system): source = system.config.get_source_by_name(self.source) assert source is not None, "Source with name %s not found" % self.source return source.get_part_url(self) class RegisterImportOptions(PropertySet): parts = Property(type=RegisterPart, is_list=True) register_schema(RegisterImportOptions) class Register(JobHandler): Options = RegisterImportOptions method = 'register' def run(self, job): logging.info('Starting register import.') assert job is not None, "Job can't be None" logging.info('Job\n%s', job.to_json()) self.step = job.get_current_step() self.system = current_system() self.options = self.step.options self.register_parts()
import os import logging import uuid import datetime from jsonobject import PropertySet, Property, register_schema from images7.job import JobHandler, Job, StepStatus, register_job_handler from images7.localfile import calculate_hash class CalculateHashOptions(PropertySet): path = Property() register_schema(CalculateHashOptions) 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())
def get_job_handler_for_method(method): return _handlers[method] class JobHandler(object): def __init__(self, **kwargs): for key, value in kwargs.items(): setattr(self, key.replace(' ', '_'), value) def run(self, *args, **kwargs): raise NotImplemented class DummyOptions(PropertySet): time = Property(float, default=1.0) class DummyJobHandler(JobHandler): method = 'dummy' Options = DummyOptions def run(self, job): options = job.options time.sleep(options.time) register_job_handler(DummyJobHandler) register_schema(DummyOptions)
from jsonobject import PropertySet, Property, register_schema from images7.system import current_system from images7.config import resolve_path from images7.job import JobHandler, Job, register_job_handler, StepStatus from images7.files import get_file_by_url from images7.localfile import FileCopy class ToCutOptions(PropertySet): source_root_path = Property() source_url = Property() register_schema(ToCutOptions) class ToCutResult(PropertySet): path = Property() register_schema(ToCutResult) class ToCut(JobHandler): method = 'to_cut' Options = ToCutOptions def run(self, job: Job): logging.debug(job.to_json())
from images7.config import resolve_path from images7.job import JobHandler, Job, StepStatus, register_job_handler from images7.retry import retry from images7.entry import get_entry_by_id, update_entry_by_id, FilePurpose, FileReference from images7.files import get_file_by_url, create_file, File, FileStatus from images7.localfile import FileCopy from images7.job.transcode import get_transcoder class CreateProxyOptions(PropertySet): path = Property() entry_id = Property() source_url = Property() register_schema(CreateProxyOptions) class CreateProxyResult(PropertySet): pass register_schema(CreateProxyResult) class CreateProxy(JobHandler): method = 'create_proxy' Options = CreateProxyOptions def run(self, job: Job): logging.debug(job.to_json())
from images7.localfile import FileCopy, mangle, calculate_hash from images7.files import get_file_by_url, create_file, File, FileStatus from images7.analyse import get_analyser from images7.entry import get_entry_by_id, update_entry_by_id, FilePurpose, FileReference from images7.retry import retry, GiveUp class TransferOptions(PropertySet): entry_id = Property() source_url = Property() source_root_path = Property() destination = Property() steps = Property(type=list) register_schema(TransferOptions) class TransferJobHandler(JobHandler): Options = TransferOptions method = 'transfer' def run(self, job): logging.info('Starting transfer') assert job is not None, "Job can't be None" assert job.options is not None, "Job Options can't be None" logging.info('Job\n%s', job.to_json()) self.system = current_system() self.options = job.options self.source = get_file_by_url(self.options.source_url)