aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGöktürk Yüksek <gokturk@gentoo.org>2016-12-29 01:13:51 -0500
committerGöktürk Yüksek <gokturk@gentoo.org>2016-12-29 01:13:51 -0500
commitdad01a9243e6d217da18976b93dbb4f84cf93b44 (patch)
tree6359a08ff6e629b2a8563326950f5fe6305e26bb
parentclient/gentoostats/environment.py: fix getLastSync() (diff)
downloadgentoostats-dad01a9243e6d217da18976b93dbb4f84cf93b44.tar.gz
gentoostats-dad01a9243e6d217da18976b93dbb4f84cf93b44.tar.bz2
gentoostats-dad01a9243e6d217da18976b93dbb4f84cf93b44.zip
client: add support python3 compatibility
-rwxr-xr-xclient/gentoostats-cli6
-rwxr-xr-xclient/gentoostats-send19
-rw-r--r--client/gentoostats/list.py8
-rw-r--r--client/gentoostats/payload.py10
-rw-r--r--client/gentoostats/search.py5
-rw-r--r--client/gentoostats/utils.py7
6 files changed, 40 insertions, 15 deletions
diff --git a/client/gentoostats-cli b/client/gentoostats-cli
index a22ccc7..768a1ed 100755
--- a/client/gentoostats-cli
+++ b/client/gentoostats-cli
@@ -10,13 +10,15 @@ def main():
parser.add_argument('-s', '--server', default='soc.dev.gentoo.org')
parser.add_argument('-u', '--url', default='/gentoostats')
- subparsers = parser.add_subparsers()
+ # http://bugs.python.org/issue9253
+ subparsers = parser.add_subparsers(dest='command')
+ subparsers.required = True
list.add_parser(subparsers)
search.add_parser(subparsers)
args = parser.parse_args()
- args.func(args)
+ args.command(args)
if __name__ == "__main__":
main()
diff --git a/client/gentoostats-send b/client/gentoostats-send
index 2ae2857..eac742c 100755
--- a/client/gentoostats-send
+++ b/client/gentoostats-send
@@ -1,10 +1,21 @@
#!/usr/bin/env python
+from __future__ import print_function
+
import sys
import json
import argparse
-import ConfigParser
-import httplib
+
+try:
+ import configparser as ConfigParser
+except ImportError:
+ import ConfigParser
+
+try:
+ import http.client as httplib
+except ImportError:
+ import httplib
+
from gentoostats.payload import Payload
def getAuthInfo(auth):
@@ -67,8 +78,8 @@ def main():
conn = httplib.HTTPSConnection(args['server'] + ':' + str(args['port']))
conn.request('POST', url=post_url, headers=post_headers, body=post_body)
response = conn.getresponse()
- print response.status, response.reason
- print 'Server response: ' + response.read()
+ print(response.status, response.reason)
+ print('Server response: ' + response.read().decode("utf-8"))
except httplib.HTTPException:
sys.stderr.write('Something went wrong')
sys.exit(1)
diff --git a/client/gentoostats/list.py b/client/gentoostats/list.py
index 3140041..8c369ab 100644
--- a/client/gentoostats/list.py
+++ b/client/gentoostats/list.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
import pprint as pp
from gentoostats import utils
@@ -6,7 +7,7 @@ def pprint(title, object):
"""
Pretty printer for the decoded json data
"""
- print title
+ print(title)
pp.pprint(object)
def add_parser(subparsers):
@@ -14,7 +15,8 @@ def add_parser(subparsers):
Setup argparse parsers
"""
list_parser = subparsers.add_parser('list')
- list_subparsers = list_parser.add_subparsers()
+ list_subparsers = list_parser.add_subparsers(dest='subcommand')
+ list_subparsers.required = True
objects = {
'arch': ['parser_arch', list_arch],
@@ -27,7 +29,7 @@ def add_parser(subparsers):
}
for obj in objects.keys():
parser = vars()[objects[obj][0]] = list_subparsers.add_parser(obj)
- parser.set_defaults(func=objects[obj][1])
+ parser.set_defaults(command=objects[obj][1])
# need separate arguments for package
parser = vars()[objects['package'][0]]
diff --git a/client/gentoostats/payload.py b/client/gentoostats/payload.py
index b2c459f..569b69b 100644
--- a/client/gentoostats/payload.py
+++ b/client/gentoostats/payload.py
@@ -1,7 +1,13 @@
+from __future__ import print_function
import sys
import pprint
-import ConfigParser
+
+try:
+ import configparser as ConfigParser
+except ImportError:
+ import ConfigParser
+
from gentoostats.environment import Environment
from gentoostats.packages import Packages
from gentoostats.metadata import Metadata
@@ -79,4 +85,4 @@ class Payload(object):
if human:
pprint.pprint(self.payload)
else:
- print self.payload
+ print(self.payload)
diff --git a/client/gentoostats/search.py b/client/gentoostats/search.py
index c77c119..89b4d20 100644
--- a/client/gentoostats/search.py
+++ b/client/gentoostats/search.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
import pprint as pp
from gentoostats import utils
@@ -6,7 +7,7 @@ def pprint(title, object):
"""
Pretty printer for the decoded json data
"""
- print title
+ print(title)
pp.pprint(object)
def add_parser(subparsers):
@@ -20,7 +21,7 @@ def add_parser(subparsers):
search_parser.add_argument('-r', '--repo')
search_parser.add_argument('--min_hosts', type=int)
search_parser.add_argument('--max_hosts', type=int)
- search_parser.set_defaults(func=search)
+ search_parser.set_defaults(command=search)
def search(args):
"""
diff --git a/client/gentoostats/utils.py b/client/gentoostats/utils.py
index af807c8..af8dab2 100644
--- a/client/gentoostats/utils.py
+++ b/client/gentoostats/utils.py
@@ -1,6 +1,9 @@
import json
-import httplib
+try:
+ import http.client as httplib
+except ImportError:
+ import httplib
# json headers for gentoostats-cli
headers = {'Accept': 'application/json'}
@@ -15,7 +18,7 @@ def GET(server, url, headers, https=True):
conn = httplib.HTTPConnection(server)
try:
conn.request('GET', url=url, headers=headers)
- data = conn.getresponse().read()
+ data = conn.getresponse().read().decode("utf-8")
except httplib.HTTPException:
return None
finally: