aboutsummaryrefslogtreecommitdiffstats
path: root/lvc/conversion.py
diff options
context:
space:
mode:
Diffstat (limited to 'lvc/conversion.py')
-rw-r--r--lvc/conversion.py35
1 files changed, 20 insertions, 15 deletions
diff --git a/lvc/conversion.py b/lvc/conversion.py
index 6d6f693..d634fe5 100644
--- a/lvc/conversion.py
+++ b/lvc/conversion.py
@@ -14,6 +14,7 @@ from lvc.widgets import get_conversion_directory
logger = logging.getLogger(__name__)
+
class Conversion(object):
def __init__(self, video, converter, manager, output_dir=None):
self.video = video
@@ -68,7 +69,7 @@ class Conversion(object):
try:
self.temp_output = tempfile.mktemp(
dir=os.path.dirname(self.output))
- except EnvironmentError,e :
+ except EnvironmentError as e:
logger.exception('while creating temp file for %r',
self.output)
self.error = str(e)
@@ -101,7 +102,7 @@ class Conversion(object):
# then we will transition the next state to 'failed' in
# finalize()
self.status = 'canceled'
- except EnvironmentError, e:
+ except EnvironmentError as e:
logger.exception('while stopping %s' % (self,))
self.error = str(e)
self.popen = None
@@ -116,14 +117,14 @@ class Conversion(object):
# if we stop the thread, we can get here after `.stop()`
# finishes.
self.popen.wait()
- except OSError, e:
+ except OSError as e:
if e.errno == errno.ENOENT:
self.error = '%r does not exist' % (
self.converter.get_executable(),)
else:
logger.exception('OSError in %s' % (self.thread.name,))
self.error = str(e)
- except Exception, e:
+ except Exception as e:
logger.exception('in %s' % (self.thread.name,))
self.error = str(e)
@@ -140,22 +141,22 @@ class Conversion(object):
def _write_thumbnail_file(self):
if self.video.audio_only:
logging.warning("write_thumbnail_file: audio_only=True "
- "not writing thumbnail %s", self.video.filename)
+ "not writing thumbnail %s", self.video.filename)
return
output_basename = os.path.splitext(os.path.basename(self.output))[0]
logging.info("td: %s ob: %s", self._get_thumbnail_dir(),
- output_basename)
+ output_basename)
thumbnail_path = os.path.join(self._get_thumbnail_dir(),
- output_basename + '.png')
+ output_basename + '.png')
logging.info("creating thumbnail: %s", thumbnail_path)
width, height = self.converter.get_target_size(self.video)
get_thumbnail_synchronous(self.video.filename, width, height,
- thumbnail_path)
+ thumbnail_path)
if os.path.exists(thumbnail_path):
logging.info("thumbnail successful: %s", thumbnail_path)
else:
logging.warning("get_thumbnail_synchronous() succeeded, but the "
- "thumbnail file is missing!")
+ "thumbnail file is missing!")
def _get_thumbnail_dir(self):
"""Get the directory to store thumbnails in it.
@@ -186,7 +187,7 @@ class Conversion(object):
# because iterating over the file object gives us all the lines when
# the process ends, and we're looking for real-time updates.
for line in line_reader(self.popen.stdout):
- self.lines.append(line) # for debugging, if needed
+ self.lines.append(line) # for debugging, if needed
try:
status = self.converter.process_status_line(self.video, line)
except StandardError:
@@ -234,9 +235,9 @@ class Conversion(object):
self.notify_listeners()
try:
self.converter.finalize(self.temp_output, self.output)
- except EnvironmentError, e:
+ except EnvironmentError as e:
logger.exception('while trying to move %r to %r after %s',
- self.temp_output, self.output, self)
+ self.temp_output, self.output, self)
self.error = str(e)
self.status = 'failed'
else:
@@ -246,8 +247,11 @@ class Conversion(object):
try:
os.unlink(self.temp_output)
except EnvironmentError:
- pass # ignore errors removing temp files; they may not have
- # been created
+ pass
+ '''
+ ignore errors removing temp files;
+ they may not have been created
+ '''
if self.status != 'canceled':
self.status = 'failed'
if self.status != 'canceled':
@@ -258,6 +262,7 @@ class Conversion(object):
return ([self.converter.get_executable()] +
list(self.converter.get_arguments(self.video, output)))
+
class ConversionManager(object):
def __init__(self, simultaneous=None):
self.notify_queue = set()
@@ -278,7 +283,7 @@ class ConversionManager(object):
def run_conversion(self, conversion):
if (self.simultaneous is not None and
- len(self.in_progress) >= self.simultaneous):
+ len(self.in_progress) >= self.simultaneous):
self.waiting.append(conversion)
else:
self._start_conversion(conversion)