Skip to content

Commit

Permalink
Merge pull request #287 from candango/develop
Browse files Browse the repository at this point in the history
Merging develop to master.
  • Loading branch information
piraz committed Dec 25, 2019
2 parents d23f111 + bc42b2f commit 5cf97bc
Show file tree
Hide file tree
Showing 23 changed files with 179 additions and 52 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"
install:
- "pip install -r requirements/basic.txt"
- "pip install -r requirements/redis.txt"
- "pip install -r requirements/pexpect.txt"
- "pip install -r requirements/sqlalchemy.txt"
- "pip install -r requirements/all.txt"
script:
- "PYTHONPATH=$PYTHONPATH:. python tests/runtests.py"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2015-2016 Flavio Garcia
Copyright 2015-2020 Flavio Garcia

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include LICENSE
include requirements/all.txt
include requirements/basic.txt
include requirements/pexpect.txt
include requirements/redis.txt
Expand Down
5 changes: 3 additions & 2 deletions docs/guide/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ commands.

The framework provides a category called Firenado with the following commands:

- app
- projec(ect)
- app Application related commands
- projec(ect) Project related commands
- rand(om) Random related commands

Firenado has a command line program that helps to create a new project, run an
application and other things.
Expand Down
19 changes: 13 additions & 6 deletions docs/guide/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ Introduction
Firenado is a Python web framework that primarily extends the
`Tornado <http://www.tornadoweb.org>`_ framework and runs over it's web server.

A Firenado application is organized in loose couple components and it is wired
using yaml config files. The framework makes possible to develop components
that can be shared between applications and distributed separately.
A Firenado application is organized in components wired by yaml config files.
This design makes it possible to develop shareable components between
applications and be distributed separately.

When you develop with Firenado you can use the our server side session layer
based on files or redis, and you can develop a custom storage.
Firenado also provides a server side session layer based on files or redis. If
you prefer it is also possible to create a new backend to the session layer or
disable it.

Other features shipped with the framework are configurable data sources, a
service layer that could be injected to handles via decorators, a command line
that helps start a project and run an application.

Firenado provides many other features and resources that will help a developer
to create and manage Tornado applications.

Other features are offered shiped at the framework core or via components.

Instalation
-----------
Expand Down
1 change: 1 addition & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Release notes
.. toctree::
:maxdepth: 2

releases/v0.1.7.8
releases/v0.1.7.7
releases/v0.1.7.6
releases/v0.1.7.5
Expand Down
36 changes: 36 additions & 0 deletions docs/releases/v0.1.7.8.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
What's new in Firenado 0.1.7.8
==============================

Dec 25, 2019
------------

We are pleased to announce the release of Firenado 0.1.7.8.

Last Firenado supporting python 2.7 in the main development we will move
Tornado 5.x codebase to a legacy state and only fixing bugs if needed.

Next release we're moving to Tornado 6.x.

We added an extra options to install all extra dependencies and random string
and uuid commands to the command line program.

We fixed bugs with processes launcher and added interface to send lines to the
process running.


Here are the highlights:

New Features
~~~~~~~~~~~~

* Add to setup.py an extra option to install all extras. `#280 <https://github.com/candango/firenado/issues/280>`_
* Random string and uuid command line tasks #284. `#284 <https://github.com/candango/firenado/issues/284>`_

Bug Fixes
~~~~~~~~~
* ProcessLauncher logfile parameter assignment overrides socket. `#279 <https://github.com/candango/firenado/issues/279>`_
* Control ProcessLauncher shutdown properly. `#281 <https://github.com/candango/firenado/issues/281>`_

Examples
~~~~~~~~~
* Async timeout example. `#283 <https://github.com/candango/firenado/issues/283>`_
1 change: 1 addition & 0 deletions examples/launcher/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ def initialize(self):
self.launcher.load()
yield self.launcher.launch()

@gen.coroutine
def shutdown(self):
self.launcher.shutdown()
1 change: 1 addition & 0 deletions examples/testapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def get_handlers(self):
default_login = firenado.conf.app['login']['urls']['default']
return [
(r"/", handlers.IndexHandler),
(r"/async/timeout", handlers.AsyncTimeoutHandler),
(r"/session/counter", handlers.SessionCounterHandler),
(r"/session/config", handlers.SessionConfigHandler),
(r"/pagination", handlers.PaginationHandler),
Expand Down
24 changes: 22 additions & 2 deletions examples/testapp/handlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# Copyright 2015-2018 Flavio Garcia
# Copyright 2015-2019 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,8 +15,12 @@
# limitations under the License.

import firenado.conf
from firenado import security, service, tornadoweb
from firenado import security, service, tornadogen, tornadoweb
from firenado.components.toolbox.pagination import Paginator
from tornado import gen
import logging

logger = logging.getLogger(__name__)


class AuthHandler:
Expand All @@ -29,6 +33,22 @@ def get_current_user(self):
return None


class AsyncTimeoutHandler(tornadoweb.TornadoHandler):

def timed_out(self):
self.render("async_timeout.html")

@gen.coroutine
def get(self):
from tornado.util import TimeoutError
try:
yield tornadogen.with_timeout(2, gen.sleep(5))
self.write("This will never be reached!!")
except TimeoutError as te:
logger.warning(te.__repr__())
self.timed_out()


class IndexHandler(AuthHandler, tornadoweb.TornadoHandler):

def get(self):
Expand Down
9 changes: 9 additions & 0 deletions examples/testapp/templates/async_timeout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "testapp:base.html" %}

{% block content %}
<h1>Async Timeout:</h1>
<p>If you seeing this the timeout was reached.</p>
<ul>
<li><a href="{% module RootedPath('/') %}">Index</a></li>
</ul>
{% end %}
5 changes: 5 additions & 0 deletions examples/testapp/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
<li><a href="{% module RootedPath('/private') %}">Not Public</a></li>
</ul>

{% module Header1("Async") %}
<ul>
<li><a href="{% module RootedPath('/async/timeout') %}">Async Timeout</a></li>
</ul>

{% module Header1("Toolbox") %}
<ul>
<li><a href="{% module RootedPath('/pagination') %}">Pagination</a></li>
Expand Down
16 changes: 14 additions & 2 deletions firenado/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: UTF-8 -*-
#
# Copyright 2015-2019 Flavio Garcia
# Copyright 2015-2020 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,18 @@

from __future__ import (absolute_import, division, print_function,
with_statement)
__author__ = "Flavio Garcia <piraz@candango.org>"
__version__ = (0, 1, 7, 8)
__licence__ = "Apache License V2.0"

__version__ = (0, 1, 7, 7)

def get_version():
return ".".join(map(str, __version__))


def get_author():
return __author__.split(" <")[0]


def get_author_email():
return __author__.split(" <")[1][:-1]
27 changes: 14 additions & 13 deletions firenado/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, **settings):
super(ProcessLauncher, self).__init__(**settings)
self.process = None
self.process_callback = None
self.logfile = self.socket = settings.get("logfile", None)
self.logfile = settings.get("logfile", None)
self.command = None
self.response = None

Expand All @@ -94,17 +94,13 @@ def load(self):
@gen.coroutine
def read_process(self):
import pexpect
import re
self.process_callback.stop()
try:
# Getting everithing but this line, this is a workaround
# TODO: Get everything and remove workaround.
# Don't know if pexpect support that currently.
# See: https://bit.ly/2Zt2sFZ
line = "[-!-!-EVERYTHING_BUT_THIS-!-!-]"
yield self.process.expect(
[r'^((?!' + re.escape(line) + ').)*$'], async_=True)
# Simple way to catch everything is wait for a new line:
#
yield self.process.expect("\n", async_=True)
except pexpect.TIMEOUT:
logger.warning("Reached timeout")
pass
self.process_callback.start()

Expand All @@ -120,18 +116,23 @@ def launch(self):
if self.logfile is not None:
parameters['logfile'] = self.logfile
self.process = pexpect.spawn(**parameters)
yield self.process.expect("Firenado server started successfully.",
async_=True)
yield self.process.expect(
[r"[Firenado server started successfully].*"], async_=True)
self.process_callback = tornado.ioloop.PeriodicCallback(
self.read_process,
400
)
self.process_callback.start()

def send(self, line):
logger.info("Sending line {}".format(line))
self.process.sendline(line)

@gen.coroutine
def shutdown(self):
import pexpect
yield self.process.expect(pexpect.EOF)
logger.warning("Shutting down process launcher.")
self.send("^C")
yield self.process.expect("^C", async_=True)


class TornadoLauncher(FirenadoLauncher):
Expand Down
7 changes: 4 additions & 3 deletions firenado/management/commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# Copyright 2015-2018 Flavio Garcia
# Copyright 2015-2020 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,10 +38,11 @@
tasks=tasks.CreateProjectTask)
])
ManagementCommand(
"rand(om)", "Random related commands", loader.load("app_command_help.txt"),
"rand(om)", "Random related commands", loader.load(
"random_command_help.txt"),
category="Firenado", sub_commands=[
ManagementCommand("string", "Generates a random string", "",
tasks=tasks.GenerateCookieSecretTask),
tasks=tasks.GenerateRandomStringTask),
ManagementCommand("uuid", "Generates a random uuid", "",
tasks=tasks.GenerateUuidTask)
])
23 changes: 18 additions & 5 deletions firenado/management/tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: UTF-8 -*-
#
# Copyright 2015-2019 Flavio Garcia
# Copyright 2015-2020 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -141,18 +141,31 @@ def run(self, namespace):
launcher.launch()


class GenerateCookieSecretTask(ManagementTask):
""" Generates a radom string to serve as the cookie secret for an
class GenerateRandomStringTask(ManagementTask):
""" Generates a random string to serve as the cookie secret for an
application.
"""

def add_arguments(self, parser):
parser.add_argument("size", nargs='?', default=64, type=int)

def run(self, namespace):
from firenado.util import random_string
print(random_string(64))
size = namespace.size
if size > 1000000:
logger.error("The size {} has reached this command "
"limit.".format(size))
sys.exit(1)
logger.debug("Displaying a random string with size {}".format(size))
print(random_string(size))
sys.exit(0)


class GenerateUuidTask(ManagementTask):
""" Generates an uuid string
""" Generates an uuid4 string
"""
def run(self, namespace):
from uuid import uuid4
logger.debug("Displaying a random uuid4 string.")
print(uuid4())
sys.exit(0)
9 changes: 9 additions & 0 deletions firenado/management/templates/help/random_command_help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rand(om) <sub-command>

Sub-commands are:

string Print a random string.
Inform a interger size to change the string size.
Default size is 64.

uuid Print a random uuid.
9 changes: 6 additions & 3 deletions firenado/session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: UTF-8 -*-
#
# Copyright 2015-2019 Flavio Garcia
# Copyright 2015-2020 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -483,8 +483,11 @@ def __init__(self, engine):

def configure(self):
self.life_time = firenado.conf.session['life_time']
self.data_source = self.engine.get_session_aware_instance().\
get_data_source(firenado.conf.session['redis']['data']['source'])
self.data_source = (
self.engine.get_session_aware_instance().get_data_source(
firenado.conf.session['redis']['data']['source']
)
)

def create_session(self, session_id, data):
self.write_stored_session(session_id, data)
Expand Down
3 changes: 3 additions & 0 deletions requirements/all.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-r pexpect.txt
-r redis.txt
-r sqlalchemy.txt
4 changes: 2 additions & 2 deletions requirements/basic.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pyyaml==5.1
pyyaml==5.2
tornado==5.1.1
six==1.12.0
six==1.13.0
4 changes: 2 additions & 2 deletions requirements/redis.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
redis==3.2.1
hiredis==1.0.0
redis==3.3.11
hiredis==1.0.1
2 changes: 1 addition & 1 deletion requirements/sqlalchemy.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sqlalchemy==1.3.7
sqlalchemy==1.3.12

0 comments on commit 5cf97bc

Please sign in to comment.