PEP8 for bin directory
Closes-Bug: #1516754 Change-Id: I548cf0e86aee57ede32eace505468026ca871fcd
This commit is contained in:
parent
911adf7299
commit
b15e9637dc
@ -17,8 +17,8 @@
|
|||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
import gettext
|
import gettext
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from os.path import basename
|
from sys import argv
|
||||||
from sys import argv, exit
|
from sys import exit
|
||||||
|
|
||||||
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
||||||
from swift.common.utils import urlparse
|
from swift.common.utils import urlparse
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
import gettext
|
import gettext
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from os.path import basename
|
from sys import argv
|
||||||
from sys import argv, exit
|
from sys import exit
|
||||||
|
|
||||||
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
||||||
from swift.common.utils import urlparse
|
from swift.common.utils import urlparse
|
||||||
@ -81,11 +81,12 @@ if __name__ == '__main__':
|
|||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
if resp.status // 100 != 2:
|
if resp.status // 100 != 2:
|
||||||
headers['Content-Length'] = '0'
|
headers['Content-Length'] = '0'
|
||||||
conn = http_connect(parsed.hostname, parsed.port, 'PUT', path, headers,
|
conn = http_connect(parsed.hostname, parsed.port, 'PUT', path,
|
||||||
ssl=(parsed.scheme == 'https'))
|
headers, 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,
|
||||||
|
@ -14,19 +14,23 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
from datetime import timedelta
|
||||||
try:
|
try:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import json
|
import json
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
import gettext
|
import gettext
|
||||||
import re
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from sys import argv, exit
|
import re
|
||||||
from time import sleep, time
|
from sys import argv
|
||||||
|
from sys import exit
|
||||||
|
from time import sleep
|
||||||
|
from time import time
|
||||||
|
|
||||||
from swiftclient.client import Connection, ClientException
|
from swiftclient.client import ClientException
|
||||||
|
from swiftclient.client import Connection
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
gettext.install('swauth', unicode=1)
|
gettext.install('swauth', unicode=1)
|
||||||
@ -86,12 +90,12 @@ if __name__ == '__main__':
|
|||||||
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 as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
continue
|
continue
|
||||||
@ -106,7 +110,7 @@ if __name__ == '__main__':
|
|||||||
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 as e:
|
||||||
if e.http_status == 404:
|
if e.http_status == 404:
|
||||||
exit('Container %s not found. swauth-prep needs to be '
|
exit('Container %s not found. swauth-prep needs to be '
|
||||||
'rerun' % (container))
|
'rerun' % (container))
|
||||||
@ -122,12 +126,12 @@ if __name__ == '__main__':
|
|||||||
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 as err:
|
||||||
if err.http_status != 404:
|
if err.http_status != 404:
|
||||||
raise
|
raise
|
||||||
continue
|
continue
|
||||||
@ -136,7 +140,7 @@ 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']))
|
||||||
@ -144,23 +148,23 @@ if __name__ == '__main__':
|
|||||||
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 as 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)
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
import gettext
|
import gettext
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from os.path import basename
|
from sys import argv
|
||||||
from sys import argv, exit
|
from sys import exit
|
||||||
|
|
||||||
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
||||||
from swift.common.utils import urlparse
|
from swift.common.utils import urlparse
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
import gettext
|
import gettext
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from os.path import basename
|
from sys import argv
|
||||||
from sys import argv, exit
|
from sys import exit
|
||||||
|
|
||||||
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
||||||
from swift.common.utils import urlparse
|
from swift.common.utils import urlparse
|
||||||
|
@ -21,8 +21,8 @@ except ImportError:
|
|||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
import gettext
|
import gettext
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from os.path import basename
|
from sys import argv
|
||||||
from sys import argv, exit
|
from sys import exit
|
||||||
|
|
||||||
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
||||||
from swift.common.utils import urlparse
|
from swift.common.utils import urlparse
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
import gettext
|
import gettext
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from os.path import basename
|
from sys import argv
|
||||||
from sys import argv, exit
|
from sys import exit
|
||||||
|
|
||||||
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
||||||
from swift.common.utils import urlparse
|
from swift.common.utils import urlparse
|
||||||
|
@ -21,8 +21,8 @@ except ImportError:
|
|||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
import gettext
|
import gettext
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from os.path import basename
|
from sys import argv
|
||||||
from sys import argv, exit
|
from sys import exit
|
||||||
|
|
||||||
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
from swift.common.bufferedhttp import http_connect_raw as http_connect
|
||||||
from swift.common.utils import urlparse
|
from swift.common.utils import urlparse
|
||||||
@ -35,7 +35,8 @@ Usage: %prog [options] <account> <service> <name> <value>
|
|||||||
|
|
||||||
Sets a service URL for an account. Can only be set by a reseller admin.
|
Sets a service URL for an account. Can only be set by a reseller admin.
|
||||||
|
|
||||||
Example: %prog -K swauthkey test storage local http://127.0.0.1:8080/v1/AUTH_018c3946-23f8-4efb-a8fb-b67aae8e4162
|
Example: %prog -K swauthkey test storage local
|
||||||
|
http://127.0.0.1:8080/v1/AUTH_018c3946-23f8-4efb-a8fb-b67aae8e4162
|
||||||
'''.strip())
|
'''.strip())
|
||||||
parser.add_option('-A', '--admin-url', dest='admin_url',
|
parser.add_option('-A', '--admin-url', dest='admin_url',
|
||||||
default='http://127.0.0.1:8080/auth/', help='The URL to the auth '
|
default='http://127.0.0.1:8080/auth/', help='The URL to the auth '
|
||||||
|
4
tox.ini
4
tox.ini
@ -24,7 +24,9 @@ setenv = VIRTUAL_ENV={envdir}
|
|||||||
NOSE_COVER_HTML_DIR={toxinidir}/cover
|
NOSE_COVER_HTML_DIR={toxinidir}/cover
|
||||||
|
|
||||||
[testenv:pep8]
|
[testenv:pep8]
|
||||||
commands = flake8 swauth test
|
commands =
|
||||||
|
flake8 swauth test
|
||||||
|
flake8 --filename=swauth* bin
|
||||||
|
|
||||||
[testenv:venv]
|
[testenv:venv]
|
||||||
commands = {posargs}
|
commands = {posargs}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user