Skip to content

Commit 8105a8e

Browse files
committed
Merge branch 'master' into pevm-unittest-determinism
grab bucket property deletion
2 parents 433f08f + f25f4a2 commit 8105a8e

File tree

10 files changed

+91
-8
lines changed

10 files changed

+91
-8
lines changed

riak/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
@author Jay Baird (@skatterbean) ([email protected])
3131
"""
3232

33+
__all__ = ['RiakClient', 'RiakBucket', 'RiakNode', 'RiakObject',
34+
'RiakMapReduce', 'RiakKeyFilter', 'RiakLink', 'RiakError',
35+
'ONE', 'ALL', 'QUORUM', 'key_filter']
36+
3337

3438
class RiakError(Exception):
3539
"""
@@ -41,7 +45,11 @@ def __init__(self, value):
4145
def __str__(self):
4246
return repr(self.value)
4347

44-
from mapreduce import RiakKeyFilter
48+
from client import RiakClient
49+
from bucket import RiakBucket
50+
from node import RiakNode
51+
from riak_object import RiakObject
52+
from mapreduce import RiakKeyFilter, RiakMapReduce, RiakLink
4553

4654
ONE = "one"
4755
ALL = "all"

riak/bucket.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ def get_properties(self):
344344
"""
345345
return self._client.get_bucket_props(self)
346346

347+
def clear_properties(self):
348+
"""
349+
Reset all bucket properties to their defaults.
350+
351+
"""
352+
return self._client.clear_bucket_props(self)
353+
347354
def get_keys(self):
348355
"""
349356
Return all keys within the bucket.

riak/client/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,19 @@ def __init__(self, protocol='http', transport_options={},
6363
the transport constuctor
6464
:type transport_options: dict
6565
"""
66+
unused_args = unused_args.copy()
67+
6668
if 'port' in unused_args:
6769
deprecated("port option is deprecated, use http_port or pb_port,"
68-
+ " or the nodes option")
70+
" or the nodes option. Your given port of %r will be "
71+
"used as the %s port unless already set" %
72+
(unused_args['port'], protocol))
73+
unused_args['already_warned_port'] = True
74+
if (protocol in ['http', 'https'] and
75+
'http_port' not in unused_args):
76+
unused_args['http_port'] = unused_args['port']
77+
elif protocol == 'pbc' and 'pb_port' not in unused_args:
78+
unused_args['pb_port'] = unused_args['port']
6979

7080
if 'transport_class' in unused_args:
7181
deprecated(

riak/client/operations.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ def set_bucket_props(self, transport, bucket, props):
8989
"""
9090
return transport.set_bucket_props(bucket, props)
9191

92+
@retryableHttpOnly
93+
def clear_bucket_props(self, transport, bucket):
94+
"""
95+
Resets bucket properties for the given bucket.
96+
97+
:param bucket: the bucket whose properties will be set
98+
:type bucket: RiakBucket
99+
"""
100+
return transport.clear_bucket_props(bucket)
101+
92102
@retryable
93103
def get_keys(self, transport, bucket):
94104
"""

riak/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__(self, host='127.0.0.1', http_port=8098, pb_port=8087,
9090
:type pb_port: integer
9191
"""
9292

93-
if 'port' in unused_args:
93+
if 'port' in unused_args and not 'already_warned_port' in unused_args:
9494
deprecated("port option is deprecated, use http_port or pb_port")
9595

9696
self.host = host

riak/riak_object.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
)
3131
from riak import RiakError
3232

33+
3334
class RiakObject(object):
3435
"""
3536
The RiakObject holds meta information about a Riak object, plus the
@@ -209,7 +210,6 @@ def remove_index(self, field=None, value=None):
209210
raise RiakError("Cannot pass value without a field"
210211
" name while removing index")
211212

212-
213213
# This removes the index entries that's in the ries list.
214214
# Done because this is preferred over metadata[MD_INDEX].remove(rie)
215215
self.metadata[MD_INDEX] = [rie for rie in self.metadata[MD_INDEX]
@@ -224,7 +224,8 @@ def set_indexes(self, indexes):
224224
iterable of 2 item tuples, (field, value).
225225
226226
:param indexes: iterable of 2 item tuples consisting the field
227-
and value. Both the field and the value must be a string.
227+
and value. Both the field and the value must
228+
be a string.
228229
:rtype: RiakObject
229230
"""
230231
# makes a copy and does type conversion

riak/tests/test_all.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ def test_too_many_link_headers_shouldnt_break_http(self):
170170
stored_object = bucket.get("lots_of_links")
171171
self.assertEqual(len(stored_object.get_links()), 400)
172172

173+
def test_clear_bucket_properties(self):
174+
bucket = self.client.bucket('bucket')
175+
bucket.allow_mult = True
176+
self.assertTrue(bucket.allow_mult)
177+
bucket.n_val = 1
178+
self.assertEqual(bucket.n_val, 1)
179+
# Test setting clearing properties...
180+
181+
self.assertTrue(bucket.clear_properties())
182+
self.assertFalse(bucket.allow_mult)
183+
self.assertEqual(bucket.n_val, 3)
184+
173185

174186
class FilterTests(unittest.TestCase):
175187
def test_simple(self):

riak/transports/http/transport.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,30 @@ def set_bucket_props(self, bucket, props):
279279
raise Exception('Error setting bucket properties.')
280280
return True
281281

282+
def clear_bucket_props(self, bucket):
283+
"""
284+
reset the properties on the bucket object given
285+
"""
286+
url = self.bucket_properties_path(bucket.name)
287+
headers = {'Content-Type': 'application/json'}
288+
289+
# Run the request...
290+
response = self._request('DELETE', url, headers, None)
291+
292+
# Handle the response...
293+
if response is None:
294+
raise Exception('Error clearing bucket properties.')
295+
296+
# Check the response value...
297+
status = response[0]['http_code']
298+
if status == 204:
299+
return True
300+
elif status == 405:
301+
return False
302+
else:
303+
raise Exception('Error %s clearing bucket properties.'
304+
% status)
305+
282306
def mapred(self, inputs, query, timeout=None):
283307
"""
284308
Run a MapReduce query.

riak/transports/transport.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ def set_bucket_props(self, bucket, props):
120120
"""
121121
raise NotImplementedError
122122

123+
def clear_bucket_props(self, bucket):
124+
"""
125+
Reset bucket properties to their defaults
126+
bucket = bucket object
127+
"""
128+
raise NotImplementedError
129+
123130
def get_keys(self, bucket):
124131
"""
125132
Lists all keys within the given bucket.

riak/util.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import warnings
2020
from collections import Mapping
2121

22+
2223
def quacks_like_dict(object):
2324
"""Check if object is dict-like"""
2425
return isinstance(object, Mapping)
@@ -54,7 +55,7 @@ def deep_merge(a, b):
5455

5556

5657
def deprecated(message, stacklevel=3):
57-
warnings.warn(message, DeprecationWarning, stacklevel=stacklevel)
58+
warnings.warn(message, UserWarning, stacklevel=stacklevel)
5859

5960
QUORUMS = ['r', 'pr', 'w', 'dw', 'pw', 'rw']
6061
QDEPMESSAGE = """
@@ -79,21 +80,24 @@ def __deprecateQuorumAccessor(klass, parent, quorum):
7980
getter_name = "get_%s" % quorum
8081
setter_name = "set_%s" % quorum
8182
if not parent:
82-
def getter(self, val=None):
83+
def direct_getter(self, val=None):
8384
deprecated(QDEPMESSAGE % klass.__name__)
8485
if val:
8586
return val
8687
return getattr(self, propname, "default")
8788

89+
getter = direct_getter
8890
else:
89-
def getter(self, val=None):
91+
def parent_getter(self, val=None):
9092
deprecated(QDEPMESSAGE % klass.__name__)
9193
if val:
9294
return val
9395
parentInstance = getattr(self, parent)
9496
return getattr(self, propname,
9597
getattr(parentInstance, propname, "default"))
9698

99+
getter = parent_getter
100+
97101
def setter(self, value):
98102
deprecated(QDEPMESSAGE % klass.__name__)
99103
setattr(self, propname, value)

0 commit comments

Comments
 (0)