Replace simplejson with json and fix missed print statement

This commit is contained in:
tobe 2016-07-27 09:13:25 +08:00
parent 405f013e7a
commit 9b687f2ed6

View File

@ -1,8 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
import requests import json
import simplejson
import logging import logging
import requests
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
@ -52,7 +52,8 @@ class HarborClient(object):
project_id, project_name)) project_id, project_name))
return project_id return project_id
else: 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 return None
# GET /search # GET /search
@ -107,7 +108,7 @@ class HarborClient(object):
def create_project(self, project_name, is_public=False): def create_project(self, project_name, is_public=False):
result = False result = False
path = '%s://%s/api/projects' % (self.protocol, self.host) path = '%s://%s/api/projects' % (self.protocol, self.host)
request_body = simplejson.dumps({'project_name': project_name, request_body = json.dumps({'project_name': project_name,
'public': is_public}) 'public': is_public})
response = requests.post(path, response = requests.post(path,
cookies={'beegosessionID': self.session_id}, cookies={'beegosessionID': self.session_id},
@ -129,7 +130,7 @@ class HarborClient(object):
result = False result = False
path = '%s://%s/api/projects/%s/publicity?project_id=%s' % ( path = '%s://%s/api/projects/%s/publicity?project_id=%s' % (
self.protocol, self.host, project_id, project_id) 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, response = requests.put(path,
cookies={'beegosessionID': self.session_id}, cookies={'beegosessionID': self.session_id},
data=request_body) data=request_body)
@ -175,7 +176,7 @@ class HarborClient(object):
def create_user(self, username, email, password, realname, comment): def create_user(self, username, email, password, realname, comment):
result = False result = False
path = '%s://%s/api/users' % (self.protocol, self.host) path = '%s://%s/api/users' % (self.protocol, self.host)
request_body = simplejson.dumps({'username': username, request_body = json.dumps({'username': username,
'email': email, 'email': email,
'password': password, 'password': password,
'realname': realname, 'realname': realname,
@ -199,7 +200,7 @@ class HarborClient(object):
result = False result = False
path = '%s://%s/api/users/%s?user_id=%s' % (self.protocol, self.host, path = '%s://%s/api/users/%s?user_id=%s' % (self.protocol, self.host,
user_id, user_id) user_id, user_id)
request_body = simplejson.dumps({'email': email, request_body = json.dumps({'email': email,
'realname': realname, 'realname': realname,
'comment': comment}) 'comment': comment})
response = requests.put(path, response = requests.put(path,
@ -236,7 +237,7 @@ class HarborClient(object):
result = False result = False
path = '%s://%s/api/users/%s/password?user_id=%s' % ( path = '%s://%s/api/users/%s/password?user_id=%s' % (
self.protocol, self.host, user_id, user_id) self.protocol, self.host, user_id, user_id)
request_body = simplejson.dumps({'old_password': old_password, request_body = json.dumps({'old_password': old_password,
'new_password': new_password}) 'new_password': new_password})
response = requests.put(path, response = requests.put(path,
cookies={'beegosessionID': self.session_id}, cookies={'beegosessionID': self.session_id},