mirror of
https://github.com/gryf/ferrit.git
synced 2026-02-07 08:45:53 +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
|
||||
|
||||
|
||||
# This global variable meant to be set in module, which imports this one
|
||||
FIFO = None
|
||||
FILE_DIR = os.path.dirname(__file__)
|
||||
BASE_NAME = os.path.extsep.join(os.path.basename(__file__)
|
||||
.split(os.path.extsep)[:-1])
|
||||
@@ -19,7 +21,6 @@ LOG.addHandler(handler)
|
||||
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)
|
||||
@@ -27,9 +28,6 @@ class App(bottle.Bottle):
|
||||
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 ''
|
||||
|
||||
@@ -37,7 +35,6 @@ class App(bottle.Bottle):
|
||||
return ''
|
||||
|
||||
def _events(self, t1=None):
|
||||
__import__('pdb').set_trace()
|
||||
return {}
|
||||
|
||||
def _projects(params=None):
|
||||
@@ -56,9 +53,15 @@ class App(bottle.Bottle):
|
||||
"description": "users",
|
||||
"state": "ACTIVE",
|
||||
"web_links": [{"name": "browse",
|
||||
"url": "/plugins/gitiles/i"
|
||||
"url": "/plugins/gitiles/"
|
||||
"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):
|
||||
# We are looking for labels in the json
|
||||
@@ -74,8 +77,11 @@ class App(bottle.Bottle):
|
||||
|
||||
def main():
|
||||
app = App()
|
||||
app.run(port=8181, host='localhost', debug=True)
|
||||
app.run(port=8181, host='localhost', debug=False, quiet=True)
|
||||
|
||||
|
||||
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 logging
|
||||
import os
|
||||
import socketserver
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import traceback
|
||||
@@ -12,24 +10,21 @@ import traceback
|
||||
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
|
||||
PORT = 2200
|
||||
|
||||
FILE_DIR = os.path.dirname(__file__)
|
||||
BASE_NAME = os.path.extsep.join(os.path.basename(__file__)
|
||||
.split(os.path.extsep)[:-1])
|
||||
HOST_KEY = paramiko.RSAKey(filename=os.path.join(FILE_DIR,
|
||||
'gerrit-server-key'),
|
||||
password='jenkins')
|
||||
fd, FIFO = tempfile.mkstemp(suffix='.fifo', prefix='ferrit.')
|
||||
os.close(fd)
|
||||
os.unlink(FIFO)
|
||||
# TODO(gryf): make the path to the key configurable
|
||||
HOST_KEY = paramiko.RSAKey(filename='gerrit-server-key', password='jenkins')
|
||||
|
||||
GERRIT_CMD_PROJECTS = """All-Projects
|
||||
All-Users
|
||||
openstack
|
||||
openstack/nova
|
||||
openstack/neutron
|
||||
example
|
||||
"""
|
||||
GERRIT_CMD_VERSION = "ferrit version 0.0.1\n"
|
||||
GERRIT_SHELL_MSG = """\r
|
||||
@@ -51,11 +46,6 @@ handler.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] '
|
||||
'%(filename)s:%(lineno)s - '
|
||||
'%(message)s'))
|
||||
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):
|
||||
@@ -186,15 +176,15 @@ class SSHHandler(socketserver.StreamRequestHandler):
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
os.mkfifo(FIFO)
|
||||
sys.stdout.write('Opening named FIFO queue: %s\n' % FIFO)
|
||||
sshserver = socketserver.ThreadingTCPServer(('127.0.0.1', PORT),
|
||||
SSHHandler)
|
||||
sshserver.serve_forever()
|
||||
finally:
|
||||
os.remove(FIFO)
|
||||
sshserver = socketserver.ThreadingTCPServer(('127.0.0.1', PORT),
|
||||
SSHHandler)
|
||||
sshserver.serve_forever()
|
||||
|
||||
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user