Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/wodim_tools.py
diff options
context:
space:
mode:
Diffstat (limited to 'wodim_tools.py')
-rw-r--r--wodim_tools.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/wodim_tools.py b/wodim_tools.py
new file mode 100644
index 0000000..16c9f04
--- /dev/null
+++ b/wodim_tools.py
@@ -0,0 +1,49 @@
+# Copyright (c) 2010, Nathaniel Theis
+
+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+ *)*)")
+
+totalmatcher = re.compile(r"Total size:\W*(?P<totsize>\d+ [MmKkGg]B)"
+ + r"(?P<tottime>\(\d+:\d+.\d+\)) = (?P<totsectors>\d+) sectors")
+
+carriagereturn = chr(13)
+
+
+
+class WodimParser():
+ def _get_track_data(self, wodim_process):
+ trackinfo = []
+ totalline = ""
+
+ while True:
+ whichmatch = wodim_process.expect([trackmatcher, totalmatcher])
+ if whichmatch == 1:
+ #Total info line
+ totalline = wodim_process.match
+ break
+ else:
+ #Track info line
+ trackinfo.append(wodim_process.match.groupdict())
+
+ return (trackinfo, totalline)
+
+ def __init__(self, args, output_cb, command_path="wodim"):
+ wodim_command = command_path + " "
+ wodim_command += " ".join(args)
+
+ wodim_process = pexpect.spawn(wodim_command)
+
+ trackdata = self._get_track_data(self, wodim_process)
+
+
+
+ try:
+ while wodim_process.expect() == 0:
+ output_cb(wodim_process.before)
+ except pexpect.EOF:
+ return wodim_process.before