Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/wodim_tools.py
blob: 16c9f048355b408cf62d959fc5b3306d6ace7a55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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