diff options
author | olpc user <natetheis@gmail.com> | 2010-11-28 23:13:39 (GMT) |
---|---|---|
committer | olpc user <natetheis@gmail.com> | 2010-11-28 23:13:39 (GMT) |
commit | d51a92bd1624d661a486af03f5c8b7d36298a1c5 (patch) | |
tree | c957283e9a1ab417851a4d9bb75de1ec3f51c16f | |
parent | 25d90d84aad122ad4d9b3bd5cc5cae952647838b (diff) |
Added initial parser regexes
-rw-r--r-- | ToasterActivity.py | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/ToasterActivity.py b/ToasterActivity.py index e6d37d8..2998fcc 100644 --- a/ToasterActivity.py +++ b/ToasterActivity.py @@ -24,7 +24,7 @@ pygtk.require('2.0') import gtk import os.path -import pexpect +import pexpect, re import sugar from sugar.activity import activity @@ -259,14 +259,27 @@ class ToasterActivity(activity.Activity): vt = self.notebook.get_nth_page(self.notebook.get_current_page()).vt vt.paste_clipboard() -class WodimParser(): - def __init__(self, args): - wodim_command = "wget " +class WodimWrapper(): + def __init__(self, args, output_cb, command_path="wodim"): + wodim_command = command_path + " " for arg in args: - wodim_command += arg + wodim_command += (arg + " ") wodim_handle = pexpect.spawn(wodim_command) - while wodim_handle.expect(chr(13)) == 0: - print wodim_handle.before - print wodim_handle.before + + trackmatcher = 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 = (r"Total size:\W*(?P<totsize>\d+ [MmKkGg]B)" + + r"(?P<tottime>\(\d+:\d+.\d+\)) = (?P<totsectors>\d+) sectors") + + while True: + wodim_handle.expect(trackmatcher, ) + print wodim_handle.match.groupdict() + try: + while wodim_handle.expect(chr(13)) == 0: + output_cb(wodim_handle.before) + except pexpect.EOF: + return wodim_handle.before |