Bugfix release
/mp3togo/main.py
blob:a167abc0046dca23308027b915265a1f6e63e5e3 -> blob:37c60f80e56193ccfe2497131e31cc8aa6e9515c
--- mp3togo/main.py
+++ mp3togo/main.py
@@ -140,8 +140,14 @@ def main(argv):
def execute_sequential(playlist, opts, cooked=None):
"""Run the conversions one at a time"""
- print "mp3togo %s\n" % mp3togo.version
- print "<space> or 'p' to pause, <esc> or 'q' to quit\n"
+ # shouldn't print if verbose is 0:
+ if opts['verbosity']:
+ tryp = conf.try_print
+ else:
+ tryp = lambda x: None
+
+ tryp("mp3togo %s\n\n" % mp3togo.version)
+ tryp("<space> or 'p' to pause, <esc> or 'q' to quit\n\n")
c = ''
start_time = time.time()
good_ones = 0
@@ -150,25 +156,27 @@ def execute_sequential(playlist, opts, c
try:
# Terminal sushi
- fd = sys.stdin.fileno()
- oldterm = termios.tcgetattr(fd)
- newattr = termios.tcgetattr(fd)
- newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
- termios.tcsetattr(fd, termios.TCSANOW, newattr)
-
- oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
- fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
-
+ raw = False
if opts['verbosity']:
- tryp = conf.try_print
- else:
- tryp = lambda x: None
+ try:
+ fd = sys.stdin.fileno()
+ oldterm = termios.tcgetattr(fd)
+ newattr = termios.tcgetattr(fd)
+ newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
+ termios.tcsetattr(fd, termios.TCSANOW, newattr)
+ oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
+ fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
+ raw = True
+ except:
+ fail('Error setting the terminal to raw mode.\nIs this a tty?')
+
+ pl = pool.Pool(opts) # make a new one for every track? Huh?
for name in playlist:
track_start = time.time()
tryp("(%d/%d) %s: \n" % (playlist.cur_file() + 1, len(playlist), name))
trk = track.Track(name, opts, cooked)
- pl = pool.Pool(opts) # make a new one for every track? Huh?
+ #pl = pool.Pool(opts) # make a new one for every track? Huh?
if pl.add_track(trk):
tsk = trk.getfirst()
try:
@@ -229,8 +237,7 @@ def execute_sequential(playlist, opts, c
tryp("Undo: %s\n" % tsk.name)
tsk.undo()
tsk = tsk.prev()
- sys.exit(1)
- pass
+ break
else:
opts.log(1, "Out of space. Exiting.")
break
@@ -259,14 +266,15 @@ def execute_sequential(playlist, opts, c
bad_str = ", %d tracks failed." % bad_ones
else:
bad_str = "."
- #bytes = format_bytes(pl.produced_bytes) # you are using a new pool each time!
- tryp("\n%d tracks done%s %s total time elapsed.\n" %
- (good_ones, bad_str, ts))
+ bytes = format_bytes(pl.produced_bytes)
+ tryp("\n%s written for %d tracks%s %s total time elapsed.\n" %
+ (bytes, good_ones, bad_str, ts))
finally:
# Fry some fish:
- termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
- fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
+ if raw:
+ termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
+ fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
def format_time(tm):
@@ -286,14 +294,12 @@ def format_bytes(bytes):
k = 1024.0
m = 1024 * k
g = 1024 * m
- if 0 < bytes < k:
- ret = str(int(bytes/k)) + " KB"
- elif k <= bytes < m:
- ret = str(int(bytes/k)) + " KB"
- elif m <= bytes < g:
- ret = str(int(bytes/m)) + " MB"
+ if k <= bytes < m:
+ return "%.2f KB" % (bytes/k)
+ elif m <= bytes: # < g:
+ return "%.2f MB" % (bytes/m)
else:
- ret = str(bytes) + " Bytes"
+ return str(bytes) + " Bytes"
if __name__ == "__main__": main(sys.argv)