Skip to content

Commit

Permalink
global: migration from GitLab to GitHub
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Delgado <JavierDelgado@outlook.com>
  • Loading branch information
JavierDelgadoFernandez committed May 3, 2017
1 parent 3ec218f commit 20412ad
Show file tree
Hide file tree
Showing 18 changed files with 1,265 additions and 1 deletion.
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# IDEA files. [0/90]
.idea/

# KDevelop files.
.kdev4/
*.kdev4
.directory

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
.cache/
.coverage

# Databases
*.db

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

npm-debug.log
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

language: python
python:
- "3.5"
- "3.5-dev" # 3.5 development branch
- "3.6"
- "3.6-dev" # 3.6 development branch
- "3.7-dev" # 3.7 development branch
- "nightly" # currently points to 3.7-dev
install: "pip install -e .[tests]"
script: "./run-tests.sh"
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# selenol-platform
# selenol-platform

Base system to orchestrate selenol services.

[![Travis](https://img.shields.io/travis/selenol/selenol-platform.svg)](https://travis-ci.org/selenol/selenol-platform/builds) [![PyPI](https://img.shields.io/pypi/dm/selenol-platform.svg)](https://pypi.python.org/pypi?name=selenol-platform) [![GitHub release](https://img.shields.io/github/release/selenol/selenol-platform.svg)](https://github.com/selenol/selenol-platform)
17 changes: 17 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

[pytest]
addopts = --pep8 --ignore=docs --cov=selenol_platform --cov-report=term-missing
19 changes: 19 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env sh
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

pydocstyle selenol_platform && \
isort -rc -c -df **/*.py && \
python setup.py pytest
16 changes: 16 additions & 0 deletions selenol_platform/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Base system to orchestrate selenol services."""
73 changes: 73 additions & 0 deletions selenol_platform/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Application module to manage the services."""

import click
import pkg_resources

from selenol_python.persistences import Base, get_engine, session_creator

from .pool import SelenolPool


def load_service_entrypoints(group):
"""Apply the given function to all the service entripoints."""
return [item.load() for item in
pkg_resources.iter_entry_points(group=group)]


@click.group()
def cli_group():
"""CLI tool."""


@cli_group.group(name='db')
def db_group():
"""DB related methods."""


@cli_group.group(name='fixtures')
def fixtures_group():
"""Fixture related methods."""


@fixtures_group.command('create')
@click.option('-c', '--connection', default=None)
def create_fixtures(connection):
"""Create all the fixtures used by the application."""
session = session_creator(connection)

for fixture in load_service_entrypoints('selenol.fixtures'):
fixture(session)


@db_group.command(name='create')
@click.option('-c', '--connection', default=None)
def create_db(connection):
"""Create all the database base."""
engine = get_engine(connection)

load_service_entrypoints('selenol.services')

Base.metadata.create_all(engine)


@cli_group.command()
def run():
"""Run the service."""
services = load_service_entrypoints('selenol.services')
pool = SelenolPool(services)
pool.serve()
3 changes: 3 additions & 0 deletions selenol_platform/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Configuration variables."""

SELENOL_DEFAULT_DATABASE_CONNECTION = 'sqlite:///database.db'
52 changes: 52 additions & 0 deletions selenol_platform/pool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Pool implementation to manage multiple services at the same time."""

import logging
from threading import Thread


def service_manager(service, connection=None, session=None):
"""Run a service in an infinitive loop until an exception occurs.
:param service: Selenol service to be executed.
:param connection: Selenol backend connection.
:param session: Database session for the service.
"""
try:
process = service(connection, session)
process.run()
except Exception as ex:
logging.exception(ex)


class SelenolPool(object):
"""Pool of thread to process services."""

def __init__(self, services):
"""Constructor.
:param services: List of services that the pool will manage.
"""
self.services = services
self.processess = []

def serve(self):
"""Create all the services and run them in parallel."""
self.processess = [Thread(target=service_manager, args=[service]) for
service in self.services]
for process in self.processess:
process.start()
52 changes: 52 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Setup module."""

from setuptools import setup

setup(
name='selenol-platform',
version='0.1.0',
description='Base system to orchestrate selenol services.',
url='https://github.com/selenol/selenol-platform',
author='Javier Delgado',
author_email='JavierDelgado@outlook.com',
license='GPLv3',
test_suite='tests',
entry_points={
'console_scripts': [
'selenol=selenol_platform.cli:cli_group',
],
},
install_requires=[
'Click>=6.7',
'selenol-python>=0.1',
'sqlalchemy>=1.1.9',
],
packages=['selenol_platform'],
extras_require={
'tests': [
'coverage>=4.0',
'isort>=4.2.5',
'pytest>=3.0.7',
'pydocstyle>=1.1.1',
'pytest-cache>=1.0',
'pytest-cov>=2.4.0',
'pytest-pep8>=1.0.6',
'pytest-runner>=2.11.1',
],
},
)
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Conftest module."""
16 changes: 16 additions & 0 deletions tests/demo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Demo service implementation."""
24 changes: 24 additions & 0 deletions tests/demo/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Demo fixture."""

from .models import TestTable


def create_test(session):
"""Demo fixture."""
session.add(TestTable(test="ThisIsATest"))
session.commit()
29 changes: 29 additions & 0 deletions tests/demo/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Demo service model declaration."""

from sqlalchemy import Column, Integer, Text

from selenol_python.persistences import Base


class TestTable(Base):
"""Test table."""
__tablename__ = 'test_table'

id = Column(Integer, primary_key=True)

test = Column(Text)
Loading

0 comments on commit 20412ad

Please sign in to comment.