]>
git.ipfire.org Git - ipfire.org.git/blob - src/backend/iuse.py
19651b565ac32fb5227fc2f60f2e84d7ff8bd979
7 from PIL
import Image
, ImageDraw
, ImageFont
, PngImagePlugin
9 from .misc
import Object
10 from .decorators
import *
15 def get_imagetype(self
, id):
18 for image_type
in image_types
:
19 if image_type
.id == id:
23 class ImageObject(Object
):
26 def init(self
, request
, profile
):
27 self
.request
= request
28 self
.profile
= profile
31 if self
.filename
and os
.path
.exists(self
.filename
):
32 with Image
.open(self
.filename
) as image
:
33 self
._image
= image
.convert("RGBA")
35 self
._image
= Image
.new("RGBA", (100, 100))
40 with io
.BytesIO() as f
:
41 self
._image
.save(f
, "PNG", optimize
=True)
47 fontfile
= os
.path
.join(
48 self
.request
.application
.settings
.get("static_path", ""),
49 "fonts/Prompt-Regular.ttf"
52 return ImageFont
.truetype(fontfile
, 15, encoding
="unic")
56 return ImageDraw
.Draw(self
._image
)
58 def draw_text(self
, pos
, text
, **kwargs
):
59 return self
.draw
.text(pos
, text
, font
=self
.font
, **kwargs
)
63 if not self
._filename
:
67 self
.request
.application
.settings
.get("template_path", ""),
68 "fireinfo", self
._filename
73 return self
.request
.locale
76 class Image1(ImageObject
):
79 default_size
= 500, 50
80 _filename
= "i-use-1.png"
83 _
= self
.locale
.translate
85 line1
= [_("%s on %s") % (self
.profile
.system
.release
, self
.profile
.processor
.arch
),]
88 # Show the hypervisor vendor for virtual machines
89 if self
.profile
.system
.is_virtual():
90 if self
.profile
.hypervisor
:
91 line2
.append(_("Virtualised on %s") % self
.profile
.hypervisor
)
93 line2
.append(_("Running in a virtualised environment"))
95 # Otherwise show some general hardware information of the machine
97 if self
.profile
.processor
:
98 line2
.append(self
.profile
.processor
.friendly_string
)
100 line2
.append(self
.profile
.friendly_memory
)
102 self
.draw_text((225, 5), " | ".join(line1
))
103 self
.draw_text((225, 23), "%s" % " - ".join(line2
))
106 image_types
.append(Image1
)