Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNate Theis <natetheis@gmail.com>2010-11-30 04:55:03 (GMT)
committer Nate Theis <natetheis@gmail.com>2010-11-30 04:55:03 (GMT)
commitc26fef480236e9836754454daf4e524f03240094 (patch)
tree331b6ba99a1e25b1076cbb39485771678e51e9bf
parent1a91792f4136b7c53af64b38a7b3d69ecaade576 (diff)
Added a lot of parser code, notably the progress reader
-rwxr-xr-xwodim2
-rw-r--r--wodim_tools.py92
2 files changed, 72 insertions, 22 deletions
diff --git a/wodim b/wodim
index 4708bcd..e15b121 100755
--- a/wodim
+++ b/wodim
@@ -1,2 +1,2 @@
#!/bin/bash
-cat typescript
+cat wodim_log.txt
diff --git a/wodim_tools.py b/wodim_tools.py
index 16c9f04..8d8d7d5 100644
--- a/wodim_tools.py
+++ b/wodim_tools.py
@@ -4,46 +4,96 @@ import pexpect, re
#Define some handy things (regexes, strings, etc)
-trackmatcher = re.compile(r"Track (?P<tracknum>\d+): (?P<tracktype>[A-Za-z]+)"
- + r"\W+(?P<tracksize>\d+ [MmKkGg]B) (?P<tracktime>\(\d+"
- + r":\d+.\d+\)) (?P<flags>(\w+ *)*)")
+trackmatcher = re.compile(r"Track\s(?P<tracknum>\d+):\s(?P<tracktype>[A-Za-z]+)"
+ + r"\W+(?P<tracksize>\d+\s[MmKkGg]B)\s*(?P<tracktime>\(\d+"
+ + r":\d+\.\d+\))?")
-totalmatcher = re.compile(r"Total size:\W*(?P<totsize>\d+ [MmKkGg]B)"
- + r"(?P<tottime>\(\d+:\d+.\d+\)) = (?P<totsectors>\d+) sectors")
+totalmatcher = re.compile(r"Total size:\s*(?P<totsize>\d+\s[MmKkGg]B)\s+"
+ + r"(?P<tottime>\(\d+:\d+\.\d+\))\s=\s(?P<totsectors>\d+)\ssectors")
+writestartmatcher = re.compile(r"0\sseconds.\sOperation\sstarts.")
+
+trackstartmatcher = re.compile(r"Starting\snew\strack\sat\ssector:\s+"
+ +r"(?P<startsector>\d+)")
+
+trackprogressmatcher = re.compile(r"\rTrack\s(?P<tracknum>\d+):\s+("
+ + r"?P<sofar>\d+)\sof\s+(?P<total>\d+)\s"
+ + r"(?P<unit>[MmKkGg]B)\swritten"
+ + r"(\s\(fifo\s+(?P<fifofill>\d+)+%\)\s+)?"
+ + r"(\[buf\s+(?P<buffill>\d+)%\]\s+)?"
+ + r"((?P<speed>\d+\.\d+)x)?")
+
+trackdonematcher = re.compile(r"Track\s(?P<tracknum>\d+):\sTotal\sbytes"
+ + r"\sread/written:\s(?P<bytesread>\d+)/"
+ + r"(?P<byteswritten>\d+)\s\((?P<sectors>\d+)\s"
+ + r"sectors\)\.")
+
carriagereturn = chr(13)
-class WodimParser():
- def _get_track_data(self, wodim_process):
- trackinfo = []
+class WodimWrapper():
+ def _get_track_data(self):
+ trackinfo = {}
totalline = ""
while True:
- whichmatch = wodim_process.expect([trackmatcher, totalmatcher])
+ whichmatch = self.wodim_process.expect([trackmatcher, totalmatcher])
+ matchdata = self.wodim_process.match.groupdict()
if whichmatch == 1:
#Total info line
- totalline = wodim_process.match
+ totalline = matchdata
break
else:
#Track info line
- trackinfo.append(wodim_process.match.groupdict())
+ trackinfo[matchdata["tracknum"]] = matchdata
return (trackinfo, totalline)
+
+ def _wait_until_write_start(self):
+ match = self.wodim_process.expect(writestartmatcher)
+
+ def _do_track(self):
+ self.wodim_process.expect(trackstartmatcher)
+ match = self.wodim_process.match.groupdict()
+
+ startsector = int(match['startsector'])
- def __init__(self, args, output_cb, command_path="wodim"):
- wodim_command = command_path + " "
+ self.trackstart_cb(startsector)
+
+ while True:
+ linetype = self.wodim_process.expect([trackprogressmatcher,
+ trackdonematcher])
+
+ match = self.wodim_process.match.groupdict()
+
+ if linetype == 0:
+ self.trackprogress_cb(match)
+ elif linetype == 1:
+ self.trackdone_cb(match)
+ break
+
+ def __init__(self, args, trackstart_cb, trackprogress_cb,
+ trackdone_cb, command_path="wodim"):
+ '''WodimWrapper is a class to burn CDs with Wodim'''
+
+ self.trackstart_cb = trackstart_cb
+ self.trackprogress_cb = trackprogress_cb
+ self.trackdone_cb = trackdone_cb
+
+ wodim_command = command_path + " -v " #Some info is only shown with -v
wodim_command += " ".join(args)
- wodim_process = pexpect.spawn(wodim_command)
+ self.wodim_process = pexpect.spawn(wodim_command)
- trackdata = self._get_track_data(self, wodim_process)
+ trackdata = self._get_track_data()
+ self._wait_until_write_start()
+
+ #self._do_track()
+
+ print trackdata
-
- try:
- while wodim_process.expect() == 0:
- output_cb(wodim_process.before)
- except pexpect.EOF:
- return wodim_process.before
+if __name__ == "__main__":
+ def printer(x): print x
+ ww = WodimWrapper([], printer, printer, printer, command_path="./wodim")