]>
git.ipfire.org Git - ipfire.org.git/blob - www/webapp/handlers_boot.py
5 import tornado
.httpserver
13 BASEDIR
= os
.path
.dirname(__file__
)
15 def word_wrap(s
, width
=45):
16 paragraphs
= s
.split('\n')
18 for paragraph
in paragraphs
:
19 while len(paragraph
) > width
:
20 pos
= paragraph
.rfind(' ', 0, width
)
23 lines
.append(paragraph
[:pos
])
24 paragraph
= paragraph
[pos
:]
25 lines
.append(paragraph
.lstrip())
26 return '\n'.join(lines
)
28 class BootBaseHandler(tornado
.web
.RequestHandler
):
31 return backend
.NetBoot()
34 class MenuGPXEHandler(BootBaseHandler
):
39 # XXX Check if version of the bootloader is allright
42 self
.set_header("Content-Type", "text/plain")
43 self
.write("#!gpxe\n")
44 self
.write("chain menu.c32 premenu.cfg\n")
47 class MenuCfgHandler(BootBaseHandler
):
48 def _menu_string(self
, menu
, level
=0):
52 s
+= self
._menu
_entry
(entry
, level
=level
)
56 def _menu_entry(self
, entry
, level
=0):
61 if entry
.type == "seperator":
62 lines
.append(ident
+ "menu separator")
64 elif entry
.type == "header":
65 lines
.append(ident
+ "menu begin %d" % entry
.id)
66 lines
.append(ident
+ "\tmenu title %s" % entry
.title
)
69 lines
.append(ident
+ "\tlabel %d.back" % entry
.id)
70 lines
.append(ident
+ "\t\tmenu label Back...")
71 lines
.append(ident
+ "\t\tmenu exit")
72 lines
.append(ident
+ "\tmenu separator")
74 lines
.append("%s" % self
._menu
_string
(entry
.submenu
, level
=level
+1))
75 lines
.append(ident
+ "menu end")
77 elif entry
.type == "config":
78 lines
.append(ident
+ "label %d" % entry
.id)
79 lines
.append(ident
+ "\tmenu label %s" % entry
.title
)
81 lines
.append(ident
+ "\ttext help")
82 lines
.append(word_wrap(entry
.description
))
83 lines
.append(ident
+ "\tendtext")
84 lines
.append(ident
+ "\tkernel /config/%s/boot.gpxe" % entry
.item
)
86 return "\n".join(lines
+ [""])
89 self
.set_header("Content-Type", "text/plain")
91 menu
= self
._menu
_string
(self
.netboot
.get_menu(1))
93 self
.render("menu.cfg", menu
=menu
)
96 class BootGPXEHandler(BootBaseHandler
):
98 config
= self
.netboot
.get_config(id)
100 raise tornado
.web
.HTTPError(404, "Configuration with ID '%s' was not found" % id)
102 lines
= ["#!gpxe", "imgfree",]
104 line
= "kernel -n img %s" % config
.image1
105 if line
.endswith(".iso"):
108 line
+= " %s" % config
.args
112 lines
.append("initrd -n img %s" % config
.image2
)
114 lines
.append("boot img")
117 self
.write("%s\n" % line
)