Unverified Commit bb447aaa by Gregory Martin Committed by GitHub

Merge pull request #29 from edx/yro/ElimPrintStatements

Improve logging, delete stray print statements
parents 7ff39492 6fb83d6b
...@@ -8,10 +8,10 @@ AbstractionLayer Object (acts as master abstraction) ...@@ -8,10 +8,10 @@ AbstractionLayer Object (acts as master abstraction)
""" """
import json import json
import os import logging
import requests import requests
from reporting import ErrorObject, Output from reporting import Output
import generate_apitoken import generate_apitoken
from video_worker.utils import get_config from video_worker.utils import get_config
from global_vars import * from global_vars import *
...@@ -23,6 +23,8 @@ requests.packages.urllib3.disable_warnings() ...@@ -23,6 +23,8 @@ requests.packages.urllib3.disable_warnings()
settings = get_config() settings = get_config()
logger = logging.getLogger(__name__)
class Video(object): class Video(object):
""" """
...@@ -51,20 +53,17 @@ class Video(object): ...@@ -51,20 +53,17 @@ class Video(object):
test case test case
""" """
if self.veda_id is not None and len(settings['veda_api_url']) == 0: if self.veda_id is not None and len(settings['veda_api_url']) == 0:
ErrorObject().print_error( logger.error('[ENCODE_WORKER] VEDA API Config Incorrect')
message='VEDA API Config Incorrect, run test to debug' return
)
return None
if self.veda_id is None and self.mezz_filepath is None: if self.veda_id is None and self.mezz_filepath is None:
print self.mezz_filepath
self.mezz_extension = '.mp4' self.mezz_extension = '.mp4'
self.mezz_title = TEST_VIDEO_FILE self.mezz_title = TEST_VIDEO_FILE
self.mezz_filepath = os.path.join(TEST_VIDEO_DIR, TEST_VIDEO_FILE) self.mezz_filepath = os.path.join(TEST_VIDEO_DIR, TEST_VIDEO_FILE)
self.valid = True self.valid = True
return None return
if self.veda_id is not None:
if self.veda_id:
""" """
Generated Token Generated Token
""" """
...@@ -160,10 +159,13 @@ class Encode(object): ...@@ -160,10 +159,13 @@ class Encode(object):
veda_token = generate_apitoken.veda_tokengen() veda_token = generate_apitoken.veda_tokengen()
if veda_token is None: if veda_token is None:
ErrorObject().print_error( logger.error(
message="VEDA Token Generate" '[ENCODE_WORKER] : {id} {encode} VEDA Token Generate'.format(
id=self.VideoObject.veda_id,
encode=self.profile_name
) )
return None )
return
data = {'product_spec': self.profile_name} data = {'product_spec': self.profile_name}
...@@ -183,10 +185,13 @@ class Encode(object): ...@@ -183,10 +185,13 @@ class Encode(object):
enc_dict = json.loads(x.text) enc_dict = json.loads(x.text)
if len(enc_dict['results']) == 0: if len(enc_dict['results']) == 0:
ErrorObject().print_error( logger.error(
message="VEDA API Encode Mismatch: No Data" '[ENCODE_WORKER] : {id} {encode} VEDA API Encode Mismatch: No Data'.format(
id=self.VideoObject.veda_id,
encode=self.profile_name
)
) )
return None return
for e in enc_dict['results']: for e in enc_dict['results']:
if e['product_spec'] == self.profile_name and e['profile_active'] is True: if e['product_spec'] == self.profile_name and e['profile_active'] is True:
...@@ -223,10 +228,3 @@ class Encode(object): ...@@ -223,10 +228,3 @@ class Encode(object):
with open(self.encode_library) as data_file: with open(self.encode_library) as data_file:
data = json.load(data_file) data = json.load(data_file)
return data["ENCODE_PROFILES"] return data["ENCODE_PROFILES"]
def main():
pass
if __name__ == '__main__':
sys.exit(main())
...@@ -94,11 +94,6 @@ def queue_transcode(vid_name, encode_command): ...@@ -94,11 +94,6 @@ def queue_transcode(vid_name, encode_command):
pass pass
@app.task
def test_command(message):
print message
if __name__ == '__main__': if __name__ == '__main__':
app = cel_start() app = cel_start()
app.start() app.start()
...@@ -6,22 +6,22 @@ from VEDA_WORK_DIR, retrieves and checks URL, and passes info to objects ...@@ -6,22 +6,22 @@ from VEDA_WORK_DIR, retrieves and checks URL, and passes info to objects
import boto import boto
import boto.s3 import boto.s3
from boto.exception import S3ResponseError
from boto.s3.key import Key from boto.s3.key import Key
import hashlib import hashlib
import logging
import os import os
import sys import sys
import shutil import shutil
from global_vars import MULTI_UPLOAD_BARRIER, ENCODE_WORK_DIR from global_vars import MULTI_UPLOAD_BARRIER, ENCODE_WORK_DIR
from reporting import ErrorObject
from video_worker.utils import get_config from video_worker.utils import get_config
settings = get_config() settings = get_config()
logger = logging.getLogger(__name__)
class Deliverable(): class Deliverable(object):
def __init__(self, VideoObject, encode_profile, output_file, **kwargs): def __init__(self, VideoObject, encode_profile, output_file, **kwargs):
self.VideoObject = VideoObject self.VideoObject = VideoObject
...@@ -138,8 +138,10 @@ class Deliverable(): ...@@ -138,8 +138,10 @@ class Deliverable():
b = conn.lookup(settings['veda_deliverable_bucket']) b = conn.lookup(settings['veda_deliverable_bucket'])
if b is None: if b is None:
ErrorObject().print_error( logger.error(
message='Deliverable Fail: s3 Bucket Connection Error' '[ENCODE_WORKER] : {file} Deliverable Fail: s3 Bucket Connection Error'.format(
file=self.output_file
)
) )
return False return False
......
...@@ -32,21 +32,6 @@ class Credentials(object): ...@@ -32,21 +32,6 @@ class Credentials(object):
return None return None
class ErrorObject(object):
"""
Unspecified errors with a message
"""
@staticmethod
def print_error(message):
decorator = "***************E*R*R*O*R*******************"
outgoing = '\n%s \n\n%s \n\n%s\n' % (
NODE_COLORS_BLUE + decorator + NODE_COLORS_END,
message,
NODE_COLORS_BLUE + decorator + NODE_COLORS_END,
)
print outgoing
class Output(object): class Output(object):
""" """
Various reporting methods Various reporting methods
......
...@@ -15,16 +15,18 @@ FUTURE: ...@@ -15,16 +15,18 @@ FUTURE:
- artifacting? - artifacting?
""" """
import logging
import os import os
import subprocess import subprocess
import sys import sys
from reporting import ErrorObject, Output from reporting import Output
from video_worker.utils import get_config from video_worker.utils import get_config
settings = get_config() settings = get_config()
logger = logging.getLogger(__name__)
class ValidateVideo: class ValidateVideo:
...@@ -41,14 +43,18 @@ class ValidateVideo: ...@@ -41,14 +43,18 @@ class ValidateVideo:
-file exists -file exists
""" """
if not os.path.exists(self.filepath): if not os.path.exists(self.filepath):
ErrorObject().print_error( logger.error(
message='File QA fail: File is not found\n' + self.filepath '[ENCODE_WORKER] : {filepath} File QA fail: File is not found'.format(
filepath=self.filepath
)
) )
return False return False
if os.stat(self.filepath).st_size == 0: if os.stat(self.filepath).st_size == 0:
ErrorObject().print_error( logger.error(
message='File QA fail: Filesize is 0' '[ENCODE_WORKER] : {filepath} File QA fail: Filesize is 0'.format(
filepath=self.filepath
)
) )
return False return False
...@@ -74,29 +80,24 @@ class ValidateVideo: ...@@ -74,29 +80,24 @@ class ValidateVideo:
return False return False
if "multiple edit list entries, a/v desync might occur, patch welcome" in line: if "multiple edit list entries, a/v desync might occur, patch welcome" in line:
print 1
return False return False
if "Duration: " in line: if "Duration: " in line:
"""Get and Test Duration""" """Get and Test Duration"""
if "Duration: 00:00:00.0" in line: if "Duration: 00:00:00.0" in line:
print 2
return False return False
elif "Duration: N/A, " in line: elif "Duration: N/A, " in line:
print 3
return False return False
vid_duration = line.split('Duration: ')[1].split(',')[0].strip() vid_duration = line.split('Duration: ')[1].split(',')[0].strip()
duration = Output.seconds_from_string(duration=vid_duration) duration = Output.seconds_from_string(duration=vid_duration)
if duration < 1.05: if duration < 1.05:
print 'TOO SHORT'
return False return False
try: try:
duration duration
except: except:
print 'NO DUR'
return False return False
""" """
...@@ -105,7 +106,6 @@ class ValidateVideo: ...@@ -105,7 +106,6 @@ class ValidateVideo:
if self.VideoObject is not None and self.product_file is True: if self.VideoObject is not None and self.product_file is True:
# within five seconds # within five seconds
if not (self.VideoObject.mezz_duration - 5) <= duration <= (self.VideoObject.mezz_duration + 5): if not (self.VideoObject.mezz_duration - 5) <= duration <= (self.VideoObject.mezz_duration + 5):
print 6
return False return False
return True return True
...@@ -118,10 +118,12 @@ class ValidateVideo: ...@@ -118,10 +118,12 @@ class ValidateVideo:
-file exists -file exists
""" """
if not os.path.exists(self.filepath): if not os.path.exists(self.filepath):
ErrorObject().print_error( logger.error(
message='File Vars fail: File is not found\n' + self.filepath '[ENCODE_WORKER] : {filepath} File QA fail: Filesize is 0'.format(
filepath=self.filepath
)
) )
return None return
# Filesize # Filesize
return_dict.setdefault('filesize', os.stat(self.filepath).st_size) return_dict.setdefault('filesize', os.stat(self.filepath).st_size)
......
...@@ -16,7 +16,6 @@ from boto.s3.key import Key ...@@ -16,7 +16,6 @@ from boto.s3.key import Key
import generate_apitoken import generate_apitoken
from video_worker.utils import get_config from video_worker.utils import get_config
from video_worker.reporting import ErrorObject
from video_worker.utils import build_url from video_worker.utils import build_url
...@@ -28,7 +27,7 @@ START_PERCENTAGE = 2.0 / 100 ...@@ -28,7 +27,7 @@ START_PERCENTAGE = 2.0 / 100
# skip 10 percent of video duration from end to avoid end credits # skip 10 percent of video duration from end to avoid end credits
END_PERCENTAGE = 10.0 / 100 END_PERCENTAGE = 10.0 / 100
LOGGER = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class VideoImages(object): class VideoImages(object):
...@@ -80,11 +79,12 @@ class VideoImages(object): ...@@ -80,11 +79,12 @@ class VideoImages(object):
""" """
Generate video images using ffmpeg. Generate video images using ffmpeg.
""" """
if self.video_object is None: if not self.video_object:
ErrorObject().print_error( logger.error(
message='Video Images generation failed: No Video Object' '[ENCODE_WORKER] : {id} Video Image generation failed: No Video Object'.format(
)
) )
return None return
generated_images = [] generated_images = []
for position in self.calculate_positions(self.video_object.mezz_duration): for position in self.calculate_positions(self.video_object.mezz_duration):
...@@ -108,8 +108,8 @@ class VideoImages(object): ...@@ -108,8 +108,8 @@ class VideoImages(object):
universal_newlines=True universal_newlines=True
) )
stdoutdata, stderrdata = process.communicate() stdoutdata, stderrdata = process.communicate()
LOGGER.info('executing command >> %s', command) logger.info('executing command >> %s', command)
LOGGER.info('command output >> out=%s -- err=%s', stdoutdata, stderrdata) logger.info('command output >> out=%s -- err=%s', stdoutdata, stderrdata)
return_images = [] return_images = []
for image in generated_images: for image in generated_images:
...@@ -133,10 +133,8 @@ class VideoImages(object): ...@@ -133,10 +133,8 @@ class VideoImages(object):
try: try:
bucket = s3_connection.get_bucket(self.settings['aws_video_images_bucket']) bucket = s3_connection.get_bucket(self.settings['aws_video_images_bucket'])
except S3ResponseError: except S3ResponseError:
ErrorObject().print_error( logger.error('[ENCODE_WORKER] : Invalid Storage Bucket for Video Images')
message='Invalid Storage Bucket for Video Images' return
)
return None
image_keys = [] image_keys = []
for generated_image in generated_images: for generated_image in generated_images:
...@@ -184,4 +182,10 @@ class VideoImages(object): ...@@ -184,4 +182,10 @@ class VideoImages(object):
) )
if not response.ok: if not response.ok:
ErrorObject.print_error(message=response.content) logger.error('[ENCODE_WORKER] : {id} {message}'.format(
id=self.video_object.val_id,
message=response.content
))
if __name__ == '__main__':
vi = VideoImages()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment