mirror of
https://github.com/gryf/ferrit.git
synced 2026-02-18 07:55:47 +01:00
Add main service which will launch both http and ssh services.
This commit is contained in:
@@ -4,6 +4,8 @@ import os
|
|||||||
import bottle
|
import bottle
|
||||||
|
|
||||||
|
|
||||||
|
# This global variable meant to be set in module, which imports this one
|
||||||
|
FIFO = None
|
||||||
FILE_DIR = os.path.dirname(__file__)
|
FILE_DIR = os.path.dirname(__file__)
|
||||||
BASE_NAME = os.path.extsep.join(os.path.basename(__file__)
|
BASE_NAME = os.path.extsep.join(os.path.basename(__file__)
|
||||||
.split(os.path.extsep)[:-1])
|
.split(os.path.extsep)[:-1])
|
||||||
@@ -19,7 +21,6 @@ LOG.addHandler(handler)
|
|||||||
class App(bottle.Bottle):
|
class App(bottle.Bottle):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(App, self).__init__()
|
super(App, self).__init__()
|
||||||
self.get('/<cos>', callback=self._hello)
|
|
||||||
self.route('/Documentation/<whatever>', callback=self._documentation)
|
self.route('/Documentation/<whatever>', callback=self._documentation)
|
||||||
self.route('/plugins/events-log/', callback=self._events_log)
|
self.route('/plugins/events-log/', callback=self._events_log)
|
||||||
self.route('/plugins/events-log/events/', callback=self._events)
|
self.route('/plugins/events-log/events/', callback=self._events)
|
||||||
@@ -27,9 +28,6 @@ class App(bottle.Bottle):
|
|||||||
self.post('/a/changes/<project>~<branch>~<id>/revisions/<commit_id>'
|
self.post('/a/changes/<project>~<branch>~<id>/revisions/<commit_id>'
|
||||||
'/review', callback=self._changes)
|
'/review', callback=self._changes)
|
||||||
|
|
||||||
def _hello(self, cos):
|
|
||||||
return {'data': {'foo': 'bar', 'baz': True, 'param': cos}}
|
|
||||||
|
|
||||||
def _documentation(self, whatever, params=None):
|
def _documentation(self, whatever, params=None):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
@@ -37,7 +35,6 @@ class App(bottle.Bottle):
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
def _events(self, t1=None):
|
def _events(self, t1=None):
|
||||||
__import__('pdb').set_trace()
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def _projects(params=None):
|
def _projects(params=None):
|
||||||
@@ -56,9 +53,15 @@ class App(bottle.Bottle):
|
|||||||
"description": "users",
|
"description": "users",
|
||||||
"state": "ACTIVE",
|
"state": "ACTIVE",
|
||||||
"web_links": [{"name": "browse",
|
"web_links": [{"name": "browse",
|
||||||
"url": "/plugins/gitiles/i"
|
"url": "/plugins/gitiles/"
|
||||||
"All-Users",
|
"All-Users",
|
||||||
"target": "_blank"}]}}
|
"target": "_blank"}]},
|
||||||
|
"example": {"id": "example",
|
||||||
|
"description": "example ptoject",
|
||||||
|
"state": "ACTIVE",
|
||||||
|
"web_links": [{"name": "browse",
|
||||||
|
"url": "/plugins/gitiles/example",
|
||||||
|
"target": "_blank"}]}}
|
||||||
|
|
||||||
def _changes(self, project, branch, id, commit_id):
|
def _changes(self, project, branch, id, commit_id):
|
||||||
# We are looking for labels in the json
|
# We are looking for labels in the json
|
||||||
@@ -74,8 +77,11 @@ class App(bottle.Bottle):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
app = App()
|
app = App()
|
||||||
app.run(port=8181, host='localhost', debug=True)
|
app.run(port=8181, host='localhost', debug=False, quiet=True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
# development version, meant to be run as stand alone module, like
|
||||||
|
# python -m ferrit.http
|
||||||
|
app = App()
|
||||||
|
app.run(port=8181, host='localhost', debug=True, reloader=True)
|
||||||
|
|||||||
32
ferrit/service.py
Normal file
32
ferrit/service.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
import multiprocessing
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from ferrit import ssh
|
||||||
|
from ferrit import http
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
fd, fifo = tempfile.mkstemp(suffix='.fifo', prefix='ferrit.')
|
||||||
|
os.close(fd)
|
||||||
|
os.unlink(fifo)
|
||||||
|
os.mkfifo(fifo)
|
||||||
|
ssh.FIFO = fifo
|
||||||
|
http.FIFO = fifo
|
||||||
|
try:
|
||||||
|
p1 = multiprocessing.Process(target=ssh.main)
|
||||||
|
p1.daemon = True
|
||||||
|
p1.start()
|
||||||
|
p2 = multiprocessing.Process(target=http.main)
|
||||||
|
p2.daemon = False
|
||||||
|
p2.start()
|
||||||
|
|
||||||
|
p1.join()
|
||||||
|
p2.join()
|
||||||
|
except Exception:
|
||||||
|
os.unlink(fifo)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import socketserver
|
import socketserver
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
@@ -12,24 +10,21 @@ import traceback
|
|||||||
import paramiko
|
import paramiko
|
||||||
|
|
||||||
|
|
||||||
|
# This global variable meant to be set in module, which imports this one
|
||||||
|
FIFO = None
|
||||||
|
|
||||||
# it could be even 29418, which is standard gerrit port
|
# it could be even 29418, which is standard gerrit port
|
||||||
PORT = 2200
|
PORT = 2200
|
||||||
|
|
||||||
FILE_DIR = os.path.dirname(__file__)
|
FILE_DIR = os.path.dirname(__file__)
|
||||||
BASE_NAME = os.path.extsep.join(os.path.basename(__file__)
|
BASE_NAME = os.path.extsep.join(os.path.basename(__file__)
|
||||||
.split(os.path.extsep)[:-1])
|
.split(os.path.extsep)[:-1])
|
||||||
HOST_KEY = paramiko.RSAKey(filename=os.path.join(FILE_DIR,
|
# TODO(gryf): make the path to the key configurable
|
||||||
'gerrit-server-key'),
|
HOST_KEY = paramiko.RSAKey(filename='gerrit-server-key', password='jenkins')
|
||||||
password='jenkins')
|
|
||||||
fd, FIFO = tempfile.mkstemp(suffix='.fifo', prefix='ferrit.')
|
|
||||||
os.close(fd)
|
|
||||||
os.unlink(FIFO)
|
|
||||||
|
|
||||||
GERRIT_CMD_PROJECTS = """All-Projects
|
GERRIT_CMD_PROJECTS = """All-Projects
|
||||||
All-Users
|
All-Users
|
||||||
openstack
|
example
|
||||||
openstack/nova
|
|
||||||
openstack/neutron
|
|
||||||
"""
|
"""
|
||||||
GERRIT_CMD_VERSION = "ferrit version 0.0.1\n"
|
GERRIT_CMD_VERSION = "ferrit version 0.0.1\n"
|
||||||
GERRIT_SHELL_MSG = """\r
|
GERRIT_SHELL_MSG = """\r
|
||||||
@@ -51,11 +46,6 @@ handler.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] '
|
|||||||
'%(filename)s:%(lineno)s - '
|
'%(filename)s:%(lineno)s - '
|
||||||
'%(message)s'))
|
'%(message)s'))
|
||||||
LOG.addHandler(handler)
|
LOG.addHandler(handler)
|
||||||
handler = logging.StreamHandler(sys.stdout)
|
|
||||||
handler.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] '
|
|
||||||
'%(filename)s:%(lineno)s - '
|
|
||||||
'%(message)s'))
|
|
||||||
LOG.addHandler(handler)
|
|
||||||
|
|
||||||
|
|
||||||
class Server(paramiko.ServerInterface):
|
class Server(paramiko.ServerInterface):
|
||||||
@@ -186,15 +176,15 @@ class SSHHandler(socketserver.StreamRequestHandler):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
sshserver = socketserver.ThreadingTCPServer(('127.0.0.1', PORT),
|
||||||
os.mkfifo(FIFO)
|
SSHHandler)
|
||||||
sys.stdout.write('Opening named FIFO queue: %s\n' % FIFO)
|
sshserver.serve_forever()
|
||||||
sshserver = socketserver.ThreadingTCPServer(('127.0.0.1', PORT),
|
|
||||||
SSHHandler)
|
|
||||||
sshserver.serve_forever()
|
|
||||||
finally:
|
|
||||||
os.remove(FIFO)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
handler = logging.StreamHandler(sys.stdout)
|
||||||
|
handler.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] '
|
||||||
|
'%(filename)s:%(lineno)s - '
|
||||||
|
'%(message)s'))
|
||||||
|
LOG.addHandler(handler)
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user