Best Python code snippet using lemoncheesecake
services.py
Source:services.py
...28 with ExifTool(path) as et:29 for image in images:30 ext = os.path.splitext(image.name)[1]31 metadata = Metadata(image.date_time, None, image.author.name)32 params = MetadataSerializerService.instance().serialize_metadata(ext, metadata);33 if params:34 et.execute("-overwrite_original", "-use", "MWG", "-preserve", *params, image.name)35 36 for att in image.attachments.all():37 ext = os.path.splitext(att.name)[1]38 params = MetadataSerializerService.instance().serialize_metadata(ext, metadata);39 if params:40 et.execute("-overwrite_original", "-use", "MWG", "-preserve", *params, att.name)41class MetadataParserService:42 __instance = None43 @classmethod44 def instance(cls):45 if cls.__instance is not None:46 return cls.__instance47 else:48 cls.__instance = MetadataParserService()49 cls.__instance.logger = logging.getLogger(__name__)50 return cls.__instance51 def __init__(self):52 self.parsers = [FujiXT20ImageParser()]53 def parse_metadata(self, json: dict) -> Metadata:54 for p in self.parsers:55 if p.can_parse(json):56 return p.parse(json)57 self.logger.warn('No parser found for %s' % json);58 return Metadata(None, None, None)59class MetadataSerializerService:60 __instance = None61 @classmethod62 def instance(cls):63 if cls.__instance is not None:64 return cls.__instance65 else:66 cls.__instance = MetadataSerializerService()67 return cls.__instance68 def __init__(self):69 self.serializers = [JpegImageSerializer(), OriginalFileSerializer(), FujiRawImageSerializer()]70 def serialize_metadata(self, extension, metadata: Metadata) -> list:71 for p in self.serializers:72 if p.can_serialize(extension):73 return p.serialize(metadata)...
api_utils.py
Source:api_utils.py
...18from qonos.common import timeutils19from qonos.common import utils20from qonos.openstack.common._i18n import _21CONF = api.CONF22def serialize_metadata(metadata):23 to_return = {}24 for item in metadata:25 to_return[item['key']] = item['value']26 return to_return27def deserialize_metadata(metadata):28 to_return = []29 for key, value in metadata.iteritems():30 dict_entry = {}31 if len(key.strip()):32 dict_entry['key'] = key33 dict_entry['value'] = value34 to_return.append(dict_entry)35 else:36 msg = _("Metadata value '%s' is missing key") % value37 raise exception.MissingValue(message=unicode(msg))38 return to_return39def check_read_only_properties(values):40 _read_only_properties = ['created_at', 'updated_at', 'last_scheduled']41 bad_keys = []42 for key in values.keys():43 if key in _read_only_properties:44 bad_keys.append(key)45 if bad_keys:46 msg = _("Cannot update the following read-only attributes: %s") \47 % ', '.join(bad_keys)48 raise exception.Forbidden(message=unicode(msg))49 return values50def serialize_schedule_metadata(schedule):51 metadata = schedule.pop('schedule_metadata')52 schedule['metadata'] = serialize_metadata(metadata)53def deserialize_schedule_metadata(schedule):54 if 'metadata' in schedule:55 metadata = schedule.pop('metadata')56 schedule['schedule_metadata'] = deserialize_metadata(metadata)57def serialize_job_metadata(job):58 metadata = job.pop('job_metadata')59 job['metadata'] = serialize_metadata(metadata)60def deserialize_job_metadata(job):61 if 'metadata' in job:62 metadata = job.pop('metadata')63 job['job_metadata'] = deserialize_metadata(metadata)64def schedule_to_next_run(schedule, start_time=None):65 start_time = start_time or timeutils.utcnow()66 minute = schedule.get('minute', '*')67 hour = schedule.get('hour', '*')68 day_of_month = schedule.get('day_of_month', '*')69 month = schedule.get('month', '*')70 day_of_week = schedule.get('day_of_week', '*')71 return utils.cron_string_to_next_datetime(minute, hour, day_of_month,72 month, day_of_week,73 start_time)74def get_new_timeout_by_action(action):75 now = timeutils.utcnow()76 group = 'action_' + action77 if group not in CONF:...
show.py
Source:show.py
...26 return ensure_single_line_text(suite.description)27 else:28 return suite.path29 def show_test(self, test, suite):30 md = serialize_metadata(test)31 padding = self.get_padding(suite.hierarchy_depth + 1)32 test_label = self.get_test_label(test)33 print("%s- %s%s" % (padding, test_label, " (%s)" % md if md else ""))34 def show_suite(self, suite):35 md = serialize_metadata(suite)36 padding = self.get_padding(suite.hierarchy_depth)37 suite_label = self.get_suite_label(suite)38 print("%s* %s%s" % (padding, bold(suite_label), " (%s)" % md if md else ""))39 for test in suite.get_tests():40 self.show_test(test, suite)41 for sub_suite in suite.get_suites():42 self.show_suite(sub_suite)43 def show_suites(self, suites):44 for suite in suites:45 self.show_suite(suite)46class ShowCommand(Command):47 def get_name(self):48 return "show"49 def get_description(self):...
serializers.py
Source:serializers.py
1from rest_framework import serializers2from torrents.models import AlcazarClientConfig, Realm, Torrent, TorrentInfo, DownloadLocation3from trackers.registry import TrackerRegistry4class AlcazarClientConfigSerializer(serializers.ModelSerializer):5 class Meta:6 model = AlcazarClientConfig7 fields = ('base_url', 'token', 'unify_single_file_torrents')8class RealmSerializer(serializers.ModelSerializer):9 class Meta:10 model = Realm11 fields = ('id', 'name')12class TorrentInfoSerializer(serializers.ModelSerializer):13 metadata = serializers.SerializerMethodField()14 def __init__(self, *args, **kwargs):15 super().__init__(*args, **kwargs)16 self.metadata_serializers_by_realm_id = None17 def _ensure_metadata_serializers_by_realm_id(self):18 if self.metadata_serializers_by_realm_id is not None:19 return20 realms_by_name = {r.name: r for r in Realm.objects.all()}21 self.metadata_serializers_by_realm_id = {}22 for tracker in TrackerRegistry.get_plugins():23 realm = realms_by_name.get(tracker.name)24 if not realm:25 continue26 serializer_class = tracker.torrent_info_metadata_serializer_class27 if serializer_class is None:28 continue29 serializer = serializer_class()30 serializer.bind('metadata', self)31 self.metadata_serializers_by_realm_id[realm.id] = serializer32 def get_metadata(self, obj):33 if not self.context.get('serialize_metadata', True):34 return None35 self._ensure_metadata_serializers_by_realm_id()36 metadata_serializer = self.metadata_serializers_by_realm_id.get(obj.realm_id)37 if metadata_serializer:38 return metadata_serializer.to_representation(obj)39 class Meta:40 model = TorrentInfo41 fields = ('info_hash', 'tracker_id', 'fetched_datetime', 'metadata')42class TorrentSerializer(serializers.ModelSerializer):43 realm = serializers.IntegerField(source='realm_id')44 torrent_info = TorrentInfoSerializer()45 @classmethod46 def get_context_from_request_data(cls, data):47 return {48 'serialize_metadata': bool(int(data.get('serialize_metadata', '1')))49 }50 class Meta:51 model = Torrent52 fields = '__all__'53class DownloadLocationSerializer(serializers.ModelSerializer):54 realm = serializers.PrimaryKeyRelatedField(queryset=Realm.objects.all())55 class Meta:56 model = DownloadLocation...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!