basic segment counting working

pull/128/head
Christopher Usher 5 years ago
parent 3618510f35
commit 66f5a06a5c

@ -1,6 +1,6 @@
import datatime
import logging import logging
import os import os
import signal
import argh import argh
import gevent.backdoor import gevent.backdoor
@ -15,7 +15,7 @@ class CoverageChecker(object):
CHECK_INTERVAL = 60 #seconds between checking coverage CHECK_INTERVAL = 60 #seconds between checking coverage
def __init__(channel, qualities, base_dir): def __init__(self, channel, qualities, base_dir):
"""Constructor for CoverageChecker. """Constructor for CoverageChecker.
Creates a checker for a given channel with specified qualities.""" Creates a checker for a given channel with specified qualities."""
@ -41,21 +41,21 @@ class CoverageChecker(object):
for quality in self.qualities: for quality in self.qualities:
if self.stopping.is_set(): if self.stopping.is_set():
break break
path = os.path.join(self.basedir, self.channel, quality) path = os.path.join(self.base_dir, self.channel, quality)
hours = [name for name in os.listdir(path) if not name.startswith('.')] hours = [name for name in os.listdir(path) if not name.startswith('.')]
hours.sort() hours.sort()
for hour in hours: for hour in hours:
if self.stopping.is_set(): if self.stopping.is_set():
break break
self.logger.info('Checking {}/{}'.format(quality, hour)) self.logger.info('Checking {}/{}'.format(quality, hour))
path = os.path.join(self.basedir, self.channel, quality, hour) path = os.path.join(self.base_dir, self.channel, quality, hour)
segment_names = [name for name in os.listdir(path) if not name.startswith('.')] segment_names = [name for name in os.listdir(path) if not name.startswith('.')]
segment_names.sort() segment_names.sort()
segments = [] segments = []
for name in segment_names: for name in segment_names:
path = os.path.join(hour, name) path = os.path.join(hour, name)
try: try:
segments.append(parse_segment_path(path)) segments.append(common.parse_segment_path(path))
except ValueError: except ValueError:
self.logger.warning('Skipping segment {} with invalid format'.format(path)) self.logger.warning('Skipping segment {} with invalid format'.format(path))
@ -63,8 +63,8 @@ class CoverageChecker(object):
partial_segments = [segment for segment in segments if segment.type == 'partial'] partial_segments = [segment for segment in segments if segment.type == 'partial']
full_segments_duration = sum([segment.duration.seconds for segment in full_segments]) full_segments_duration = sum([segment.duration.seconds for segment in full_segments])
partial_segments_duration = sum([segment.duration.seconds for segment in partial_segments]) partial_segments_duration = sum([segment.duration.seconds for segment in partial_segments])
self.logger.info('{}/{}: {} full segments totalling {} s'.format(quality, hour, len(full_segments), full_segments_duration) self.logger.info('{}/{}: {} full segments totalling {} s'.format(quality, hour, len(full_segments), full_segments_duration))
self.logger.info('{}/{}: {} partial segments totalling {} s'.format(quality, hour,len(partial_segments), partial_segments_duration) self.logger.info('{}/{}: {} partial segments totalling {} s'.format(quality, hour, len(partial_segments), partial_segments_duration))
self.stopping.wait(common.jitter(self.CHECK_INTERVAL)) self.stopping.wait(common.jitter(self.CHECK_INTERVAL))

Loading…
Cancel
Save