Skip to content

Commit

Permalink
Upgrade pep8 to 1.3.3.
Browse files Browse the repository at this point in the history
This required a bunch of whitespace-poking of the scripts in bin, but
that's all. Now every file in swift/ and bin/ is pep8-1.3.3-compliant,
so hopefully we can be done with this pep8 stuff for a good long time.

Change-Id: I44fdb41d219c57400a4c396ab7eb0ffa9dcd8db8
  • Loading branch information
smerritt committed Nov 27, 2012
1 parent 2ad23a2 commit 35f4d29
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 73 deletions.
25 changes: 12 additions & 13 deletions bin/swift-account-audit
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Examples!

class Auditor(object):
def __init__(self, swift_dir='/etc/swift', concurrency=50, deep=False,
error_file=None):
error_file=None):
self.pool = GreenPool(concurrency)
self.object_ring = Ring(os.path.join(swift_dir, ring_name='object'))
self.container_ring = \
Expand Down Expand Up @@ -89,7 +89,7 @@ class Auditor(object):
try:
if self.deep:
conn = http_connect(node['ip'], node['port'],
node['device'], part, 'GET', path, {})
node['device'], part, 'GET', path, {})
resp = conn.getresponse()
calc_hash = md5()
chunk = True
Expand All @@ -101,13 +101,13 @@ class Auditor(object):
self.object_not_found += 1
consistent = False
print ' Bad status GETting object "%s" on %s/%s' \
% (path, node['ip'], node['device'])
% (path, node['ip'], node['device'])
continue
if resp.getheader('ETag').strip('"') != calc_hash:
self.object_checksum_mismatch += 1
consistent = False
print ' MD5 doesnt match etag for "%s" on %s/%s' \
% (path, node['ip'], node['device'])
% (path, node['ip'], node['device'])
etags.append(resp.getheader('ETag'))
else:
conn = http_connect(node['ip'], node['port'],
Expand All @@ -118,14 +118,14 @@ class Auditor(object):
self.object_not_found += 1
consistent = False
print ' Bad status HEADing object "%s" on %s/%s' \
% (path, node['ip'], node['device'])
% (path, node['ip'], node['device'])
continue
etags.append(resp.getheader('ETag'))
except Exception:
self.object_exceptions += 1
consistent = False
print ' Exception fetching object "%s" on %s/%s' \
% (path, node['ip'], node['device'])
% (path, node['ip'], node['device'])
continue
if not etags:
consistent = False
Expand All @@ -136,7 +136,7 @@ class Auditor(object):
consistent = False
self.object_checksum_mismatch += 1
print ' ETag mismatch for "%s" on %s/%s' \
% (path, node['ip'], node['device'])
% (path, node['ip'], node['device'])
if not consistent and self.error_file:
print >>open(self.error_file, 'a'), path
self.objects_checked += 1
Expand Down Expand Up @@ -183,7 +183,7 @@ class Auditor(object):
self.container_exceptions += 1
consistent = False
print ' Exception GETting container "%s" on %s/%s' % \
(path, node['ip'], node['device'])
(path, node['ip'], node['device'])
break
if results:
marker = results[-1]['name']
Expand All @@ -196,13 +196,12 @@ class Auditor(object):
self.container_obj_mismatch += 1
consistent = False
print(" Different versions of %s/%s "
"in container dbs." % \
(name, obj['name']))
"in container dbs." % (name, obj['name']))
if (obj['last_modified'] >
rec_d[obj_name]['last_modified']):
rec_d[obj_name] = obj
obj_counts = [int(header['x-container-object-count'])
for header in responses.values()]
for header in responses.values()]
if not obj_counts:
consistent = False
print " Failed to fetch container %s at all!" % path
Expand Down Expand Up @@ -266,7 +265,7 @@ class Auditor(object):
marker = results[-1]['name']
headers = [resp[0] for resp in responses.values()]
cont_counts = [int(header['x-account-container-count'])
for header in headers]
for header in headers]
if len(set(cont_counts)) != 1:
self.account_container_mismatch += 1
consistent = False
Expand All @@ -276,7 +275,7 @@ class Auditor(object):
print " Max: %s, Min: %s" % (max(cont_counts),
min(cont_counts))
obj_counts = [int(header['x-account-object-count'])
for header in headers]
for header in headers]
if len(set(obj_counts)) != 1:
self.account_object_mismatch += 1
consistent = False
Expand Down
6 changes: 3 additions & 3 deletions bin/swift-dispersion-populate
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ if __name__ == '__main__':
account = url.rsplit('/', 1)[1]
connpool = Pool(max_size=concurrency)
connpool.create = lambda: Connection(conf['auth_url'],
conf['auth_user'], conf['auth_key'],
retries=retries,
preauthurl=url, preauthtoken=token)
conf['auth_user'], conf['auth_key'],
retries=retries,
preauthurl=url, preauthtoken=token)

container_ring = Ring(swift_dir, ring_name='container')
parts_left = dict((x, x) for x in xrange(container_ring.partition_count))
Expand Down
8 changes: 4 additions & 4 deletions bin/swift-drive-audit
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def get_devices(device_dir, logger):
except OSError, e:
# If we can't stat the device, then something weird is going on
logger.error("Error: Could not stat %s!" %
block_device)
block_device)
continue
device['major'] = str(os.major(device_num))
device['minor'] = str(os.minor(device_num))
devices.append(device)
for line in open('/proc/partitions').readlines()[2:]:
major, minor, blocks, kernel_device = line.strip().split()
device = [d for d in devices
if d['major'] == major and d['minor'] == minor]
if d['major'] == major and d['minor'] == minor]
if device:
device[0]['kernel_device'] = kernel_device
return devices
Expand Down Expand Up @@ -127,10 +127,10 @@ if __name__ == '__main__':
mount_point = device[0]['mount_point']
if mount_point.startswith(device_dir):
logger.info("Unmounting %s with %d errors" %
(mount_point, count))
(mount_point, count))
subprocess.call(['umount', '-fl', mount_point])
logger.info("Commenting out %s from /etc/fstab" %
(mount_point))
(mount_point))
comment_fstab(mount_point)
unmounts += 1
if unmounts == 0:
Expand Down
3 changes: 2 additions & 1 deletion bin/swift-form-signature
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ if __name__ == '__main__':
print ' Or: /v1/account/container/object_prefix'
exit(1)
sig = hmac.new(key, '%s\n%s\n%s\n%s\n%s' % (path, redirect, max_file_size,
max_file_count, expires), sha1).hexdigest()
max_file_count, expires),
sha1).hexdigest()
print ' Expires:', expires
print 'Signature:', sig
8 changes: 4 additions & 4 deletions bin/swift-get-nodes
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ parser.add_option('-p', '--partition', metavar='PARTITION',
if (len(args) < 2 or len(args) > 4) and \
(options.partition is None or not args):
print 'Usage: %s [-a] <ring.gz> <account> [<container>] [<object>]' \
% sys.argv[0]
% sys.argv[0]
print ' Or: %s [-a] <ring.gz> -p partition' % sys.argv[0]
print 'Shows the nodes responsible for the item specified.'
print 'Example:'
Expand Down Expand Up @@ -102,19 +102,19 @@ print 'Hash \t%s\n' % hash_str

for node in nodes:
print 'Server:Port Device\t%s:%s %s' % (node['ip'], node['port'],
node['device'])
node['device'])
for mnode in more_nodes:
print 'Server:Port Device\t%s:%s %s\t [Handoff]' \
% (mnode['ip'], mnode['port'], mnode['device'])
print "\n"
for node in nodes:
print 'curl -I -XHEAD "http://%s:%s/%s/%s/%s"' \
% (node['ip'], node['port'], node['device'], part,
urllib.quote(target))
urllib.quote(target))
for mnode in more_nodes:
print 'curl -I -XHEAD "http://%s:%s/%s/%s/%s" # [Handoff]' \
% (mnode['ip'], mnode['port'], mnode['device'], part,
urllib.quote(target))
urllib.quote(target))
print "\n"
for node in nodes:
if hash_str:
Expand Down
2 changes: 1 addition & 1 deletion bin/swift-object-info
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ if __name__ == '__main__':
part, nodes = ring.get_nodes(account, container, obj)
for node in nodes:
print (' %s:%s - /srv/node/%s/objects/%s/%s/%s/%s.data' %
(node['ip'], node['port'], node['device'], part,
(node['ip'], node['port'], node['device'], part,
obj_hash[-3:], obj_hash, ts))
else:
print 'Path: Not found in metadata'
Expand Down
7 changes: 4 additions & 3 deletions bin/swift-oldies
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ if __name__ == '__main__':
Lists old Swift processes.
'''.strip())
parser.add_option('-a', '--age', dest='hours', type='int', default=720,
help='look for processes at least HOURS old; default: 720 (30 days)')
help='look for processes at least HOURS old; '
'default: 720 (30 days)')
(options, args) = parser.parse_args()

listing = []
Expand All @@ -27,8 +28,8 @@ Lists old Swift processes.
etime, pid, args = line.split(None, 2)
except ValueError:
sys.exit('Could not process ps line %r' % line)
if (not args.startswith('/usr/bin/python /usr/bin/swift-') and
not args.startswith('/usr/bin/python /usr/local/bin/swift-')):
if not args.startswith('/usr/bin/python /usr/bin/swift-') and \
not args.startswith('/usr/bin/python /usr/local/bin/swift-'):
continue
args = args.split('-', 1)[1]
etime = etime.split('-')
Expand Down
13 changes: 8 additions & 5 deletions bin/swift-orphans
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ Example (sends SIGTERM to all orphaned Swift processes older than two hours):
%prog -a 2 -k TERM
'''.strip())
parser.add_option('-a', '--age', dest='hours', type='int', default=24,
help='look for processes at least HOURS old; default: 24')
help="look for processes at least HOURS old; "
"default: 24")
parser.add_option('-k', '--kill', dest='signal',
help='send SIGNAL to matched processes; default: just list process '
'information')
help='send SIGNAL to matched processes; default: just '
'list process information')
parser.add_option('-w', '--wide', dest='wide', default=False,
action='store_true', help="don't clip the listing at 80 characters")
action='store_true',
help="don't clip the listing at 80 characters")
(options, args) = parser.parse_args()

pids = []
Expand Down Expand Up @@ -95,7 +97,8 @@ Example (sends SIGTERM to all orphaned Swift processes older than two hours):
signum = int(options.signal)
except ValueError:
signum = getattr(signal, options.signal.upper(),
getattr(signal, 'SIG' + options.signal.upper(), None))
getattr(signal, 'SIG' + options.signal.upper(),
None))
if not signum:
sys.exit('Could not translate %r to a signal number.' %
options.signal)
Expand Down
Loading

0 comments on commit 35f4d29

Please sign in to comment.