7a4042ee43
Split gerrit client across 3 files Rework gerrit_client.py toward simple and direct interface between functional code and Gerrit Rest API Pull common utility functions into utils.py Add gerrit_info_provider.py and pull parsing changed modules from review into it Add DependencyProvider and its initial implementation Closes-Bug: #1551640 Change-Id: I54efc625ff74037a88efe64795bd151be3f4ba89
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
# Copyright 2016 Mirantis, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import json
|
|
|
|
|
|
def check_status_code(code):
|
|
def outer_wrap(f):
|
|
def inner_wrap(*args, **kwargs):
|
|
r = f(*args, **kwargs)
|
|
if r.status_code != code:
|
|
raise Exception("Unexpected status code. "
|
|
"Wanted status code: {0}. "
|
|
"Got status code: {1}"
|
|
.format(code, r.status_code))
|
|
return r
|
|
return inner_wrap
|
|
return outer_wrap
|
|
|
|
|
|
def json_to_dict(data):
|
|
return dict(json.loads(data))
|
|
|
|
|
|
def filter_gerrit_response_separator(data):
|
|
return data.replace(")]}\'", "")
|
|
|
|
|
|
def filter_newlines(data):
|
|
return data.replace('\n', '')
|
|
|
|
|
|
def filter_response_text(data):
|
|
data = filter_gerrit_response_separator(data)
|
|
data = filter_newlines(data)
|
|
return data
|