1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Screens.HelpMenu import HelpableScreen
4 from Components.ActionMap import HelpableActionMap, ActionMap
5 from Components.Sources.List import List
6 from Components.Sources.StaticText import StaticText
7 from Components.Sources.Progress import Progress
8 from Components.Task import Task, Job, job_manager, Condition
9 from Components.ScrollLabel import ScrollLabel
10 from Components.Harddisk import harddiskmanager
11 from Components.Console import Console
13 class DVDToolbox(Screen):
15 <screen position="90,83" size="560,445" title="DVD media toolbox" >
16 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
17 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
18 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
19 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
20 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
21 <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
22 <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
23 <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
24 <widget source="info" render="Label" position="20,60" size="520,100" font="Regular;20" />
25 <widget name="details" position="20,200" size="520,200" font="Regular;16" />
26 <widget source="space_bar" render="Progress" position="10,410" size="540,26" borderWidth="1" backgroundColor="#254f7497" />
27 <widget source="space_label" render="Label" position="20,414" size="520,22" zPosition="2" font="Regular;18" halign="center" transparent="1" foregroundColor="#000000" />
30 def __init__(self, session):
31 Screen.__init__(self, session)
33 self["key_red"] = StaticText(_("Exit"))
34 self["key_green"] = StaticText(_("Update"))
35 self["key_yellow"] = StaticText()
36 self["key_blue"] = StaticText()
38 self["space_label"] = StaticText()
39 self["space_bar"] = Progress()
42 self.formattable = False
43 self["details"] = ScrollLabel()
44 self["info"] = StaticText()
46 self["toolboxactions"] = ActionMap(["ColorActions", "DVDToolbox", "OkCancelActions"],
50 "yellow": self.format,
53 "pageUp": self.pageUp,
54 "pageDown": self.pageDown
59 self["details"].pageUp()
62 self["details"].pageDown()
65 self["space_label"].text = _("Please wait... Loading list...")
66 self["info"].text = ""
67 self["details"].setText("")
68 self.Console = Console()
69 cmd = "/bin/dvd+rw-mediainfo /dev/" + harddiskmanager.getCD()
70 self.Console.ePopen(cmd, self.mediainfoCB)
74 job = DVDformatJob(self)
75 job_manager.AddJob(job)
76 from Screens.TaskView import JobView
77 self.session.openWithCallback(self.formatCB, JobView, job)
79 def formatCB(self, in_background):
82 def mediainfoCB(self, mediuminfo, retval, extra_args):
87 for line in mediuminfo.splitlines():
88 if line.find("Mounted Media:") > -1:
89 mediatype = line.rsplit(',',1)[1][1:]
90 if mediatype.find("RW") > 0:
91 self.formattable = True
93 self.formattable = False
94 if line.find("Legacy lead-out at:") > -1:
95 used = int(line.rsplit('=',1)[1]) / 1048576.0
96 print "[lead out] used =", used
97 elif line.find("formatted:") > -1:
98 capacity = int(line.rsplit('=',1)[1]) / 1048576.0
99 print "[formatted] capacity =", capacity
100 elif capacity == 1 and line.find("READ CAPACITY:") > -1:
101 capacity = int(line.rsplit('=',1)[1]) / 1048576.0
102 print "[READ CAP] capacity =", capacity
103 elif line.find("Disc status:") > -1:
104 if line.find("blank") > -1:
105 print "[Disc status] capacity=%d, used=0" % (capacity)
108 elif line.find("Free Blocks:") > -1:
110 size = eval(line[14:].replace("KB","*1024"))
114 capacity = size / 1048576
117 print "[free blocks] capacity=%d, used=%d" % (capacity, used)
118 infotext += line+'\n'
119 self["details"].setText(infotext)
121 self["key_yellow"].text = _("Format")
123 self["key_yellow"].text = ""
124 percent = 100 * used / (capacity or 1)
126 self["space_label"].text = "%d / %d MB" % (used, capacity) + " (%.2f%% " % percent + _("of a DUAL layer medium used.") + ")"
127 self["space_bar"].value = int(percent)
129 self["space_label"].text = "%d / %d MB" % (used, capacity) + " (%.2f%% " % percent + _("of a SINGLE layer medium used.") + ")"
130 self["space_bar"].value = int(percent)
131 elif capacity == 1 and used > 0:
132 self["space_label"].text = "%d MB " % (used) + _("on READ ONLY medium.")
133 self["space_bar"].value = int(percent)
135 self["space_label"].text = _("Medium is not a writeable DVD!")
136 self["space_bar"].value = 0
140 self["info"].text = "Media-Type:\t\t%s\nFree capacity:\t\t%d MB" % (mediatype or "NO DVD", free)
146 class DVDformatJob(Job):
147 def __init__(self, toolbox):
148 Job.__init__(self, _("DVD media toolbox"))
149 self.toolbox = toolbox
153 self.tasks[0].args += [ "-force" ]
156 class DVDformatTaskPostcondition(Condition):
158 def check(self, task):
159 return task.error is None
161 def getErrorMessage(self, task):
163 task.ERROR_ALREADYFORMATTED: _("This DVD RW medium is already formatted - reformatting will erase all content on the disc."),
164 task.ERROR_NOTWRITEABLE: _("Medium is not a writeable DVD!"),
165 task.ERROR_UNKNOWN: _("An unknown error occured!")
168 class DVDformatTask(Task):
169 ERROR_ALREADYFORMATTED, ERROR_NOTWRITEABLE, ERROR_UNKNOWN = range(3)
170 def __init__(self, job, extra_args=[]):
171 Task.__init__(self, job, ("RW medium format"))
172 self.toolbox = job.toolbox
173 self.postconditions.append(DVDformatTaskPostcondition())
174 self.setTool("/bin/dvd+rw-format")
175 self.args += [ "/dev/" + harddiskmanager.getCD() ]
181 def processOutputLine(self, line):
182 if line.startswith("- media is already formatted"):
183 self.error = self.ERROR_ALREADYFORMATTED
185 if line.startswith(":-( mounted media doesn't appear to be"):
186 self.error = self.ERROR_NOTWRITEABLE
188 def processOutput(self, data):
189 print "[DVDformatTask processOutput] ", data
190 if data.endswith('%'):
191 data= data.replace('\x08','')
192 self.progress = int(float(data[:-1])*10)
194 Task.processOutput(self, data)