-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store ToC file generated by cdrdao #277
Conversation
What does 'FR' mean? |
whipper/common/program.py
Outdated
@@ -614,3 +617,12 @@ def writeLog(self, discName, logger): | |||
self.logPath = logPath | |||
|
|||
return logPath | |||
|
|||
def writeToc(self, discName): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stumbled for a moment on the name of this-- what's actually happening is we're moving a previous created tocfile to the output directory, so maybe we should make the method name (and docstring if necessary) reflect this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this too: decided to use this name/style to mimic the existing code style. It's true in this case it's a bit deceptive: I'll amend this (+ add a docstring). What would be a good name for the method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this?
def move_tocfile(self, discName):
"""Move cdrdao's tocfile to the discname path (.toc ending)"""
whipper/common/program.py
Outdated
|
||
def writeToc(self, discName): | ||
tocPath = '%s.toc' % discName | ||
logger.debug('write .toc file to %s', tocPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the present active: "writing .toc file to %s"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there's a similar logger.debug
statement in whipper/command/cd.py
maybe I should drop one of them? (written it like this to mimic the existing code style).
whipper/command/offset.py
Outdated
@@ -85,7 +85,7 @@ def do(self): | |||
utils.unmount_device(device) | |||
|
|||
# first get the Table Of Contents of the CD | |||
t = cdrdao.ReadTOCTask(device) | |||
t = cdrdao.ReadTOCTask(device)[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we keep the "return a tuple" behaviour for ReadTOCTask (which is a little awkward but it's not a big deal), we should write this as t, _ = cdrdao.ReadTOCTask(device)
, which is a little less opaque than [0]
in my opinion. Maybe a comment explaining the tocfile is unused (e.g., ...Task(device) # tocfile unused
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I'll improve this as suggested.
P.S. What would be a better way to avoid the awkward return of a tuple?
Thanks for the pull request review. |
whipper/common/program.py
Outdated
@@ -614,3 +617,13 @@ def writeLog(self, discName, logger): | |||
self.logPath = logPath | |||
|
|||
return logPath | |||
|
|||
def move_tocfile(self, discName): | |||
"""Move cdrdao's tocfile to the discname path (.toc ending)""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a little more clear. Maybe "to the output directory ('DISCNAME.toc')", "... ('[discname].toc')", etc.
whipper/program/cdrdao.py
Outdated
@@ -43,8 +43,7 @@ def read_toc(device, fast_toc=False): | |||
|
|||
toc = TocFile(tocfile) | |||
toc.parse() | |||
os.unlink(tocfile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that when the tocfile is unused (like for whipper offset
), we have a /tmp
-file that isn't cleaned up?
whipper/common/program.py
Outdated
@@ -614,3 +618,11 @@ def writeLog(self, discName, logger): | |||
self.logPath = logPath | |||
|
|||
return logPath | |||
|
|||
def move_tocfile(self, discName): | |||
"""Move cdrdao's tocfile to the output dir. ('[discName].toc')""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nitpick, but now I think "Move cdrdao's tocfile to output-dir/discName.toc
" would read the best.
whipper/common/program.py
Outdated
|
||
def move_tocfile(self, discName): | ||
"""Move cdrdao's tocfile to the output dir. ('[discName].toc')""" | ||
tocPath = '%s.toc' % discName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These variable names are confusing. Maybe something like result_toc_path
to differentiate the new path from the temporary path.
Honestly I think we might be doing this backwards. Maybe it's best to move the toc from /tmp to the result directory in the read_toc()
function itself if persist_tocfile
is True
and just return toc
in read_toc()
like before. I think it would keep things simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
Let's say I've done this:
diff --git a/whipper/program/cdrdao.py b/whipper/program/cdrdao.py
index e0da15c..778fb7a 100644
--- a/whipper/program/cdrdao.py
+++ b/whipper/program/cdrdao.py
@@ -1,5 +1,6 @@
import os
import re
+import shutil
import tempfile
from subprocess import Popen, PIPE
@@ -12,7 +13,7 @@ logger = logging.getLogger(__name__)
CDRDAO = 'cdrdao'
-def read_toc(device, fast_toc=False):
+def read_toc(device, fast_toc=False, toc_path=None):
"""
Return cdrdao-generated table of contents for 'device'.
"""
@@ -43,7 +44,10 @@ def read_toc(device, fast_toc=False):
toc = TocFile(tocfile)
toc.parse()
- os.unlink(tocfile)
+ if toc_path is not None:
+ shutil.move(tocfile, toc_path)
+ else:
+ os.unlink(tocfile)
return toc
@@ -83,14 +87,14 @@ def ReadTOCTask(device):
"""
stopgap morituri-insanity compatibility layer
"""
- return read_toc(device, fast_toc=True)
+ return read_toc(device, fast_toc=True, toc_path=None)
def ReadTableTask(device):
"""
stopgap morituri-insanity compatibility layer
"""
- return read_toc(device)
+ return read_toc(device, toc_path=None)
def getCDRDAOVersion():
Who gives me the proper toc_path
? (unfortunately it seems that one isn't available both in getFastToc()
and in getTable()
methods).
P.S. I'm quite tired right now so I may be missing something obvious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From cd.py, pass the path to the function that ultimately calls read_toc(): something like self.program.getTable(..., output_dir)
and self.program.getFastToc(..., output_dir)
. (This could be kwarg with default =None
if we don't want to always persist the toc.) Then pass output_dir
to read_toc()
.
We will need to make sure that the output directory has been created by the time we persist the toc though, right now that happens after both calls to getFastToc()
and getTable()
. As far as I can tell, we're committed to ripping after getFastToc()
but before getTable()
, so we should have getTable()
be the call that persists the toc.
31aa1cd
to
b87a970
Compare
New solution implemented and tested: seems to be working as expected. RFC: @MerlijnWajer, @RecursiveForest. |
Whipper uses cdrdao during its ripping process. With this commit it will now store cdrdao's generated tocfile in the ripping path. Preserving the tocfile allows users to easily burn ripped discs having a non-compliant cue sheet. Fixes #214.
960618e
to
59ef066
Compare
Fixes #214.
This FR isn't implemented as an option because I think always having the original toc file could be useful for debugging purposes, burning a copy of the source CD and it's a tiny file anyway...