Source code for copr.client_v2.entities

from ..util import UnicodeMixin

from .schemas import ProjectSchema, EmptySchema, ProjectChrootSchema, BuildSchema, BuildTaskSchema, MockChrootSchema, \
    ProjectCreateSchema

try:
    _ = ProjectSchema(strict=True)
    kwargs = {"strict": True}
except TypeError:
    kwargs = {}


class Link(UnicodeMixin):

[docs] _schema = EmptySchema() def __init__(self, **kwargs): for field in self._schema.fields.keys(): setattr(self, field, kwargs.get(field)) def to_dict(self):
[docs] output = self._schema.dump(self) output = getattr(output, "data", output) return output def to_json(self):
[docs] output = self._schema.dumps(self) output = getattr(output, "data", output) return output @classmethod
def from_dict(cls, raw_dict):
[docs] parsed = cls._schema.load(raw_dict) parsed = getattr(parsed, "data", parsed) return cls(**parsed) class ProjectEntity(Entity):
[docs] _schema = ProjectSchema(**kwargs) def __unicode__(self): return "<Project #{0}: {1}/{2}>".format(self.id, self.owner, self.name) class ProjectCreateEntity(Entity):
[docs] _schema = ProjectCreateSchema(**kwargs) def __unicode__(self): return "<New project {0}/{1}>".format(self.owner, self.name) class ProjectChrootEntity(Entity):
[docs] _schema = ProjectChrootSchema(**kwargs) def __unicode__(self): return "<Project chroot: {0}, additional " \ "packages: {1}, comps size if any: {2}>"\ .format(self.name, self.buildroot_pkgs, self.comps_len,) class BuildEntity(Entity):
[docs] _schema = BuildSchema(**kwargs) def __unicode__(self): return "<Build #{0} state: {1}>".format(self.id, self.state) def is_finished(self):
[docs] """ Check is the build was finished :rtype: bool """ return self.state in [ "failed", "skipped", "succeeded" ] class BuildTaskEntity(Entity):
[docs] _schema = BuildTaskSchema(**kwargs) def __unicode__(self): return "<Build task #{0}-{1}, state: {2}>".format( self.build_id, self.chroot_name, self.state ) class MockChrootEntity(Entity):
[docs] _schema = MockChrootSchema(**kwargs) def __unicode__(self): return "<Mock chroot: {0} is active: {1}>".format( self.name, self.is_active )