mirror of
https://github.com/gryf/ferrit.git
synced 2026-03-23 10:43:31 +01:00
Make http server to use class, instead functions.
This commit is contained in:
0
generate_event.py
Normal file → Executable file
0
generate_event.py
Normal file → Executable file
117
gerrit_fake_http_server.py
Normal file → Executable file
117
gerrit_fake_http_server.py
Normal file → Executable file
@@ -1,54 +1,81 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
import bottle
|
import bottle
|
||||||
|
|
||||||
|
|
||||||
@bottle.route('/plugins/events-log/')
|
FILE_DIR = os.path.dirname(__file__)
|
||||||
def events_log(params=None):
|
BASE_NAME = os.path.extsep.join(os.path.basename(__file__)
|
||||||
return ''
|
.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/')
|
class App(bottle.Bottle):
|
||||||
def projects(params=None):
|
def __init__(self):
|
||||||
"""
|
super(App, self).__init__()
|
||||||
Possible params (accessible via bottle.request.params) is 'd'
|
self.get('/<cos>', callback=self._hello)
|
||||||
"""
|
self.route('/Documentation/<whatever>', callback=self._documentation)
|
||||||
return {"All-Projects": {"id": "All-Projects",
|
self.route('/plugins/events-log/', callback=self._events_log)
|
||||||
"description": "all projects",
|
self.route('/plugins/events-log/events/', callback=self._events)
|
||||||
"state": "ACTIVE",
|
self.route('/a/projects/', callback=self._projects)
|
||||||
"web_links": [{"name": "browse",
|
self.post('/a/changes/<project>~<branch>~<id>/revisions/<commit_id>'
|
||||||
"url":
|
'/review', callback=self._changes)
|
||||||
"/plugins/gitiles/All-Projects",
|
|
||||||
"target": "_blank"}]},
|
def _hello(self, cos):
|
||||||
"All-Users": {"id": "All-Users",
|
return {'data': {'foo': 'bar', 'baz': True, 'param': cos}}
|
||||||
"description": "users",
|
|
||||||
"state": "ACTIVE",
|
def _documentation(self, whatever, params=None):
|
||||||
"web_links": [{"name": "browse",
|
return ''
|
||||||
"url": "/plugins/gitiles/All-Users",
|
|
||||||
"target": "_blank"}]},
|
def _events_log(params=None):
|
||||||
"DEDICATED": {"id": "DEDICATED",
|
return ''
|
||||||
"state": "ACTIVE",
|
|
||||||
"web_links": [{"name": "browse",
|
def _events(self, t1=None):
|
||||||
"url": "/plugins/gitiles/DEDICATED",
|
__import__('pdb').set_trace()
|
||||||
"target": "_blank"}]}}
|
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 main():
|
||||||
def changes(project, branch, id, commit_id):
|
app = App()
|
||||||
# We are looking for labels in the json
|
app.run(port=8181, host='localhost', debug=True)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
@bottle.route('/a/plugins/events-log/events/')
|
if __name__ == "__main__":
|
||||||
def events(t1=None):
|
main()
|
||||||
return {}
|
|
||||||
|
|
||||||
|
|
||||||
bottle.run(host='localhost', port=8181, debug=True)
|
|
||||||
|
|||||||
0
gerrit_fake_ssh_server.py
Normal file → Executable file
0
gerrit_fake_ssh_server.py
Normal file → Executable file
Reference in New Issue
Block a user