From b15e9637dccb6e57747cea3886f52dda05eee4c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Nov=C3=BD?= <ondrej.novy@firma.seznam.cz>
Date: Thu, 19 Nov 2015 23:01:39 +0100
Subject: [PATCH] PEP8 for bin directory

Closes-Bug: #1516754
Change-Id: I548cf0e86aee57ede32eace505468026ca871fcd
---
 bin/swauth-add-account         |  4 ++--
 bin/swauth-add-user            | 11 ++++++-----
 bin/swauth-cleanup-tokens      | 36 +++++++++++++++++++---------------
 bin/swauth-delete-account      |  4 ++--
 bin/swauth-delete-user         |  4 ++--
 bin/swauth-list                |  4 ++--
 bin/swauth-prep                |  4 ++--
 bin/swauth-set-account-service |  7 ++++---
 tox.ini                        |  4 +++-
 9 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/bin/swauth-add-account b/bin/swauth-add-account
index 033b6cb..012ab20 100755
--- a/bin/swauth-add-account
+++ b/bin/swauth-add-account
@@ -17,8 +17,8 @@
 from getpass import getpass
 import gettext
 from optparse import OptionParser
-from os.path import basename
-from sys import argv, exit
+from sys import argv
+from sys import exit
 
 from swift.common.bufferedhttp import http_connect_raw as http_connect
 from swift.common.utils import urlparse
diff --git a/bin/swauth-add-user b/bin/swauth-add-user
index ec6ecec..28133ac 100755
--- a/bin/swauth-add-user
+++ b/bin/swauth-add-user
@@ -17,8 +17,8 @@
 from getpass import getpass
 import gettext
 from optparse import OptionParser
-from os.path import basename
-from sys import argv, exit
+from sys import argv
+from sys import exit
 
 from swift.common.bufferedhttp import http_connect_raw as http_connect
 from swift.common.utils import urlparse
@@ -81,11 +81,12 @@ if __name__ == '__main__':
         resp = conn.getresponse()
         if resp.status // 100 != 2:
             headers['Content-Length'] = '0'
-            conn = http_connect(parsed.hostname, parsed.port, 'PUT', path, headers,
-                                ssl=(parsed.scheme == 'https'))
+            conn = http_connect(parsed.hostname, parsed.port, 'PUT', path,
+                                headers, ssl=(parsed.scheme == 'https'))
             resp = conn.getresponse()
             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
     path = '%sv2/%s/%s' % (parsed_path, account, user)
     headers = {'X-Auth-Admin-User': options.admin_user,
diff --git a/bin/swauth-cleanup-tokens b/bin/swauth-cleanup-tokens
index 9b410d9..259558d 100755
--- a/bin/swauth-cleanup-tokens
+++ b/bin/swauth-cleanup-tokens
@@ -14,19 +14,23 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from datetime import datetime
+from datetime import timedelta
 try:
     import simplejson as json
 except ImportError:
     import json
 from getpass import getpass
 import gettext
-import re
-from datetime import datetime, timedelta
 from optparse import OptionParser
-from sys import argv, exit
-from time import sleep, time
+import re
+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__':
     gettext.install('swauth', unicode=1)
@@ -86,12 +90,12 @@ if __name__ == '__main__':
                     token = headers['x-object-meta-auth-token']
                     container = '.token_%s' % token[-1]
                     if options.verbose:
-                        print('%s/%s purge account %r; deleting' % \
+                        print('%s/%s purge account %r; deleting' %
                               (container, token, options.purge_account))
                     print('DELETE %s/%s' % (container, token))
                     try:
                         conn.delete_object(container, token)
-                    except ClientException, err:
+                    except ClientException as err:
                         if err.http_status != 404:
                             raise
                 continue
@@ -106,7 +110,7 @@ if __name__ == '__main__':
                 print('GET %s?marker=%s' % (container, marker))
             try:
                 objs = conn.get_container(container, marker=marker)[1]
-            except ClientException, e:
+            except ClientException as e:
                 if e.http_status == 404:
                     exit('Container %s not found. swauth-prep needs to be '
                         'rerun' % (container))
@@ -122,12 +126,12 @@ if __name__ == '__main__':
             for obj in objs:
                 if options.purge_all:
                     if options.verbose:
-                        print('%s/%s purge all; deleting' % \
+                        print('%s/%s purge all; deleting' %
                               (container, obj['name']))
                     print('DELETE %s/%s' % (container, obj['name']))
                     try:
                         conn.delete_object(container, obj['name'])
-                    except ClientException, err:
+                    except ClientException as err:
                         if err.http_status != 404:
                             raise
                     continue
@@ -136,7 +140,7 @@ if __name__ == '__main__':
                 ago = datetime.utcnow() - last_modified
                 if ago > options.token_life:
                     if options.verbose:
-                        print('%s/%s last modified %ss ago; investigating' % \
+                        print('%s/%s last modified %ss ago; investigating' %
                               (container, obj['name'],
                                ago.days * 86400 + ago.seconds))
                         print('GET %s/%s' % (container, obj['name']))
@@ -144,23 +148,23 @@ if __name__ == '__main__':
                     detail = json.loads(detail)
                     if detail['expires'] < time():
                         if options.verbose:
-                            print('%s/%s expired %ds ago; deleting' % \
+                            print('%s/%s expired %ds ago; deleting' %
                                   (container, obj['name'],
                                    time() - detail['expires']))
                         print('DELETE %s/%s' % (container, obj['name']))
                         try:
                             conn.delete_object(container, obj['name'])
-                        except ClientException, e:
+                        except ClientException as e:
                             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'],
                                     e.http_status))
                     elif options.verbose:
-                        print("%s/%s won't expire for %ds; skipping" % \
+                        print("%s/%s won't expire for %ds; skipping" %
                               (container, obj['name'],
                                detail['expires'] - time()))
                 elif options.verbose:
-                    print('%s/%s last modified %ss ago; skipping' % \
+                    print('%s/%s last modified %ss ago; skipping' %
                           (container, obj['name'],
                            ago.days * 86400 + ago.seconds))
                 sleep(options.sleep)
diff --git a/bin/swauth-delete-account b/bin/swauth-delete-account
index a3c68eb..380f315 100755
--- a/bin/swauth-delete-account
+++ b/bin/swauth-delete-account
@@ -17,8 +17,8 @@
 from getpass import getpass
 import gettext
 from optparse import OptionParser
-from os.path import basename
-from sys import argv, exit
+from sys import argv
+from sys import exit
 
 from swift.common.bufferedhttp import http_connect_raw as http_connect
 from swift.common.utils import urlparse
diff --git a/bin/swauth-delete-user b/bin/swauth-delete-user
index b8fbcbb..eb585af 100755
--- a/bin/swauth-delete-user
+++ b/bin/swauth-delete-user
@@ -17,8 +17,8 @@
 from getpass import getpass
 import gettext
 from optparse import OptionParser
-from os.path import basename
-from sys import argv, exit
+from sys import argv
+from sys import exit
 
 from swift.common.bufferedhttp import http_connect_raw as http_connect
 from swift.common.utils import urlparse
diff --git a/bin/swauth-list b/bin/swauth-list
index a9eb823..d7b968d 100755
--- a/bin/swauth-list
+++ b/bin/swauth-list
@@ -21,8 +21,8 @@ except ImportError:
 from getpass import getpass
 import gettext
 from optparse import OptionParser
-from os.path import basename
-from sys import argv, exit
+from sys import argv
+from sys import exit
 
 from swift.common.bufferedhttp import http_connect_raw as http_connect
 from swift.common.utils import urlparse
diff --git a/bin/swauth-prep b/bin/swauth-prep
index 61aeba0..6801b5e 100755
--- a/bin/swauth-prep
+++ b/bin/swauth-prep
@@ -17,8 +17,8 @@
 from getpass import getpass
 import gettext
 from optparse import OptionParser
-from os.path import basename
-from sys import argv, exit
+from sys import argv
+from sys import exit
 
 from swift.common.bufferedhttp import http_connect_raw as http_connect
 from swift.common.utils import urlparse
diff --git a/bin/swauth-set-account-service b/bin/swauth-set-account-service
index b43c8e3..63d2359 100755
--- a/bin/swauth-set-account-service
+++ b/bin/swauth-set-account-service
@@ -21,8 +21,8 @@ except ImportError:
 from getpass import getpass
 import gettext
 from optparse import OptionParser
-from os.path import basename
-from sys import argv, exit
+from sys import argv
+from sys import exit
 
 from swift.common.bufferedhttp import http_connect_raw as http_connect
 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.
 
-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())
     parser.add_option('-A', '--admin-url', dest='admin_url',
         default='http://127.0.0.1:8080/auth/', help='The URL to the auth '
diff --git a/tox.ini b/tox.ini
index 5070340..34533e9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -24,7 +24,9 @@ setenv = VIRTUAL_ENV={envdir}
          NOSE_COVER_HTML_DIR={toxinidir}/cover
 
 [testenv:pep8]
-commands = flake8 swauth test
+commands =
+    flake8 swauth test
+    flake8 --filename=swauth* bin
 
 [testenv:venv]
 commands = {posargs}