Change print statement to function

Change-Id: I85948efa441aec13c0ab3cf50c66ac2cbc660d4b
This commit is contained in:
Ondřej Nový 2015-11-19 22:40:26 +01:00
parent 3e19273cc1
commit 911adf7299
3 changed files with 28 additions and 28 deletions

View File

@ -85,7 +85,7 @@ if __name__ == '__main__':
ssl=(parsed.scheme == 'https')) ssl=(parsed.scheme == 'https'))
resp = conn.getresponse() resp = conn.getresponse()
if resp.status // 100 != 2: if resp.status // 100 != 2:
print 'Account creation failed: %s %s' % (resp.status, resp.reason) print('Account creation failed: %s %s' % (resp.status, resp.reason))
# Add the user # Add the user
path = '%sv2/%s/%s' % (parsed_path, account, user) path = '%sv2/%s/%s' % (parsed_path, account, user)
headers = {'X-Auth-Admin-User': options.admin_user, headers = {'X-Auth-Admin-User': options.admin_user,

View File

@ -70,25 +70,25 @@ if __name__ == '__main__':
marker = None marker = None
while True: while True:
if options.verbose: if options.verbose:
print 'GET %s?marker=%s' % (options.purge_account, marker) print('GET %s?marker=%s' % (options.purge_account, marker))
objs = conn.get_container(options.purge_account, marker=marker)[1] objs = conn.get_container(options.purge_account, marker=marker)[1]
if objs: if objs:
marker = objs[-1]['name'] marker = objs[-1]['name']
else: else:
if options.verbose: if options.verbose:
print 'No more objects in %s' % options.purge_account print('No more objects in %s' % options.purge_account)
break break
for obj in objs: for obj in objs:
if options.verbose: if options.verbose:
print 'HEAD %s/%s' % (options.purge_account, obj['name']) print('HEAD %s/%s' % (options.purge_account, obj['name']))
headers = conn.head_object(options.purge_account, obj['name']) headers = conn.head_object(options.purge_account, obj['name'])
if 'x-object-meta-auth-token' in headers: if 'x-object-meta-auth-token' in headers:
token = headers['x-object-meta-auth-token'] token = headers['x-object-meta-auth-token']
container = '.token_%s' % token[-1] container = '.token_%s' % token[-1]
if options.verbose: if options.verbose:
print '%s/%s purge account %r; deleting' % \ print('%s/%s purge account %r; deleting' % \
(container, token, options.purge_account) (container, token, options.purge_account))
print 'DELETE %s/%s' % (container, token) print('DELETE %s/%s' % (container, token))
try: try:
conn.delete_object(container, token) conn.delete_object(container, token)
except ClientException, err: except ClientException, err:
@ -96,14 +96,14 @@ if __name__ == '__main__':
raise raise
continue continue
if options.verbose: if options.verbose:
print 'Done.' print('Done.')
exit(0) exit(0)
for x in xrange(16): for x in xrange(16):
container = '.token_%x' % x container = '.token_%x' % x
marker = None marker = None
while True: while True:
if options.verbose: if options.verbose:
print 'GET %s?marker=%s' % (container, marker) print('GET %s?marker=%s' % (container, marker))
try: try:
objs = conn.get_container(container, marker=marker)[1] objs = conn.get_container(container, marker=marker)[1]
except ClientException, e: except ClientException, e:
@ -117,14 +117,14 @@ if __name__ == '__main__':
marker = objs[-1]['name'] marker = objs[-1]['name']
else: else:
if options.verbose: if options.verbose:
print 'No more objects in %s' % container print('No more objects in %s' % container)
break break
for obj in objs: for obj in objs:
if options.purge_all: if options.purge_all:
if options.verbose: if options.verbose:
print '%s/%s purge all; deleting' % \ print('%s/%s purge all; deleting' % \
(container, obj['name']) (container, obj['name']))
print 'DELETE %s/%s' % (container, obj['name']) print('DELETE %s/%s' % (container, obj['name']))
try: try:
conn.delete_object(container, obj['name']) conn.delete_object(container, obj['name'])
except ClientException, err: except ClientException, err:
@ -136,33 +136,33 @@ if __name__ == '__main__':
ago = datetime.utcnow() - last_modified ago = datetime.utcnow() - last_modified
if ago > options.token_life: if ago > options.token_life:
if options.verbose: if options.verbose:
print '%s/%s last modified %ss ago; investigating' % \ print('%s/%s last modified %ss ago; investigating' % \
(container, obj['name'], (container, obj['name'],
ago.days * 86400 + ago.seconds) ago.days * 86400 + ago.seconds))
print 'GET %s/%s' % (container, obj['name']) print('GET %s/%s' % (container, obj['name']))
detail = conn.get_object(container, obj['name'])[1] detail = conn.get_object(container, obj['name'])[1]
detail = json.loads(detail) detail = json.loads(detail)
if detail['expires'] < time(): if detail['expires'] < time():
if options.verbose: if options.verbose:
print '%s/%s expired %ds ago; deleting' % \ print('%s/%s expired %ds ago; deleting' % \
(container, obj['name'], (container, obj['name'],
time() - detail['expires']) time() - detail['expires']))
print 'DELETE %s/%s' % (container, obj['name']) print('DELETE %s/%s' % (container, obj['name']))
try: try:
conn.delete_object(container, obj['name']) conn.delete_object(container, obj['name'])
except ClientException, e: except ClientException, e:
if e.http_status != 404: if e.http_status != 404:
print 'DELETE of %s/%s failed with status ' \ print('DELETE of %s/%s failed with status ' \
'code %d' % (container, obj['name'], 'code %d' % (container, obj['name'],
e.http_status) e.http_status))
elif options.verbose: elif options.verbose:
print "%s/%s won't expire for %ds; skipping" % \ print("%s/%s won't expire for %ds; skipping" % \
(container, obj['name'], (container, obj['name'],
detail['expires'] - time()) detail['expires'] - time()))
elif options.verbose: elif options.verbose:
print '%s/%s last modified %ss ago; skipping' % \ print('%s/%s last modified %ss ago; skipping' % \
(container, obj['name'], (container, obj['name'],
ago.days * 86400 + ago.seconds) ago.days * 86400 + ago.seconds))
sleep(options.sleep) sleep(options.sleep)
if options.verbose: if options.verbose:
print 'Done.' print('Done.')

View File

@ -84,6 +84,6 @@ If the [user] is '.groups', the active groups for the account will be listed.
if options.plain_text: if options.plain_text:
info = json.loads(body) info = json.loads(body)
for group in info[['accounts', 'users', 'groups'][len(args)]]: for group in info[['accounts', 'users', 'groups'][len(args)]]:
print group['name'] print(group['name'])
else: else:
print body print(body)