source: trunk/morituri/result/logger.py @ 582

Revision 582, 4.2 KB checked in by thomas, 11 months ago (diff)
  • morituri/result/logger.py: Fix logging of AR data
Line 
1# -*- Mode: Python; test-case-name: morituri.test.test_result_logger -*-
2# vi:si:et:sw=4:sts=4:ts=4
3
4# Morituri - for those about to RIP
5
6# Copyright (C) 2009 Thomas Vander Stichele
7
8# This file is part of morituri.
9#
10# morituri is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# morituri is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with morituri.  If not, see <http://www.gnu.org/licenses/>.
22
23import time
24
25from morituri.common import common
26from morituri.configure import configure
27
28class MorituriLogger(object):
29
30    def log(self, ripResult, epoch=time.time()):
31        lines = self.logRip(ripResult, epoch=epoch)
32        return '\n'.join(lines)
33
34
35    def logRip(self, ripResult, epoch):
36
37        lines = []
38
39        ### global
40
41        lines.append("Logfile created by: morituri %s" % configure.version)
42        # FIXME: when we localize this, see #49 to handle unicode properly.
43        import locale
44        old = locale.getlocale(locale.LC_TIME)
45        locale.setlocale(locale.LC_TIME, 'C')
46        date = time.strftime("%b %d %H:%M:%S", time.localtime(epoch))
47        locale.setlocale(locale.LC_TIME, old)
48        lines.append("Logfile created on: %s" % date)
49        lines.append("")
50
51        # album
52        lines.append("Album: %s - %s" % (ripResult.artist, ripResult.title))
53        lines.append("")
54
55        # drive
56        lines.append(
57            "Drive: vendor %s, model %s" % (
58                ripResult.vendor, ripResult.model))
59        lines.append("")
60
61        lines.append("Read offset correction: %d" %
62            ripResult.offset)
63        lines.append("")
64
65        # toc
66        lines.append("Table of Contents:")
67        lines.append("")
68        lines.append(
69            "     Track |   Start           |  Length")
70        lines.append(
71            "     ------------------------------------------------")
72        table = ripResult.table
73
74
75        for t in table.tracks:
76            start = t.getIndex(1).absolute
77            length = table.getTrackLength(t.number)
78            lines.append(
79            "       %2d  | %6d - %s | %6d - %s" % (
80                t.number, 
81                start, common.framesToMSF(start),
82                length, common.framesToMSF(length)))
83
84        lines.append("")
85        lines.append("")
86
87        ### per-track
88        for t in ripResult.tracks:
89            lines.extend(self.trackLog(t))
90            lines.append('')
91
92        return lines
93
94    def trackLog(self, trackResult):
95
96        lines = []
97
98        lines.append('Track %2d' % trackResult.number)
99        lines.append('')
100        lines.append('  Filename %s' % trackResult.filename)
101        lines.append('')
102        if trackResult.pregap:
103            lines.append('  Pre-gap: %s' % common.framesToMSF(
104                trackResult.pregap))
105            lines.append('')
106
107        lines.append('  Peak level %.1f %%' % (trackResult.peak * 100.0))
108        if trackResult.copycrc is not None:
109            lines.append('  Copy CRC %08X' % trackResult.copycrc)
110        if trackResult.testcrc is not None:
111            lines.append('  Test CRC %08X' % trackResult.testcrc)
112            if trackResult.testcrc == trackResult.copycrc:
113                lines.append('  Copy OK')
114            else:
115                lines.append("  WARNING: CRCs don't match!")
116        else:
117            lines.append("  WARNING: no CRC check done")
118       
119        if trackResult.accurip:
120            lines.append('  Accurately ripped (confidence %d) [%08X]' % (
121                trackResult.ARDBConfidence, trackResult.ARCRC))
122        else:
123            if trackResult.ARDBCRC:
124                lines.append('  Cannot be verified as accurate '
125                    '[%08X], AccurateRip returned [%08X]' % (
126                        trackResult.ARCRC, trackResult.ARDBCRC))
127            else:
128                lines.append('  Track not present in AccurateRip database')
129
130        return lines
Note: See TracBrowser for help on using the repository browser.