3
3
from datetime import datetime, timedelta
4
4
from boto.services.service import Service
7
get_results.py [-q queuename] [-m mimetype_file] [-n] path
9
queuename - The name of the SQS queue containing status messages.
10
This would be the queuename passed with the -o arg
11
to the start_service.py command
12
mimetype_file - A file containing additional mimetypes to be
13
loaded before processing the results. The file
14
should consist of lines of text where each line
15
represents a new mimetype and file extension
16
separated by whitespace, e.g."
20
path - The location on your local file system where results
22
if -n is specified, the result files will not be retrieved
23
from S3, otherwise the result files will be downloaded to
6
27
class ResultProcessor:
8
30
TimeFormat = '%a, %d %b %Y %H:%M:%S %Z'
9
31
LogFileName = 'log.csv'
11
def __init__(self, queue_name):
33
def __init__(self, queue_name, mimetype_files=None):
12
34
self.queue_name = queue_name
13
35
self.service = Service(output_queue_name=queue_name,
37
mimetype_files=mimetype_files,
38
preserve_file_name=True)
17
41
self.total_time = 0
58
82
if not os.path.isdir(path):
60
m = self.service.get_result(path, original_name=True, get_file=get_file)
84
m = self.service.get_result(path, get_file=get_file)
63
87
self.log_message(m, path)
64
88
self.calculate_stats(m)
65
m = self.service.get_result(path, original_name=True,
89
m = self.service.get_result(path, get_file=get_file)
68
91
self.log_fp.close()
69
92
print '%d results successfully retrieved.' % total_files
78
101
print 'Throughput: %f transactions / minute' % tput
81
print 'get_results.py [-q queuename] [-n] path'
82
print '\tif -n is specified, the result files will not be retrieved'
83
print '\tfrom S3, otherwise the result files will be downloaded to'
84
print '\tthe specified path'
88
opts, args = getopt.getopt(sys.argv[1:], 'hnq:',
89
['help', 'no_retrieve', 'queue'])
108
opts, args = getopt.getopt(sys.argv[1:], 'hm:nq:',
109
['help', 'mimetypes',
110
'no_retrieve', 'queue'])
97
119
if o in ('-h', '--help'):
122
if o in ('-m', '--mimetypes'):
100
124
if o in ('-n', '--no-retrieve'):
102
126
if o in ('-q', '--queue'):
108
132
if len(args) > 1:
110
s = ResultProcessor(queue_name)
134
# mimetypes doesn't know about flv files, let's clue it in
135
mimetypes.add_type('video/x-flv', '.flv')
136
s = ResultProcessor(queue_name, mimetype_file)
111
137
s.get_results(path, get_file)