diff --git a/README.md b/README.md index 0c06559..c46734b 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,12 @@ Install requirements: pip install -r test-requirements.txt -By default manage.py works with test settings. -For working with prod settings use `python manage.py --mode` option. +By default manage_collector.py works with prod settings. +For working with test settings use `python manage_collector.py --mode` option. For creating DB migration: - python manage.py db migrate -m "Migration comment" \ + python manage_collector.py --mode test db migrate -m "Migration comment" \ -d collector/api/db/migrations/ Create DB user with password 'collector': @@ -36,12 +36,14 @@ Create DB and grant privileges to it: For apply the latest migration: - python manage.py db upgrade -d collector/api/db/migrations/ + python manage_collector.py --mode test db upgrade -d collector/api/db/migrations/ For revert all migrations: - python manage.py db downgrade -d collector/api/db/migrations/ + python manage_collector.py --mode test db downgrade -d collector/api/db/migrations/ For starting test server: - python manage.py runserver + python manage_collector.py --mode test runserver + +Example config for uWSGI is located in collector/uwsgi/collector_test.yaml diff --git a/collector/manage.py b/collector/manage_collector.py similarity index 88% rename from collector/manage.py rename to collector/manage_collector.py index 86ac749..300c22f 100644 --- a/collector/manage.py +++ b/collector/manage_collector.py @@ -1,4 +1,4 @@ -# Migration manager +#!/usr/bin/env python from flask_migrate import Migrate from flask_migrate import MigrateCommand @@ -21,7 +21,7 @@ def configure_app(mode=None): manager = Manager(configure_app) manager.add_option('--mode', help="Acceptable modes. Default: 'test'", - choices=('test', 'prod'), default='test', dest='mode') + choices=('test', 'prod'), default='prod', dest='mode') migrate = Migrate(app, db) manager.add_command('db', MigrateCommand) diff --git a/collector/setup.py b/collector/setup.py new file mode 100644 index 0000000..7c41699 --- /dev/null +++ b/collector/setup.py @@ -0,0 +1,45 @@ +import os + +from setuptools import find_packages +from setuptools import setup + + +def parse_requirements_txt(): + root = os.path.dirname(os.path.abspath(__file__)) + requirements = [] + with open(os.path.join(root, 'requirements.txt'), 'r') as f: + for line in f.readlines(): + line = line.rstrip() + if not line or line.startswith('#'): + continue + requirements.append(line) + return requirements + + +setup( + name='collector', + version='0.0.1', + description="Service of collecting anonymous statistics", + long_description="""Service of collecting anonymous statistics""", + license="http://www.apache.org/licenses/LICENSE-2.0", + classifiers=[ + "License :: OSI Approved :: Apache Software License", + "Development Status :: 3 - Alpha", + "Programming Language :: Python", + "Topic :: Internet :: WWW/HTTP", + "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", + ], + author='Mirantis Inc.', + author_email='product@mirantis.com', + url='https://mirantis.com', + keywords='fuel anonymous statistics collector mirantis', + packages=find_packages(), + zip_safe=False, + install_requires=parse_requirements_txt(), + include_package_data=True, + scripts=['manage_collector.py'], + # entry_points={ + # 'console_scripts': [ + # 'upgrade_db = collector.cli:main'] + # } +) diff --git a/collector/test-requirements.txt b/collector/test-requirements.txt index af12b01..10cbe63 100644 --- a/collector/test-requirements.txt +++ b/collector/test-requirements.txt @@ -1,3 +1,7 @@ -r requirements.txt unittest2 mock +nose +hacking +nose2 +tox diff --git a/collector/tox.ini b/collector/tox.ini new file mode 100644 index 0000000..bf108f2 --- /dev/null +++ b/collector/tox.ini @@ -0,0 +1,42 @@ +[tox] +minversion = 1.6 +skipsdist = True +envlist = py27,pep8 + +[testenv] +usedevelop = True +install_command = pip install {packages} +setenv = VIRTUAL_ENV={envdir} +deps = -r{toxinidir}/test-requirements.txt +commands = + nosetests {posargs:collector/test} + +[tox:jenkins] +downloadcache = ~/cache/pip + +[testenv:pep8] +deps = hacking==0.7 +usedevelop = False +commands = + flake8 {posargs:collector} + +[testenv:cover] +setenv = NOSE_WITH_COVERAGE=1 + +[testenv:venv] +deps = -r{toxinidir}/test-requirements.txt +commands = {posargs:} + +[testenv:devenv] +envdir = devenv +usedevelop = True + +[flake8] +ignore = H234,H302,H802 +exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,__init__.py,docs +show-pep8 = True +show-source = True +count = True + +[hacking] +import_exceptions = testtools.matchers diff --git a/collector/uwsgi/collector_example.yaml b/collector/uwsgi/collector_example.yaml new file mode 100644 index 0000000..4cab3cc --- /dev/null +++ b/collector/uwsgi/collector_example.yaml @@ -0,0 +1,5 @@ +uwsgi: + socket: :8081 + module: collector.api.app + callable: app + protocol: http