]>
git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - webapp/backend/iuse.py
3 from __future__
import division
9 from PIL
import Image
, ImageDraw
, ImageFont
, PngImagePlugin
11 from misc
import Object
16 def get_imagetype(self
, id):
19 for image_type
in image_types
:
20 if image_type
.id == id:
24 class ImageObject(Object
):
26 default_size
= 100, 100
29 _font
= "DejaVuSans.ttf"
32 def __init__(self
, backend
, request
, profile
):
33 Object
.__init
__(self
, backend
)
35 self
.request
= request
36 self
.profile
= profile
39 if self
.filename
and os
.path
.exists(self
.filename
):
40 self
.open(self
.filename
)
42 self
._image
= Image
.new(self
.default_mode
, self
.default_size
)
46 def open(self
, filename
):
47 logging
.debug("Opening image as a template: %s" % filename
)
49 image
= Image
.open(filename
)
50 self
._image
= image
.convert(self
.default_mode
)
52 def save(self
, filename
):
53 self
._image
.save(filename
, "PNG", optimize
=True)
56 f
= StringIO
.StringIO()
64 if not hasattr(self
, "_draw"):
65 self
._draw
= ImageDraw
.Draw(self
._image
)
70 raise NotImplementedError
74 if not hasattr(self
, "__font"):
75 fontfile
= os
.path
.join(
76 self
.request
.application
.settings
.get("template_path", ""),
77 "i-use", "fonts", self
._font
80 self
.__font
= ImageFont
.truetype(fontfile
, self
._font
_size
, encoding
="unic")
84 def draw_text(self
, pos
, text
, **kwargs
):
85 if not kwargs
.has_key("font"):
86 kwargs
["font"] = self
.font
88 return self
.paint
.text(pos
, text
, **kwargs
)
92 if not self
._filename
:
96 self
.request
.application
.settings
.get("template_path", ""),
97 "i-use", self
._filename
102 return self
.request
.locale
105 #class Image1(ImageObject):
108 # default_size = 500, 50
112 # self.paint.rectangle(((0, 0), self.default_size), fill="#000000")
114 # # Release information
115 # self.paint.text((10, 10), "%s" % self.profile.release)
117 # # Hardware information
119 # self.profile.cpu.model_string,
120 # "Mem: %.1fG" % (self.profile.memory / 1024**2),
123 # if self.profile.virtual:
124 # virt = "V-%s" % self.profile.hypervisor.vendor
125 # if self.profile.hypervisor.type == "para":
126 # virt = "%s-PV" % virt
129 # if self.profile.cpu.capable_64bit:
132 # self.paint.text((10, 30), "%s" % " | ".join(hw))
135 #IUse().add_imagetype(Image1)
138 class Image1(ImageObject
):
141 default_size
= 500, 50
143 _filename
= "i-use-1.png"
144 _font
= "DejaVuSans.ttf"
148 _
= self
.locale
.translate
150 line1
= [self
.profile
.release
,]
152 if self
.profile
.virtual
:
153 virt
= "V-%s" % self
.profile
.hypervisor
.vendor
154 if self
.profile
.hypervisor
.type == "para":
155 virt
= "%s-PV" % virt
158 self
.draw_text((225, 8), " | ".join(line1
))
161 line2
.append(self
.profile
.cpu
.friendly_string
)
162 line2
.append(_("Mem: %s") % self
.profile
.friendly_memory
)
164 if self
.profile
.root_size
:
165 line2
.append(_("Disk: %s") % self
.profile
.friendly_root_size
)
169 if self
.profile
.network
:
172 for zone
in ("green", "red", "blue", "orange"):
173 if self
.profile
.network
.has_zone(zone
):
174 zones
.append(_(zone
))
177 line3
.append(_("Networks: %s") % " | ".join(zones
))
179 self
.draw_text((225, 20), "%s" % " - ".join(line2
))
180 self
.draw_text((225, 32), "%s" % " - ".join(line3
))
183 image_types
.append(Image1
)