Create a VisibilityHandler Co-authored-by: nenzen <stefan@nenzen.com> Reviewed-on: #3 Reviewed-by: erth9960 <thuning@dsv.su.se> Co-authored-by: Stefan Nenzén <nenzen@dsv.su.se> Co-committed-by: Stefan Nenzén <nenzen@dsv.su.se>
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
from .handler import Handler
|
|
|
|
|
|
@Handler.register
|
|
class MetadataHandler(Handler):
|
|
"""
|
|
This class handles package metadata.
|
|
"""
|
|
handled_fields = ['title', 'description',
|
|
'created', 'duration',
|
|
'presenters', 'courses',
|
|
'tags']
|
|
|
|
@classmethod
|
|
def wants(cls, jobspec, existing_package):
|
|
"""
|
|
Return True if this handler wants to process this jobspec.
|
|
Raises an exception if the job is wanted but doesn't pass validation.
|
|
|
|
A job is wanted if a source has been passed that contains one or
|
|
more of the following fields:
|
|
- title
|
|
- description
|
|
- created
|
|
- presenters
|
|
- courses
|
|
- tags
|
|
"""
|
|
for key in cls.handled_fields:
|
|
if key in jobspec:
|
|
return cls._validate(jobspec, existing_package)
|
|
return False
|
|
|
|
@classmethod
|
|
def _validate(cls, jobspec, existing_package):
|
|
"""
|
|
Return True if the job is valid for this handler.
|
|
|
|
Does no specific validation since all handled fields are simply text.
|
|
"""
|
|
super()._validate(jobspec, existing_package)
|
|
return True
|
|
|
|
def _handle(self, jobspec, existing_package, tempdir):
|
|
def apply_func(package):
|
|
for key in self.handled_fields:
|
|
if key in jobspec:
|
|
package[key] = jobspec[key]
|
|
return apply_func
|