Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release-2.28.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed May 8, 2014
2 parents 9bc6e5a + 4b659ba commit b28e7fc
Show file tree
Hide file tree
Showing 85 changed files with 7,294 additions and 1,585 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING
Expand Up @@ -40,7 +40,7 @@ Reporting An Issue/Feature
* boto
* Optionally of the other dependencies involved

* If possile, create a pull request with a (failing) test case demonstrating
* If possible, create a pull request with a (failing) test case demonstrating
what's wrong. This makes the process for fixing bugs quicker & gets issues
resolved sooner.

Expand Down
4 changes: 2 additions & 2 deletions README.rst
@@ -1,9 +1,9 @@
####
boto
####
boto 2.27.0
boto 2.28.0

Released: 6-March-2014
Released: 8-May-2014

.. image:: https://travis-ci.org/boto/boto.png?branch=develop
:target: https://travis-ci.org/boto/boto
Expand Down
105 changes: 77 additions & 28 deletions bin/mturk
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright 2012 Kodi Arfer
# Copyright 2012, 2014 Kodi Arfer
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
Expand Down Expand Up @@ -40,6 +40,8 @@ default_nicknames_path = os.path.expanduser('~/.boto_mturkcli_hit_nicknames')
nicknames = {}
nickname_pool = set(string.ascii_lowercase)

get_assignments_page_size = 100

time_units = dict(
s = 1,
min = 60,
Expand Down Expand Up @@ -281,10 +283,20 @@ but apparently, it does.'''
nicknames = {k: v for k, v in nicknames.items() if v != hit}

def list_assignments(hit, only_reviewable = False):
assignments = map(digest_assignment, con.get_assignments(
hit_id = hit,
page_size = 100,
status = 'Submitted' if only_reviewable else None))
# Accumulate all relevant assignments, one page of results at
# a time.
assignments = []
page = 1
while True:
rs = con.get_assignments(
hit_id = hit,
page_size = get_assignments_page_size,
page_number = page,
status = 'Submitted' if only_reviewable else None)
assignments += map(digest_assignment, rs)
if len(assignments) >= int(rs.TotalNumResults):
break
page += 1
if interactive:
print json.dumps(assignments, sort_keys = True, indent = 4)
print ' '.join([a['AssignmentId'] for a in assignments])
Expand Down Expand Up @@ -315,6 +327,16 @@ def unreject_assignments(message, assignments):
def notify_workers(subject, text, workers):
con.notify_workers(workers, subject, text)

def give_qualification(qualification, workers, value = 1, notify = True):
for w in workers:
con.assign_qualification(qualification, w, value, notify)
if interactive: print 'Gave to', w

def revoke_qualification(qualification, workers, message = None):
for w in workers:
con.revoke_qualification(w, qualification, message)
if interactive: print 'Revoked from', w

# --------------------------------------------------
# Mainline code
# --------------------------------------------------
Expand All @@ -332,10 +354,10 @@ if __name__ == '__main__':

sub = subs.add_parser('hit',
help = 'get information about a HIT')
sub.add_argument('hit',
sub.add_argument('HIT',
help = 'nickname or ID of the HIT to show')
sub.set_defaults(f = show_hit, a = lambda:
[get_hitid(args.hit)])
[get_hitid(args.HIT)])

sub = subs.add_parser('hits',
help = 'list all your HITs')
Expand All @@ -345,7 +367,7 @@ if __name__ == '__main__':
help = 'create a new HIT (external questions only)',
epilog = example_config_file,
formatter_class = argparse.RawDescriptionHelpFormatter)
sub.add_argument('json_path',
sub.add_argument('JSON_PATH',
help = 'path to JSON configuration file for the HIT')
sub.add_argument('-u', '--question-url', dest = 'question_url',
metavar = 'URL',
Expand All @@ -357,13 +379,13 @@ if __name__ == '__main__':
type = float, metavar = 'PRICE',
help = 'reward amount, in USD')
sub.set_defaults(f = make_hit, a = lambda: dict(
unjson(args.json_path).items() + [(k, getattr(args, k))
unjson(args.JSON_PATH).items() + [(k, getattr(args, k))
for k in ('question_url', 'assignments', 'reward')
if getattr(args, k) is not None]))

sub = subs.add_parser('extend',
help = 'add assignments or time to a HIT')
sub.add_argument('hit',
sub.add_argument('HIT',
help = 'nickname or ID of the HIT to extend')
sub.add_argument('-a', '--assignments', dest = 'assignments',
metavar = 'N', type = int,
Expand All @@ -372,68 +394,95 @@ if __name__ == '__main__':
metavar = 'T',
help = 'amount of time to add to the expiration date')
sub.set_defaults(f = extend_hit, a = lambda:
[get_hitid(args.hit), args.assignments,
[get_hitid(args.HIT), args.assignments,
args.time and parse_duration(args.time)])

sub = subs.add_parser('expire',
help = 'force a HIT to expire without deleting it')
sub.add_argument('hit',
sub.add_argument('HIT',
help = 'nickname or ID of the HIT to expire')
sub.set_defaults(f = expire_hit, a = lambda:
[get_hitid(args.hit)])
[get_hitid(args.HIT)])

sub = subs.add_parser('rm',
help = 'delete a HIT')
sub.add_argument('hit',
sub.add_argument('HIT',
help = 'nickname or ID of the HIT to delete')
sub.set_defaults(f = delete_hit, a = lambda:
[get_hitid(args.hit)])
[get_hitid(args.HIT)])

sub = subs.add_parser('as',
help = "list a HIT's submitted assignments")
sub.add_argument('hit',
sub.add_argument('HIT',
help = 'nickname or ID of the HIT to get assignments for')
sub.add_argument('-r', '--reviewable', dest = 'only_reviewable',
action = 'store_true',
help = 'show only unreviewed assignments')
sub.set_defaults(f = list_assignments, a = lambda:
[get_hitid(args.hit), args.only_reviewable])
[get_hitid(args.HIT), args.only_reviewable])

for command, fun, helpmsg in [
('approve', approve_assignments, 'approve assignments'),
('reject', reject_assignments, 'reject assignments'),
('unreject', unreject_assignments, 'approve previously rejected assignments')]:
sub = subs.add_parser(command, help = helpmsg)
sub.add_argument('assignment', nargs = '+',
sub.add_argument('ASSIGNMENT', nargs = '+',
help = 'ID of an assignment')
sub.add_argument('-m', '--message', dest = 'message',
metavar = 'TEXT',
help = 'feedback message shown to workers')
sub.set_defaults(f = fun, a = lambda:
[args.message, args.assignment])
[args.message, args.ASSIGNMENT])

sub = subs.add_parser('bonus',
help = 'give some workers a bonus')
sub.add_argument('amount', type = float,
sub.add_argument('AMOUNT', type = float,
help = 'bonus amount, in USD')
sub.add_argument('message',
sub.add_argument('MESSAGE',
help = 'the reason for the bonus (shown to workers in an email sent by MTurk)')
sub.add_argument('widaid', nargs = '+',
sub.add_argument('WIDAID', nargs = '+',
help = 'a WORKER_ID,ASSIGNMENT_ID pair')
sub.set_defaults(f = grant_bonus, a = lambda:
[args.message, args.amount,
[p.split(',') for p in args.widaid]])
[args.MESSAGE, args.AMOUNT,
[p.split(',') for p in args.WIDAID]])

sub = subs.add_parser('notify',
help = 'send a message to some workers')
sub.add_argument('subject',
sub.add_argument('SUBJECT',
help = 'subject of the message')
sub.add_argument('message',
sub.add_argument('MESSAGE',
help = 'text of the message')
sub.add_argument('worker', nargs = '+',
sub.add_argument('WORKER', nargs = '+',
help = 'ID of a worker')
sub.set_defaults(f = notify_workers, a = lambda:
[args.subject, args.message, args.worker])
[args.SUBJECT, args.MESSAGE, args.WORKER])

sub = subs.add_parser('give-qual',
help = 'give a qualification to some workers')
sub.add_argument('QUAL',
help = 'ID of the qualification')
sub.add_argument('WORKER', nargs = '+',
help = 'ID of a worker')
sub.add_argument('-v', '--value', dest = 'value',
metavar = 'N', type = int, default = 1,
help = 'value of the qualification')
sub.add_argument('--dontnotify', dest = 'notify',
action = 'store_false', default = True,
help = "don't notify workers")
sub.set_defaults(f = give_qualification, a = lambda:
[args.QUAL, args.WORKER, args.value, args.notify])

sub = subs.add_parser('revoke-qual',
help = 'revoke a qualification from some workers')
sub.add_argument('QUAL',
help = 'ID of the qualification')
sub.add_argument('WORKER', nargs = '+',
help = 'ID of a worker')
sub.add_argument('-m', '--message', dest = 'message',
metavar = 'TEXT',
help = 'the reason the qualification was revoked (shown to workers in an email sent by MTurk)')
sub.set_defaults(f = revoke_qualification, a = lambda:
[args.QUAL, args.WORKER, args.message])

args = parser.parse_args()

Expand Down
6 changes: 3 additions & 3 deletions bin/route53
Expand Up @@ -131,7 +131,7 @@ def change_record(conn, hosted_zone_id, name, type, newvalues, ttl=600,
for old_value in response.resource_records:
change1.add_value(old_value)

change2 = changes.add_change("CREATE", name, type, ttl,
change2 = changes.add_change("UPSERT", name, type, ttl,
identifier=identifier, weight=weight)
for new_value in newvalues.split(','):
change2.add_value(new_value)
Expand All @@ -148,11 +148,11 @@ def change_alias(conn, hosted_zone_id, name, type, new_alias_hosted_zone_id, new
continue
if response.identifier != identifier or response.weight != weight:
continue
change1 = changes.add_change("DELETE", name, type,
change1 = changes.add_change("DELETE", name, type,
identifier=response.identifier,
weight=response.weight)
change1.set_alias(response.alias_hosted_zone_id, response.alias_dns_name)
change2 = changes.add_change("CREATE", name, type, identifier=identifier, weight=weight)
change2 = changes.add_change("UPSERT", name, type, identifier=identifier, weight=weight)
change2.set_alias(new_alias_hosted_zone_id, new_alias_dns_name)
print changes.commit()

Expand Down
22 changes: 20 additions & 2 deletions boto/__init__.py
Expand Up @@ -37,7 +37,7 @@
import urlparse
from boto.exception import InvalidUriError

__version__ = '2.27.0'
__version__ = '2.28.0'
Version = __version__ # for backware compatibility

# http://bugs.python.org/issue7980
Expand Down Expand Up @@ -653,14 +653,32 @@ def connect_cloudsearch(aws_access_key_id=None,
:type aws_secret_access_key: string
:param aws_secret_access_key: Your AWS Secret Access Key
:rtype: :class:`boto.ec2.autoscale.CloudSearchConnection`
:rtype: :class:`boto.cloudsearch.layer2.Layer2`
:return: A connection to Amazon's CloudSearch service
"""
from boto.cloudsearch.layer2 import Layer2
return Layer2(aws_access_key_id, aws_secret_access_key,
**kwargs)


def connect_cloudsearch2(aws_access_key_id=None,
aws_secret_access_key=None,
**kwargs):
"""
:type aws_access_key_id: string
:param aws_access_key_id: Your AWS Access Key ID
:type aws_secret_access_key: string
:param aws_secret_access_key: Your AWS Secret Access Key
:rtype: :class:`boto.cloudsearch2.layer2.Layer2`
:return: A connection to Amazon's CloudSearch2 service
"""
from boto.cloudsearch2.layer2 import Layer2
return Layer2(aws_access_key_id, aws_secret_access_key,
**kwargs)


def connect_beanstalk(aws_access_key_id=None,
aws_secret_access_key=None,
**kwargs):
Expand Down
6 changes: 6 additions & 0 deletions boto/auth.py
Expand Up @@ -904,6 +904,9 @@ def _wrapper(self):
return ['hmac-v4']

if hasattr(self, 'region'):
# If you're making changes here, you should also check
# ``boto/iam/connection.py``, as several things there are also
# endpoint-related.
if getattr(self.region, 'endpoint', ''):
if '.cn-' in self.region.endpoint:
return ['hmac-v4']
Expand All @@ -921,6 +924,9 @@ def _wrapper(self):
return ['hmac-v4-s3']

if hasattr(self, 'host'):
# If you're making changes here, you should also check
# ``boto/iam/connection.py``, as several things there are also
# endpoint-related.
if '.cn-' in self.host:
return ['hmac-v4-s3']

Expand Down
12 changes: 6 additions & 6 deletions boto/beanstalk/layer1.py
Expand Up @@ -351,9 +351,9 @@ def create_environment(self, application_name, environment_name,
self.build_list_params(params, options_to_remove,
'OptionsToRemove.member')
if tier_name and tier_type and tier_version:
params['Tier.member.Name'] = tier_name
params['Tier.member.Type'] = tier_type
params['Tier.member.Version'] = tier_version
params['Tier.Name'] = tier_name
params['Tier.Type'] = tier_type
params['Tier.Version'] = tier_version
return self._get_response('CreateEnvironment', params)

def create_storage_location(self):
Expand Down Expand Up @@ -1138,9 +1138,9 @@ def update_environment(self, environment_id=None, environment_name=None,
self.build_list_params(params, options_to_remove,
'OptionsToRemove.member')
if tier_name and tier_type and tier_version:
params['Tier.member.Name'] = tier_name
params['Tier.member.Type'] = tier_type
params['Tier.member.Version'] = tier_version
params['Tier.Name'] = tier_name
params['Tier.Type'] = tier_type
params['Tier.Version'] = tier_version
return self._get_response('UpdateEnvironment', params)

def validate_configuration_settings(self, application_name,
Expand Down
42 changes: 42 additions & 0 deletions boto/cloudsearch2/__init__.py
@@ -0,0 +1,42 @@
# Copyright (c) 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from boto.regioninfo import get_regions


def regions():
"""
Get all available regions for the Amazon CloudSearch service.
:rtype: list
:return: A list of :class:`boto.regioninfo.RegionInfo`
"""
import boto.cloudsearch2.layer1
return get_regions(
'cloudsearch',
connection_cls=boto.cloudsearch2.layer1.CloudSearchConnection
)


def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
return region.connect(**kw_params)
return None

0 comments on commit b28e7fc

Please sign in to comment.