* introduce logcommand.Lager, Whipper(); use argparse for whipper image commands, stub logging * update Lager docstring to mention config.Config() * make incorrect subcommand and --version work on toplevel command * migrate accurip show, expand Lager, do not attempt to return from Lager.__init__. * migrate offset find, add Lager.error * correct offset find drive symlink handling * migrate drive * change Lager.__init__(prog) to arg from kwarg * but actually * remove Whipper.usage * add and use Lager.device_option() context manager * help I married an axe murderer * use unified options namespace for entire command tree * migrate whipper cd without comprehensive config loading * switch to logging module - use logging instead of flog for non-extern modules - use WHIPPER_DEBUG and WHIPPER_LOGFILE env variables * convert self.log calls to logger.debug * convert self.error calls to logger.error * remove log.Loggable, use logger not logging * Logging conversion continues - Convert log.* calls to logger.* - Remove morituri.common.log imports * remove morituri.common.log from tests * remove extern/flog, bare minimum Debug conversion * update README for logging changes * update soxi to use logging * refactor Lager for more declarative subcommands * Refactor Lager.device_option: - inline into __init__ - throw IOError instead of Exception for missing drives - remove CommandError checking in rip/main * rename rip to whipper in rip.main * convert rip.debug commands * Rename logcommand.Lager to command.BaseCommand - remove command.CommandError occurrences - remove python-command external module * remove submodules from README, update rclog formatter * update minor ambiguity in readme for command invocation * update version number to match setup.py * remove gitmodules * update version number in tests as well (boo) * convert logger.error to logger.critical * Change morituri.rip to morituri.command - mv common.command to command.basecommand - move TEMPLATES used only by rip.cd out of rip.common - update entry point for command to command.main * update basecommand documentation * go pyflaking: import fixing * replace self.stdout with sys.stdout * remove BaseCommand.config, alphabetise imports * convert self.stdXXX leftovers * convert last getRootCommand to config.Config * convert last getExceptionMessage's to str * change musicbrainz useragent to whipper
53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
from os.path import exists
|
|
from subprocess import Popen, PIPE
|
|
|
|
import logging
|
|
logger = logging.getLogger(__name__)
|
|
|
|
ARB = 'accuraterip-checksum'
|
|
FLAC = 'flac'
|
|
|
|
def accuraterip_checksum(f, track, tracks, wave=False, v2=False):
|
|
v = '--accuraterip-v1'
|
|
if v2:
|
|
v = '--accuraterip-v2'
|
|
|
|
track, tracks = str(track), str(tracks)
|
|
|
|
if not wave:
|
|
flac = Popen([FLAC, '-cds', f], stdout=PIPE)
|
|
|
|
arc = Popen([ARB, v, '/dev/stdin', track, tracks],
|
|
stdin=flac.stdout, stdout=PIPE, stderr=PIPE)
|
|
else:
|
|
arc = Popen([ARB, v, f, track, tracks],
|
|
stdout=PIPE, stderr=PIPE)
|
|
|
|
if not wave:
|
|
flac.stdout.close()
|
|
|
|
out, err = arc.communicate()
|
|
|
|
if not wave:
|
|
flac.wait()
|
|
flac_rc = flac.returncode
|
|
|
|
arc_rc = arc.returncode
|
|
|
|
if not wave and flac_rc != 0:
|
|
logger.warning('ARC calculation failed: flac return code is non zero')
|
|
return None
|
|
|
|
if arc_rc != 0:
|
|
logger.warning('ARC calculation failed: arc return code is non zero')
|
|
return None
|
|
|
|
out = out.strip()
|
|
try:
|
|
outh = int('0x%s' % out, base=16)
|
|
except ValueError:
|
|
logger.warning('ARC output is not usable')
|
|
return None
|
|
|
|
return outh
|