~blamar/+junk/openstack-api-arrrg

« back to all changes in this revision

Viewing changes to vendor/boto/boto/mturk/test/cleanup_tests.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from boto.mturk.connection import MTurkConnection
 
2
 
 
3
def cleanup():
 
4
    """Remove any boto test related HIT's"""
 
5
 
 
6
    conn = MTurkConnection(host='mechanicalturk.sandbox.amazonaws.com')
 
7
    current_page = 1
 
8
    page_size = 10
 
9
    total_disabled = 0
 
10
    ignored = []
 
11
 
 
12
    while True:
 
13
        # reset the total for this loop
 
14
        disabled_count = 0
 
15
 
 
16
        # search all the hits in the sandbox
 
17
        search_rs = conn.search_hits(page_size=page_size, page_number=current_page)
 
18
 
 
19
        # success?
 
20
        if search_rs.status:
 
21
            for hit in search_rs:
 
22
                # delete any with Boto in the description
 
23
                print 'hit id:%s Status:%s, desc:%s' %(hit.HITId, hit.HITStatus, hit.Description)
 
24
                if hit.Description.find('Boto') != -1:
 
25
                    if hit.HITStatus != 'Reviewable':
 
26
                        print 'Disabling hit id:%s %s' %(hit.HITId, hit.Description)
 
27
                        disable_rs = conn.disable_hit(hit.HITId)
 
28
                        if disable_rs.status:
 
29
                            disabled_count += 1
 
30
                            # update the running total
 
31
                            total_disabled += 1
 
32
                        else:
 
33
                            print 'Error when disabling, code:%s, message:%s' %(disable_rs.Code, disable_rs.Message)
 
34
                    else:
 
35
                        print 'Disposing hit id:%s %s' %(hit.HITId, hit.Description)
 
36
                        dispose_rs = conn.dispose_hit(hit.HITId)
 
37
                        if dispose_rs.status:
 
38
                            disabled_count += 1
 
39
                            # update the running total
 
40
                            total_disabled += 1
 
41
                        else:
 
42
                            print 'Error when disposing, code:%s, message:%s' %(dispose_rs.Code, dispose_rs.Message)
 
43
 
 
44
                else:
 
45
                    if hit.HITId not in ignored:
 
46
                        print 'ignored:%s' %hit.HITId
 
47
                        ignored.append(hit.HITId)
 
48
 
 
49
            # any more results?
 
50
            if int(search_rs.TotalNumResults) > current_page*page_size:
 
51
                # if we have disabled any HITs on this page
 
52
                # then we don't need to go to a new page
 
53
                # otherwise we do
 
54
                if not disabled_count:
 
55
                    current_page += 1
 
56
            else:
 
57
                # no, we're done
 
58
                break
 
59
        else:
 
60
            print 'Error performing search, code:%s, message:%s' %(search_rs.Code, search_rs.Message)
 
61
            break
 
62
 
 
63
    total_ignored = len(ignored)
 
64
    print 'Processed: %d HITs, disabled/disposed: %d, ignored: %d' %(total_ignored + total_disabled, total_disabled, total_ignored)
 
65
 
 
66
if __name__ == '__main__':    
 
67
    cleanup()