-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jimmy Bradshaw
committed
Jan 7, 2020
1 parent
a7b42c4
commit 855bb92
Showing
7 changed files
with
69 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ services: | |
"300", | ||
"rabbitmq:61613", | ||
"--", | ||
"python", | ||
"chat.py", | ||
"shattered", | ||
"run", | ||
] | ||
chat: | ||
build: . | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
[tool.poetry] | ||
name = "shattered" | ||
version = "0.2.0" | ||
version = "0.3.0" | ||
description = "STOMP meets bottle.py" | ||
authors = ["Jimmy Bradshaw <[email protected]>"] | ||
repository = "https://github.com/bradshjg/shattered" | ||
license = "MIT" | ||
readme = "README-PYPI.md" | ||
|
||
[tool.poetry.scripts] | ||
shattered = "shattered.cli:main" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.6" | ||
"stomp.py" = "^5.0.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
__version__ = "0.2.0" | ||
__version__ = "0.3.0" | ||
|
||
from shattered.shattered import Shattered |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import argparse | ||
import os | ||
import sys | ||
|
||
from .shattered import Shattered | ||
|
||
|
||
def load_app(args): | ||
sys.path.insert(0, os.getcwd()) | ||
module_file = args.app or os.getenv("SHATTERED_APP", "app.py") | ||
module_name = os.path.splitext(module_file)[0] | ||
__import__(module_name) | ||
module = sys.modules[module_name] | ||
matches = [v for v in module.__dict__.values() if isinstance(v, Shattered)] | ||
if len(matches) == 1: | ||
return matches[0] | ||
else: | ||
raise EnvironmentError("Detected multiple Shattered applications.") | ||
|
||
|
||
def run_app(args): | ||
app = load_app(args) | ||
app.run() | ||
|
||
|
||
def print_config(args): | ||
app = load_app(args) | ||
for k, v in app.config.items(): | ||
print(f"{k}: {v}") | ||
|
||
|
||
def parse_arguments(): | ||
parser = argparse.ArgumentParser(prog="shattered") | ||
parser.add_argument("-a", "--app", help="shattered app") | ||
subparsers = parser.add_subparsers( | ||
title="subcommands", description="valid subcommands", help="additional help" | ||
) | ||
parser_run = subparsers.add_parser("run", help="run shattered app") | ||
parser_run.set_defaults(func=run_app) | ||
parser_config = subparsers.add_parser("config", help="show shattered app config") | ||
parser_config.set_defaults(func=print_config) | ||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = parse_arguments() | ||
args.func(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters