Skip to content

Commit b866ac4

Browse files
committed
Add .flake8 and format Python files
flake8 is a Python linter. autopep8 is a Python formatter. The config for autopep8 can reside in the .flake8 config. Used the following command to format all .py files and all files without extension containing a python shebang. { find . -type f ! -name "*.*" -exec awk '/^#!.*python/{print FILENAME}{nextfile}' {} +; find . -name '*.py'; } | sort | uniq | xargs autopep8 --in-place --aggressive --aggressive Change-Id: Ie7d20194499e91a181b9e040b44d179c35b2ce4a Reviewed-on: https://review.couchbase.org/c/kv_engine/+/205483 Tested-by: Vesko Karaganev <[email protected]> Reviewed-by: Trond Norbye <[email protected]>
1 parent bf242c9 commit b866ac4

28 files changed

+1168
-622
lines changed

.flake8

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[flake8]
2+
import-order-style = pep8
3+
max-line-length = 79
4+
ignore = E402
5+
6+
[pycodestyle]
7+
max_line_length = 79
8+
ignore = E402

engines/ep/management/cb_evict_key.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
client.sasl_auth_plain(user=sys.argv[1], password=sys.argv[2])
3030
client.bucket_select(sys.argv[3])
3131

32-
collection=None
32+
collection = None
3333
client.enable_xerror()
3434
if len(sys.argv) == 7:
3535
client.enable_collections()
@@ -38,9 +38,9 @@
3838

3939
if len(sys.argv) == 7:
4040
try:
41-
collection=int(sys.argv[6])
41+
collection = int(sys.argv[6])
4242
except ValueError:
43-
collection=sys.argv[6]
43+
collection = sys.argv[6]
4444

4545
key = sys.argv[5]
4646
client.vbucketId = int(sys.argv[4])

engines/ep/management/cbcompact

+11-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ from time import sleep
2121
import sys
2222
import mc_bin_client
2323

24+
2425
def cmd(f):
2526
f = cli_auth_utils.cmd_decorator(f)
27+
2628
def g(*args, **kwargs):
2729
mc = args[0]
2830

@@ -41,16 +43,18 @@ def cmd(f):
4143
f(mc, vbucket, purgeBeforeTs, purgeBeforeSeq, dropDeletes, **kwargs)
4244
return g
4345

46+
4447
@cmd
4548
def compact(mc, vbucket, purgeBeforeTs, purgeBeforeSeq, dropDeletes):
46-
try:
49+
try:
4750
return mc.compact_db(vbucket, purgeBeforeTs, purgeBeforeSeq,
4851
dropDeletes)
49-
except:
50-
print("Unable to compact vbucket %d with the following parameters "
51-
"(purge before time: %d, purge before seqno: %d, drop deletes: "
52-
"%d) in requested engine."
53-
% (vbucket, purgeBeforeTs, purgeBeforeSeq, dropDeletes))
52+
except BaseException:
53+
print("Unable to compact vbucket %d with the following parameters "
54+
"(purge before time: %d, purge before seqno: %d, drop deletes: "
55+
"%d) in requested engine."
56+
% (vbucket, purgeBeforeTs, purgeBeforeSeq, dropDeletes))
57+
5458

5559
def main():
5660
c = cli_auth_utils.get_authed_clitool()
@@ -64,5 +68,6 @@ def main():
6468

6569
c.execute()
6670

71+
6772
if __name__ == '__main__':
6873
main()

engines/ep/management/cbepctl

+24-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import sys
2121

2222
cmd = cli_auth_utils.cmd_decorator
2323

24+
2425
@cmd
2526
def set_param(mc, type, key, val):
2627
engine_param = None
@@ -42,43 +43,45 @@ def set_param(mc, type, key, val):
4243

4344
if key == "mem_high_wat" or key == "mem_low_wat":
4445
if val.endswith("%"):
45-
_x_ = (val[:len(val)-1])
46+
_x_ = (val[:len(val) - 1])
4647
if not _x_.isdigit():
4748
print('Error: Invalid parameter %s' % val)
4849
return
4950
if float(_x_) > 100:
5051
print('Error: Bad parameter %s' % val)
5152
return
5253
_quota_ = int(mc.stats()['ep_max_size'])
53-
val = str(int(float(_x_)*(_quota_)/100))
54+
val = str(int(float(_x_) * (_quota_) / 100))
5455
if (key == "mem_used_merge_threshold_percent" and
55-
(float(val) > 100.0 or float(val) < 0.0)):
56+
(float(val) > 100.0 or float(val) < 0.0)):
5657
print('Error: Invalid mem_used_merge_threshold_percent value %s' % val)
5758
return
5859
try:
5960
mc.set_param(0, key, val, engine_param)
60-
print('set %s to %s' %(key, val))
61+
print('set %s to %s' % (key, val))
6162
except mc_bin_client.MemcachedError as error:
6263
print('Error: %s' % error.msg)
6364
except mc_bin_client.TimeoutError as error:
6465
print(error)
6566
except Exception as e:
6667
print('Generic error (%s)' % e)
6768

69+
6870
@cmd
6971
def set_vbucket_param(mc, key, vbucket, val):
7072
engine_param = memcacheConstants.ENGINE_PARAM_VBUCKET
7173

7274
try:
7375
mc.set_param(int(vbucket), key, val, engine_param)
74-
print('set %s to %s' %(key, val))
76+
print('set %s to %s' % (key, val))
7577
except mc_bin_client.MemcachedError as error:
7678
print('Error: %s' % error.msg)
7779
except mc_bin_client.TimeoutError as error:
7880
print(error)
7981
except Exception as e:
8082
print('Generic error (%s)' % e)
8183

84+
8285
@cmd
8386
def stop(mc):
8487
try:
@@ -89,7 +92,7 @@ def stop(mc):
8992
try:
9093
stats = mc.stats()
9194
success = True
92-
except:
95+
except BaseException:
9396
if success:
9497
mc = mc_bin_client.MemcachedClient(mc.host, mc.port)
9598
raise
@@ -106,6 +109,7 @@ def stop(mc):
106109
except Exception as e:
107110
print('Generic error (%s)' % e)
108111

112+
109113
@cmd
110114
def start(mc):
111115
try:
@@ -118,6 +122,7 @@ def start(mc):
118122
except Exception as e:
119123
print('Generic error (%s)' % e)
120124

125+
121126
@cmd
122127
def drain(mc):
123128
try:
@@ -137,6 +142,7 @@ def drain(mc):
137142
except Exception as e:
138143
print('Generic error (%s)' % e)
139144

145+
140146
@cmd
141147
def set_collections(mc, filename):
142148

@@ -154,6 +160,7 @@ def set_collections(mc, filename):
154160
except Exception as e:
155161
print('Generic error (%s)' % e)
156162

163+
157164
@cmd
158165
def get_collections(mc):
159166

@@ -167,12 +174,17 @@ def get_collections(mc):
167174
except Exception as e:
168175
print('Generic error (%s)' % e)
169176

177+
170178
@cmd
171179
def run_compaction(mc, vbucket, purgeBeforeTs, purgeBeforeSeq, dropDeletes):
172180
engine_param = memcacheConstants.ENGINE_PARAM_VBUCKET
173181

174182
try:
175-
mc.compact_db(int(vbucket), int(purgeBeforeTs), int(purgeBeforeSeq), int(dropDeletes))
183+
mc.compact_db(
184+
int(vbucket),
185+
int(purgeBeforeTs),
186+
int(purgeBeforeSeq),
187+
int(dropDeletes))
176188
print('compaction started on vbucket {}'.format(vbucket))
177189
except mc_bin_client.MemcachedError as error:
178190
print('Error: %s' % error.msg)
@@ -181,6 +193,7 @@ def run_compaction(mc, vbucket, purgeBeforeTs, purgeBeforeSeq, dropDeletes):
181193
except Exception as e:
182194
print('Generic error (%s)' % e)
183195

196+
184197
if __name__ == '__main__':
185198

186199
c = cli_auth_utils.get_authed_clitool("""
@@ -351,7 +364,10 @@ Available params for "set":
351364
c.addCommand('set_vbucket_param', set_vbucket_param, 'type vbucket value')
352365
c.addCommand('start', start, 'start')
353366
c.addCommand('stop', stop, 'stop')
354-
c.addCommand('compact', run_compaction, 'vbucket purgeBeforeTs purgeBeforeSeq dropDeletes')
367+
c.addCommand(
368+
'compact',
369+
run_compaction,
370+
'vbucket purgeBeforeTs purgeBeforeSeq dropDeletes')
355371

356372
# Add collection get manifest methods - These should not be executed
357373
# except for when required by support/development

0 commit comments

Comments
 (0)