~ubuntu-branches/ubuntu/karmic/python-boto/karmic

« back to all changes in this revision

Viewing changes to boto/services/get_results.py

  • Committer: Bazaar Package Importer
  • Author(s): Eric Evans
  • Date: 2007-11-24 17:12:40 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071124171240-11841t56xlqco4pw
Tags: 0.9d-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
from datetime import datetime, timedelta
4
4
from boto.services.service import Service
5
5
 
 
6
Usage =  """
 
7
    get_results.py  [-q queuename] [-m mimetype_file] [-n] path
 
8
 
 
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."
 
17
                        
 
18
                        video/x-flv    flv
 
19
 
 
20
        path - The location on your local file system where results
 
21
               will be stored.
 
22
        if -n is specified, the result files will not be retrieved
 
23
        from S3, otherwise the result files will be downloaded to
 
24
        the specified path'
 
25
    """
 
26
 
6
27
class ResultProcessor:
7
28
 
 
29
    
8
30
    TimeFormat = '%a, %d %b %Y %H:%M:%S %Z'
9
31
    LogFileName = 'log.csv'
10
32
 
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,
14
 
                               read_userdata=False)
 
36
                               read_userdata=False,
 
37
                               mimetype_files=mimetype_files,
 
38
                               preserve_file_name=True)
15
39
        self.log_fp = None
16
40
        self.num_files = 0
17
41
        self.total_time = 0
57
81
        total_time = 0
58
82
        if not os.path.isdir(path):
59
83
            os.mkdir(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)
61
85
        while m:
62
86
            total_files += 1
63
87
            self.log_message(m, path)
64
88
            self.calculate_stats(m)
65
 
            m = self.service.get_result(path, original_name=True,
66
 
                                        get_file=get_file)
 
89
            m = self.service.get_result(path, get_file=get_file)
67
90
        if self.log_fp:
68
91
            self.log_fp.close()
69
92
        print '%d results successfully retrieved.' % total_files
78
101
            print 'Throughput: %f transactions / minute' % tput
79
102
        
80
103
def usage():
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'
 
104
    print Usage
85
105
  
86
106
def main():
87
107
    try:
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'])
90
111
    except:
91
112
        usage()
92
113
        sys.exit(2)
93
114
    queue_name = None
 
115
    mimetype_file = None
94
116
    notify = False
95
117
    get_file = True
96
118
    for o, a in opts:
97
119
        if o in ('-h', '--help'):
98
120
            usage()
99
121
            sys.exit()
 
122
        if o in ('-m', '--mimetypes'):
 
123
            mimetype_file = [a]
100
124
        if o in ('-n', '--no-retrieve'):
101
125
            get_file = False
102
126
        if o in ('-q', '--queue'):
107
131
    path = args[0]
108
132
    if len(args) > 1:
109
133
        tags = 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)
112
138
    return 1
113
139