From 9b687f2ed62781b6a78b3b869b0b62a1e2f9bba6 Mon Sep 17 00:00:00 2001 From: tobe Date: Wed, 27 Jul 2016 09:13:25 +0800 Subject: [PATCH] Replace simplejson with json and fix missed print statement --- .../harbor-py/harborclient/harborclient.py | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/contrib/sdk/harbor-py/harborclient/harborclient.py b/contrib/sdk/harbor-py/harborclient/harborclient.py index 91d8b5d58..31f9690bc 100755 --- a/contrib/sdk/harbor-py/harborclient/harborclient.py +++ b/contrib/sdk/harbor-py/harborclient/harborclient.py @@ -1,8 +1,8 @@ #!/usr/bin/env python -import requests -import simplejson +import json import logging +import requests logging.basicConfig(level=logging.INFO) @@ -52,7 +52,8 @@ class HarborClient(object): project_id, project_name)) return project_id else: - pritn("Fail to get project id from project name", project_name) + logging.error("Fail to get project id from project name", + project_name) return None # GET /search @@ -107,8 +108,8 @@ class HarborClient(object): def create_project(self, project_name, is_public=False): result = False path = '%s://%s/api/projects' % (self.protocol, self.host) - request_body = simplejson.dumps({'project_name': project_name, - 'public': is_public}) + request_body = json.dumps({'project_name': project_name, + 'public': is_public}) response = requests.post(path, cookies={'beegosessionID': self.session_id}, data=request_body) @@ -129,7 +130,7 @@ class HarborClient(object): result = False path = '%s://%s/api/projects/%s/publicity?project_id=%s' % ( self.protocol, self.host, project_id, project_id) - request_body = simplejson.dumps({'public': is_public}) + request_body = json.dumps({'public': is_public}) response = requests.put(path, cookies={'beegosessionID': self.session_id}, data=request_body) @@ -175,11 +176,11 @@ class HarborClient(object): def create_user(self, username, email, password, realname, comment): result = False path = '%s://%s/api/users' % (self.protocol, self.host) - request_body = simplejson.dumps({'username': username, - 'email': email, - 'password': password, - 'realname': realname, - 'comment': comment}) + request_body = json.dumps({'username': username, + 'email': email, + 'password': password, + 'realname': realname, + 'comment': comment}) response = requests.post(path, cookies={'beegosessionID': self.session_id}, data=request_body) @@ -199,9 +200,9 @@ class HarborClient(object): result = False path = '%s://%s/api/users/%s?user_id=%s' % (self.protocol, self.host, user_id, user_id) - request_body = simplejson.dumps({'email': email, - 'realname': realname, - 'comment': comment}) + request_body = json.dumps({'email': email, + 'realname': realname, + 'comment': comment}) response = requests.put(path, cookies={'beegosessionID': self.session_id}, data=request_body) @@ -236,8 +237,8 @@ class HarborClient(object): result = False path = '%s://%s/api/users/%s/password?user_id=%s' % ( self.protocol, self.host, user_id, user_id) - request_body = simplejson.dumps({'old_password': old_password, - 'new_password': new_password}) + request_body = json.dumps({'old_password': old_password, + 'new_password': new_password}) response = requests.put(path, cookies={'beegosessionID': self.session_id}, data=request_body)