diff options
| author | Simeon Simeonov | 2014-05-08 10:25:39 +0200 |
|---|---|---|
| committer | Simeon Simeonov | 2014-05-08 10:25:39 +0200 |
| commit | e4e15e7f4e594efc899016ba17cabd02fa344600 (patch) | |
| tree | a90786c2a56c288c0e0f541f6b9a1f0c81dedec5 /beinc_generic_client.py | |
| parent | 60f47b04174d016cc86c6e06fdaf0794c3d14216 (diff) | |
Forcing PEP8 compatibility
Diffstat (limited to 'beinc_generic_client.py')
| -rwxr-xr-x | beinc_generic_client.py | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/beinc_generic_client.py b/beinc_generic_client.py index 6cffc84..39e0fe8 100755 --- a/beinc_generic_client.py +++ b/beinc_generic_client.py | |||
| @@ -55,7 +55,6 @@ class ValidHTTPSConnection(httplib.HTTPConnection): | |||
| 55 | cert_reqs=ssl.CERT_REQUIRED) | 55 | cert_reqs=ssl.CERT_REQUIRED) |
| 56 | 56 | ||
| 57 | 57 | ||
| 58 | |||
| 59 | class ValidHTTPSHandler(urllib2.HTTPSHandler): | 58 | class ValidHTTPSHandler(urllib2.HTTPSHandler): |
| 60 | """ | 59 | """ |
| 61 | Implements a simple CERT verification functionality | 60 | Implements a simple CERT verification functionality |
| @@ -65,7 +64,6 @@ class ValidHTTPSHandler(urllib2.HTTPSHandler): | |||
| 65 | return self.do_open(ValidHTTPSConnection, req) | 64 | return self.do_open(ValidHTTPSConnection, req) |
| 66 | 65 | ||
| 67 | 66 | ||
| 68 | |||
| 69 | def action_push(args): | 67 | def action_push(args): |
| 70 | """ | 68 | """ |
| 71 | """ | 69 | """ |
| @@ -90,66 +88,57 @@ def action_push(args): | |||
| 90 | print('Body:\n{0}'.format(response.read())) | 88 | print('Body:\n{0}'.format(response.read())) |
| 91 | response.close() | 89 | response.close() |
| 92 | except urllib2.HTTPError as e: | 90 | except urllib2.HTTPError as e: |
| 93 | sys.stderr.write('BEINC-server error ({0} - {1})\n'.format(e.code, e.reason)) | 91 | sys.stderr.write('BEINC-server error ({0} - {1})\n'.format(e.code, |
| 92 | e.reason)) | ||
| 94 | except Exception as e: | 93 | except Exception as e: |
| 95 | sys.stderr.write('BEINC generic client error: {0}\n'.format(e)) | 94 | sys.stderr.write('BEINC generic client error: {0}\n'.format(e)) |
| 96 | sys.exit(errno.EPERM) | 95 | sys.exit(errno.EPERM) |
| 97 | 96 | ||
| 98 | 97 | ||
| 99 | def main(): | 98 | def main(): |
| 100 | |||
| 101 | parser = argparse.ArgumentParser( | 99 | parser = argparse.ArgumentParser( |
| 102 | description='The following options are available') | 100 | description='The following options are available') |
| 103 | |||
| 104 | parser.add_argument('url', | 101 | parser.add_argument('url', |
| 105 | metavar='URL', | 102 | metavar='URL', |
| 106 | type=str, | 103 | type=str, |
| 107 | #dest='url', | 104 | #dest='url', |
| 108 | #required=True, | 105 | #required=True, |
| 109 | help='Destination URL') | 106 | help='Destination URL') |
| 110 | |||
| 111 | parser.add_argument('-c', '--cert-file', | 107 | parser.add_argument('-c', '--cert-file', |
| 112 | metavar='FILE', | 108 | metavar='FILE', |
| 113 | type=str, | 109 | type=str, |
| 114 | dest='cert', | 110 | dest='cert', |
| 115 | default='', | 111 | default='', |
| 116 | help='BEINC CA-cert to check the server-cert against') | 112 | help='BEINC CA-cert to check the server-cert against') |
| 117 | |||
| 118 | parser.add_argument('-m', '--message', | 113 | parser.add_argument('-m', '--message', |
| 119 | metavar='MESSAGE', | 114 | metavar='MESSAGE', |
| 120 | type=str, | 115 | type=str, |
| 121 | dest='message', | 116 | dest='message', |
| 122 | default='BEINC message', | 117 | default='BEINC message', |
| 123 | help='BEINC message') | 118 | help='BEINC message') |
| 124 | |||
| 125 | parser.add_argument('-p', '--password', | 119 | parser.add_argument('-p', '--password', |
| 126 | metavar='PASSWORD', | 120 | metavar='PASSWORD', |
| 127 | type=str, | 121 | type=str, |
| 128 | dest='password', | 122 | dest='password', |
| 129 | default='', | 123 | default='', |
| 130 | help='Password') | 124 | help='Password') |
| 131 | |||
| 132 | parser.add_argument('-t', '--title', | 125 | parser.add_argument('-t', '--title', |
| 133 | metavar='TITLE', | 126 | metavar='TITLE', |
| 134 | type=str, | 127 | type=str, |
| 135 | dest='title', | 128 | dest='title', |
| 136 | default='BEINC title', | 129 | default='BEINC title', |
| 137 | help='BEINC title') | 130 | help='BEINC title') |
| 138 | |||
| 139 | parser.add_argument('-v', '--version', | 131 | parser.add_argument('-v', '--version', |
| 140 | action='version', | 132 | action='version', |
| 141 | version='%(prog)s {0}'.format(__version__), | 133 | version='%(prog)s {0}'.format(__version__), |
| 142 | help='display program-version and exit') | 134 | help='display program-version and exit') |
| 143 | |||
| 144 | args = parser.parse_args() | 135 | args = parser.parse_args() |
| 145 | |||
| 146 | if not args.password: | 136 | if not args.password: |
| 147 | try: | 137 | try: |
| 148 | args.password = getpass.getpass() | 138 | args.password = getpass.getpass() |
| 149 | except Exception as e: | 139 | except Exception as e: |
| 150 | sys.stderr.write('Prompt terminated\n') | 140 | sys.stderr.write('Prompt terminated\n') |
| 151 | sys.exit(errno.EACCES) | 141 | sys.exit(errno.EACCES) |
| 152 | |||
| 153 | action_push(args) | 142 | action_push(args) |
| 154 | sys.exit(0) | 143 | sys.exit(0) |
| 155 | 144 | ||
