projects
/
living-lab-site.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cis notified web server of a job completion; upload form interface and validation...
[living-lab-site.git]
/
cis
/
api
/
base.py
diff --git
a/cis/api/base.py
b/cis/api/base.py
index
a2e11d1
..
b4e18a8
100644
(file)
--- a/
cis/api/base.py
+++ b/
cis/api/base.py
@@
-4,11
+4,13
@@
Base classes for the external programs API.
"""
Base classes for the external programs API.
"""
-import
api_exception
s
+import
o
s
import re
import re
-import cis_util
import random
import random
+import cis_exceptions
+import cis_util
+
class BaseTranscoder:
"""
Abstraction of the API class for the transcoder program.
class BaseTranscoder:
"""
Abstraction of the API class for the transcoder program.
@@
-83,10
+85,10
@@
class BaseTranscoder:
if a_codec is None and v_codec is None:
raise ValueError('No audio or video codec specified.')
if a_codec is None and v_codec is None:
raise ValueError('No audio or video codec specified.')
- if a_codec is not None and type(a_codec)
is not str
:
+ if a_codec is not None and type(a_codec)
not in [str, unicode]
:
raise TypeError('Audio codec must be string.')
raise TypeError('Audio codec must be string.')
- if v_codec is not None and type(v_codec)
is not str
:
+ if v_codec is not None and type(v_codec)
not in [str, unicode]
:
raise TypeError('Video codec must be string.')
if a_samplingrate is not None and type(a_samplingrate) is not int:
raise TypeError('Video codec must be string.')
if a_samplingrate is not None and type(a_samplingrate) is not int:
@@
-106,7
+108,11
@@
class BaseTranscoder:
and re.match('[\d]+:[\d]+', v_dar) is None):
raise ValueError('Video display aspect ratio must be a float or a string like <den>:<num>.')
and re.match('[\d]+:[\d]+', v_dar) is None):
raise ValueError('Video display aspect ratio must be a float or a string like <den>:<num>.')
- self.output_file = self.dest_path + self.name
+ self.output_file = os.path.join(self.dest_path, self.name)
+ if os.path.exists(self.output_file):
+ raise cis_exceptions.FileAlreadyExistsException( \
+ 'file "%s" already exists' % self.output_file)
+
if v_resolution is not None:
self.output_file += '_'
self.output_file += v_resolution[(v_resolution.rindex('x')+1):]
if v_resolution is not None:
self.output_file += '_'
self.output_file += v_resolution[(v_resolution.rindex('x')+1):]
@@
-135,7
+141,8
@@
class BaseTranscoder:
""" Translates container API name into external program identifier."""
if not self.containers.has_key(name) or self.containers[name] is None:
""" Translates container API name into external program identifier."""
if not self.containers.has_key(name) or self.containers[name] is None:
- raise api_exceptions.NotImplementedException("Container " + name)
+ raise cis_exceptions.NotImplementedException("Container " + name \
+ + "not implemented")
return self.containers[name]
return self.containers[name]
@@
-156,7
+163,8
@@
class BaseTranscoder:
""" Translates audio codec API name into external program identifier."""
if not self.a_codecs.has_key(name) or self.a_codecs[name] is None:
""" Translates audio codec API name into external program identifier."""
if not self.a_codecs.has_key(name) or self.a_codecs[name] is None:
- raise api_exceptions.NotImplementedException("Audio Codec " + name)
+ raise cis_exceptions.NotImplementedException("Audio Codec " + name \
+ + "not implemented")
return self.a_codecs[name]
return self.a_codecs[name]
@@
-164,7
+172,8
@@
class BaseTranscoder:
""" Translates video codec API name into external program identifier."""
if not self.v_codecs.has_key(name) or self.v_codecs[name] is None:
""" Translates video codec API name into external program identifier."""
if not self.v_codecs.has_key(name) or self.v_codecs[name] is None:
- raise api_exceptions.NotImplementedException("Video Codec " + name)
+ raise cis_exceptions.NotImplementedException("Video Codec " + name \
+ + "not implemented")
return self.v_codecs[name]
return self.v_codecs[name]
@@
-226,7
+235,7
@@
class BaseThumbExtractor:
thumb_extracted = True
try:
self.extract_thumb(seek_pos, resolution, n_thumbs_extracted)
thumb_extracted = True
try:
self.extract_thumb(seek_pos, resolution, n_thumbs_extracted)
- except
api
_exceptions.ThumbExtractionException as e:
+ except
cis
_exceptions.ThumbExtractionException as e:
thumb_extracted = False
if thumb_extracted:
thumb_extracted = False
if thumb_extracted:
@@
-238,8
+247,13
@@
class BaseThumbExtractor:
def get_output_file_name(self, index):
""" Returns the name required as output file name based on index. """
def get_output_file_name(self, index):
""" Returns the name required as output file name based on index. """
- output_file_name =
self.dest_path + self.name
\
+ output_file_name =
os.path.join(self.dest_path, self.name)
\
+ '_t' + ("%02d" % index) + '.jpg'
+ '_t' + ("%02d" % index) + '.jpg'
+
+ if os.path.exists(output_file_name):
+ raise cis_exceptions.FileAlreadyExistsException( \
+ 'file "%s" already exists' % output_file_name)
+
return output_file_name
def get_video_duration(self):
return output_file_name
def get_video_duration(self):