1
0
mirror of https://github.com/gryf/ferrit.git synced 2026-02-07 08:45:53 +01:00

Make http server to use class, instead functions.

This commit is contained in:
2019-10-28 18:40:08 +01:00
parent 9317dc9ef3
commit 0f70f075d5
3 changed files with 72 additions and 45 deletions

0
generate_event.py Normal file → Executable file
View File

117
gerrit_fake_http_server.py Normal file → Executable file
View File

@@ -1,54 +1,81 @@
import logging
import os
import bottle
@bottle.route('/plugins/events-log/')
def events_log(params=None):
return ''
FILE_DIR = os.path.dirname(__file__)
BASE_NAME = os.path.extsep.join(os.path.basename(__file__)
.split(os.path.extsep)[:-1])
LOG = logging.getLogger('bottle')
LOG.setLevel(logging.DEBUG)
handler = logging.FileHandler(os.path.join(FILE_DIR, BASE_NAME + '.log'))
handler.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] '
'%(filename)s:%(lineno)s - '
'%(message)s'))
LOG.addHandler(handler)
@bottle.route('/a/projects/')
def projects(params=None):
"""
Possible params (accessible via bottle.request.params) is 'd'
"""
return {"All-Projects": {"id": "All-Projects",
"description": "all projects",
"state": "ACTIVE",
"web_links": [{"name": "browse",
"url":
"/plugins/gitiles/All-Projects",
"target": "_blank"}]},
"All-Users": {"id": "All-Users",
"description": "users",
"state": "ACTIVE",
"web_links": [{"name": "browse",
"url": "/plugins/gitiles/All-Users",
"target": "_blank"}]},
"DEDICATED": {"id": "DEDICATED",
"state": "ACTIVE",
"web_links": [{"name": "browse",
"url": "/plugins/gitiles/DEDICATED",
"target": "_blank"}]}}
class App(bottle.Bottle):
def __init__(self):
super(App, self).__init__()
self.get('/<cos>', callback=self._hello)
self.route('/Documentation/<whatever>', callback=self._documentation)
self.route('/plugins/events-log/', callback=self._events_log)
self.route('/plugins/events-log/events/', callback=self._events)
self.route('/a/projects/', callback=self._projects)
self.post('/a/changes/<project>~<branch>~<id>/revisions/<commit_id>'
'/review', callback=self._changes)
def _hello(self, cos):
return {'data': {'foo': 'bar', 'baz': True, 'param': cos}}
def _documentation(self, whatever, params=None):
return ''
def _events_log(params=None):
return ''
def _events(self, t1=None):
__import__('pdb').set_trace()
return {}
def _projects(params=None):
"""
Possible params (accessible via bottle.request.params) is 'd'
"""
return {"All-Projects": {"id": "All-Projects",
"description": "all projects",
"state": "ACTIVE",
"web_links": [{"name": "browse",
"url":
"/plugins/gitiles/All-"
"Projects",
"target": "_blank"}]},
"All-Users": {"id": "All-Users",
"description": "users",
"state": "ACTIVE",
"web_links": [{"name": "browse",
"url": "/plugins/gitiles/i"
"All-Users",
"target": "_blank"}]}}
def _changes(self, project, branch, id, commit_id):
# We are looking for labels in the json
labels = bottle.request.json.get('labels', {})
if not labels:
return
if labels.get('Verified') == 1:
LOG.info('True')
else:
LOG.info('False')
@bottle.post('/a/changes/<project>~<branch>~<id>/revisions/<commit_id>/review')
def changes(project, branch, id, commit_id):
# We are looking for labels in the json
labels = bottle.request.json.get('labels', {})
if not labels:
return
# TODO(gryf): It's on gerrit side now. What we do with this information on
# Ferrit? Verified is either 1 or -1, which indicates build in jenkins
if labels.get('Verified') == 1:
return True
else:
return False
def main():
app = App()
app.run(port=8181, host='localhost', debug=True)
@bottle.route('/a/plugins/events-log/events/')
def events(t1=None):
return {}
bottle.run(host='localhost', port=8181, debug=True)
if __name__ == "__main__":
main()

0
gerrit_fake_ssh_server.py Normal file → Executable file
View File