From c2c7d5ca8c1722d5b91c3fbdf5fb45de6760b7d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Mart=C3=ADnez?= Date: Fri, 7 May 2021 12:52:02 +0200 Subject: [PATCH] add package --- setup.py | 40 +++++++++++++++++ stopover/server.py | 37 ---------------- stopover_server/__init__.py | 4 ++ .../__main__.py | 43 ++++++++++++++++++- {stopover => stopover_server}/broker.py | 8 ++-- {stopover => stopover_server}/partition.py | 2 +- {stopover => stopover_server}/utils.py | 0 stopover_server/version.py | 5 +++ upload.sh | 3 ++ 9 files changed, 98 insertions(+), 44 deletions(-) create mode 100755 setup.py delete mode 100755 stopover/server.py create mode 100644 stopover_server/__init__.py rename stopover/stopover.py => stopover_server/__main__.py (66%) rename {stopover => stopover_server}/broker.py (98%) rename {stopover => stopover_server}/partition.py (99%) rename {stopover => stopover_server}/utils.py (100%) create mode 100755 stopover_server/version.py create mode 100755 upload.sh diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..071f9eb --- /dev/null +++ b/setup.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from setuptools import setup +from setuptools import find_packages +import stopover_server + +setup(name='stopover-server', + version=stopover_server.__version__, + description='Message Broker powered by RocksDB', + url='https://github.com/labteral/stopover', + author='Rodrigo Martínez Castaño', + author_email='dev@brunneis.com', + license='GNU General Public License v3 (GPLv3)', + packages=find_packages(), + zip_safe=False, + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', + 'Operating System :: POSIX :: Linux', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: Implementation :: PyPy', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + python_requires='>=3.6', + install_requires=[ + 'msgpack==1.0.2,<2.0.0', + 'python-snappy>=0.6.0,<1.0.0', + 'easyrocks>=2.214.0,<3.0.0' + 'pyyaml==5.4.1,<6.0.0', + 'falcon>=3.0.0,<4.0.0', + 'cherrybone', + ], + entry_points={ + 'console_scripts': [ + 'stopover = stopover_server.__main__:main', + ], + }) diff --git a/stopover/server.py b/stopover/server.py deleted file mode 100755 index 7f59e77..0000000 --- a/stopover/server.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from stopover import banner -from broker import Broker -import falcon -import logging -import yaml -import sys -from cherrybone import Server - -CONFIG_PATH = './config.yaml' - -logging.getLogger().setLevel(logging.INFO) -logging.basicConfig(format='%(asctime)-15s [%(levelname)s] %(message)s', - datefmt='%Y-%m-%d %H:%M:%S') -logging.info(f'\n{banner}') - -with open(CONFIG_PATH, 'r') as input_file: - config = yaml.safe_load(input_file) - -try: - open(f"{config['global']['data_dir']}/streams/.active") - -except FileNotFoundError: - logging.critical('the streams dir is not active') - sys.exit(1) - -api = falcon.App() -api.add_route('/', Broker(config)) - -if __name__ == "__main__": - threads = None - if 'threads' in config['global'] and config['global']['threads'] > 0: - threads = config['global']['threads'] - - Server(api, port=5704, threads=threads).start() diff --git a/stopover_server/__init__.py b/stopover_server/__init__.py new file mode 100644 index 0000000..72f6bd0 --- /dev/null +++ b/stopover_server/__init__.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from stopover import __version__ diff --git a/stopover/stopover.py b/stopover_server/__main__.py similarity index 66% rename from stopover/stopover.py rename to stopover_server/__main__.py index bbcda82..8517003 100755 --- a/stopover/stopover.py +++ b/stopover_server/__main__.py @@ -1,7 +1,13 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -version = '2.214.1' +from .version import __version__ +from .broker import Broker +import falcon +import logging +import yaml +import sys +from cherrybone import Server banner = f""" ███████████ ███████████ @@ -25,5 +31,38 @@ ███████████████████████ ███████████████████ ███████████ ___________________ - Stopover v{version} + Stopover v{__version__} """ + +CONFIG_PATH = './config.yaml' + +logging.getLogger().setLevel(logging.INFO) +logging.basicConfig(format='%(asctime)-15s [%(levelname)s] %(message)s', + datefmt='%Y-%m-%d %H:%M:%S') + + +def main(): + logging.info(f'\n{banner}') + + with open(CONFIG_PATH, 'r') as input_file: + config = yaml.safe_load(input_file) + + try: + open(f"{config['global']['data_dir']}/streams/.active") + + except FileNotFoundError: + logging.critical('the streams dir is not active') + sys.exit(1) + + api = falcon.App() + api.add_route('/', Broker(config)) + + threads = None + if 'threads' in config['global'] and config['global']['threads'] > 0: + threads = config['global']['threads'] + + Server(api, port=5704, threads=threads).start() + + +if __name__ == "__main__": + main() diff --git a/stopover/broker.py b/stopover_server/broker.py similarity index 98% rename from stopover/broker.py rename to stopover_server/broker.py index 23cf26b..4e8c489 100755 --- a/stopover/broker.py +++ b/stopover_server/broker.py @@ -1,14 +1,14 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from stopover import version -from partition import Partition, PartitionItem +from .version import __version__ +from .partition import Partition, PartitionItem +from . import utils from os import listdir, path from threading import Lock, Thread import traceback import random import falcon -import utils import time import json import logging @@ -48,7 +48,7 @@ def __init__(self, config): @staticmethod def on_get(request, response): response.content_type = 'text/html; charset=utf-8' - response.body = f'Labteral Stopover {version}' + response.body = f'Labteral Stopover {__version__}' def on_post(self, request, response): bin_data = request.stream.read() diff --git a/stopover/partition.py b/stopover_server/partition.py similarity index 99% rename from stopover/partition.py rename to stopover_server/partition.py index 41767be..7282151 100755 --- a/stopover/partition.py +++ b/stopover_server/partition.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import utils +from . import utils from os import makedirs from easyrocks import RocksDB, WriteBatch, CompressionType from easyrocks.utils import int_to_padded_bytes diff --git a/stopover/utils.py b/stopover_server/utils.py similarity index 100% rename from stopover/utils.py rename to stopover_server/utils.py diff --git a/stopover_server/version.py b/stopover_server/version.py new file mode 100755 index 0000000..5fcd036 --- /dev/null +++ b/stopover_server/version.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +__version__ = '2.215.0' + diff --git a/upload.sh b/upload.sh new file mode 100755 index 0000000..c9c26c5 --- /dev/null +++ b/upload.sh @@ -0,0 +1,3 @@ +#!/bin/bash +python3 setup.py bdist_wheel +twine upload dist/*.whl