From 1a91792f4136b7c53af64b38a7b3d69ecaade576 Mon Sep 17 00:00:00 2001 From: Nate Theis Date: Mon, 29 Nov 2010 05:54:58 +0000 Subject: Worked on parser, separated into own module --- diff --git a/ToasterActivity.py b/ToasterActivity.py index 7f84401..485918f 100644 --- a/ToasterActivity.py +++ b/ToasterActivity.py @@ -24,7 +24,7 @@ pygtk.require('2.0') import gtk import os.path -import pexpect, re + import sugar from sugar.activity import activity @@ -259,37 +259,5 @@ 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, output_cb, command_path="wodim"): - wodim_command = command_path + " " - for arg in args: - wodim_command += (arg + " ") - - wodim_handle = pexpect.spawn(wodim_command) - - trackmatcher = (r"Track (?P\d+): (?P[A-Za-z]+)" - + r"\W+(?P\d+ [MmKkGg]B) (?P\(\d+" - + r":\d+.\d+\)) (?P(\w+ *)*)") - totalmatcher = (r"Total size:\W*(?P\d+ [MmKkGg]B)" - + r"(?P\(\d+:\d+.\d+\)) = (?P\d+) sectors") - - trackinfo = [] - totalline = "" - - while True: - whichmatch = wodim_handle.expect([trackmatcher, totalmatcher]) - if whichmatch == 1: - #Total info line - totalline = wodim_handle.match - break - else: - #Track info line - trackinfo.append(wodim_handle.match.groupdict()) - - try: - while wodim_handle.expect(chr(13)) == 0: - output_cb(wodim_handle.before) - except pexpect.EOF: - return wodim_handle.before diff --git a/testsession b/testsession deleted file mode 100644 index a2155a2..0000000 --- a/testsession +++ /dev/null @@ -1,62 +0,0 @@ -TOC Type: 0 = CD-DA -Device type : Removable CD-ROM -Version : 5 -Response Format: 2 -Capabilities : -Vendor_info : 'Optiarc ' -Identification : 'DVD RW AD-5170A ' -Revision : '1.11' -Device seems to be: Generic mmc2 DVD-R/DVD-RW. -Current: 0x0009 (CD-R) -Profile: 0x002B (DVD+R/DL) -Profile: 0x001B (DVD+R) -Profile: 0x001A (DVD+RW) -Profile: 0x0016 (DVD-R/DL layer jump recording) -Profile: 0x0015 (DVD-R/DL sequential recording) -Profile: 0x0014 (DVD-RW sequential recording) -Profile: 0x0013 (DVD-RW restricted overwrite) -Profile: 0x0011 (DVD-R sequential recording) -Profile: 0x0010 (DVD-ROM) -Profile: 0x000A (CD-RW) -Profile: 0x0009 (CD-R) (current) -Profile: 0x0008 (CD-ROM) (current) -Using generic SCSI-3/mmc CD-R/CD-RW driver (mmc_cdr). -Driver flags : MMC-3 SWABAUDIO BURNFREE -Supported modes: TAO PACKET SAO SAO/R96R RAW/R96R -Drive buf size : 890880 = 870 KB -FIFO size : 16777216 = 16384 KB -Track 01: audio 46 MB (04:34.54) no preemp pad copy -Track 02: audio 73 MB (07:17.60) no preemp pad copy -Track 03: audio 44 MB (04:26.89) no preemp pad copy -Track 04: audio 85 MB (08:26.82) no preemp pad copy -Track 05: audio 64 MB (06:20.60) no preemp pad copy -Track 06: audio 44 MB (04:22.40) no preemp copy -Track 07: audio 63 MB (06:16.24) no preemp pad copy -Total size: 421 MB (41:45.17) = 187888 sectors -Lout start: 421 MB (41:47/13) = 187888 sectors -Current Secsize: 2048 -ATIP info from disk: - Indicated writing power: 5 - Is not unrestricted - Is not erasable - Disk sub type: Medium Type B, low Beta category (B-) (4) - ATIP start of lead in: -11933 (97:22/67) - ATIP start of lead out: 359849 (79:59/74) -Disk type: Short strategy type (Phthalocyanine or similar) -Manuf. index: 43 -Manufacturer: Acer Media Technology, Inc. -Blocks total: 359849 Blocks current: 359849 Blocks remaining: 171961 -Starting to write CD/DVD at speed 48.0 in real SAO mode for single session. -Last chance to quit, starting real write i 0 seconds. Operation starts. -Waiting for reader process to fill input buffer ... input buffer ready. -Performing OPC... -Sending CUE sheet... -Writing pregap for track 1 at -150 -Starting new track at sector: 0 -Track 01: 0 of 46 MB written. -write track data: error after 63504 bytes -Writing time: 22.112s -Average write speed 493.5x. -Fixating... -Trouble flushing the cache -Fixating time: 8.817s diff --git a/wodim b/wodim index 09fbb4e..4708bcd 100755 --- a/wodim +++ b/wodim @@ -1,2 +1,2 @@ -#!/usr/bin/python -print open("testsession").read() +#!/bin/bash +cat typescript 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\d+): (?P[A-Za-z]+)" + + r"\W+(?P\d+ [MmKkGg]B) (?P\(\d+" + + r":\d+.\d+\)) (?P(\w+ *)*)") + +totalmatcher = re.compile(r"Total size:\W*(?P\d+ [MmKkGg]B)" + + r"(?P\(\d+:\d+.\d+\)) = (?P\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 -- cgit v0.9.1