~mathiaz/+junk/image-store-proxy-pkg-ubuntu

« back to all changes in this revision

Viewing changes to imagestore/model.py

  • Committer: Mathias Gug
  • Date: 2009-09-14 15:35:26 UTC
  • Revision ID: mathias.gug@canonical.com-20090914153526-9x42slhhw3ixcodu
Import initial upstream code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from imagestore.lib.jsonobject import JSONObject, MissingValueError
 
2
 
 
3
 
 
4
class ImageFile(JSONObject):
 
5
    required = ["url", "size-in-bytes", "sha256", "kind"]
 
6
 
 
7
 
 
8
class Image(JSONObject):
 
9
    required = ["uri", "title", "summary"]
 
10
    subtypes = {"files": ImageFile}
 
11
 
 
12
 
 
13
class ImageState(JSONObject):
 
14
    required = ["image-uri", "status"]
 
15
 
 
16
 
 
17
class ImageSection(JSONObject):
 
18
    required = ["title"]
 
19
 
 
20
 
 
21
class ImageStoreResponse(JSONObject):
 
22
    subtypes = {"images": Image,
 
23
                "states": ImageState,
 
24
                "sections": ImageSection}
 
25
 
 
26
 
 
27
class ImageRegistration(object):
 
28
 
 
29
    def __init__(self, image):
 
30
        self.image = image
 
31
        self.eki = ImagePart()
 
32
        self.eri = ImagePart()
 
33
        self.emi = ImagePart()
 
34
 
 
35
    def __eq__(self, other):
 
36
        if type(self) is not type(other):
 
37
            return False
 
38
        return (self.image == other.image and
 
39
                self.eki == other.eki and
 
40
                self.eri == other.eri and
 
41
                self.emi == other.emi)
 
42
 
 
43
    def __ne__(self, other):
 
44
        return not self.__eq__(other)
 
45
 
 
46
 
 
47
class ImagePart(object):
 
48
 
 
49
    eid = None
 
50
    size = None
 
51
    kind = None
 
52
    sha256 = None
 
53
    path = None
 
54
 
 
55
    def __eq__(self, other):
 
56
        if type(self) is not type(other):
 
57
            return False
 
58
        return (self.eid == other.eid and
 
59
                self.size == other.size and
 
60
                self.kind == other.kind and
 
61
                self.sha256 == other.sha256 and
 
62
                self.path == other.path)
 
63