From 36e6ae18fc9a4eda018eae3b1d85b2dc200ffb88 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 9 Mar 2018 13:38:23 +0100 Subject: use setuptools instead of only distutils Signed-off-by: Olivier Gayot --- setup.py | 31 ++++++++++----------- swiftstory/SwiftStory.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ swiftstoryd | 72 ------------------------------------------------ 3 files changed, 86 insertions(+), 89 deletions(-) create mode 100644 swiftstory/SwiftStory.py delete mode 100755 swiftstoryd diff --git a/setup.py b/setup.py index 05232cb..a1d389b 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,4 @@ -from distutils.core import setup - -packages = [ - 'swiftstory', - ] +from setuptools import setup, find_packages prefix = '/' share_dir = 'usr/share/swiftstory/' @@ -23,16 +19,17 @@ for n in os.walk('usr'): print(data_files) -scripts = [ - 'swiftstoryd', - ] - setup( - name='swiftstory', - version='0.1', - author='Olivier Gayot', - author_email='olivier.gayot@sigexec.com', - packages=packages, - data_files=data_files, - scripts=scripts, - ) + name = 'swiftstory', + description = "SwiftStory game: We're not out of the woods yet.", + version = '0.1', + author = 'Olivier Gayot', + author_email = 'olivier.gayot@sigexec.com', + packages = find_packages(), + data_files = data_files, + entry_points = { + 'console_scripts': [ + 'swiftstoryd = swiftstory.SwiftStory:main', + ], + } +) diff --git a/swiftstory/SwiftStory.py b/swiftstory/SwiftStory.py new file mode 100644 index 0000000..2f5ae36 --- /dev/null +++ b/swiftstory/SwiftStory.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +from websocket_server import WebsocketServer +import swiftstory.GameManager +import swiftstory.Client +from swiftstory.Status import error + +import json + +game_manager = swiftstory.GameManager.GameManager() + +def new_client_handler(client, server): + client['client'] = swiftstory.Client.Client(server, client, game_manager) + +def client_left_handler(client, server): + client['client'].disconnect(); + +def message_received_handler(client, server, message): + try: + json_msg = json.loads(message) + except: + res = error('badly formatted json') + else: + op = json_msg['op'] + if op == 'join_game': + try: + game_name = json_msg['game_name'] + except KeyError: + res = error('field `game_name\' is required') + else: + lang = json_msg.get('lang') + res = client['client'].join_game(game_name, lang) + elif op == 'view_player_cards': + res = client['client'].view_player_cards() + elif op == 'view_black_card': + res = client['client'].view_black_card() + elif op == 'view_played_cards': + res = client['client'].view_played_cards() + elif op == 'pick_black_card': + res = client['client'].pick_black_card() + elif op == 'designate_card': + card_id = None + try: + card_id = int(json_msg['card_id']) + except (KeyError, TypeError): + pass + finally: + res = client['client'].designate_card(card_id) + elif op == 'play_white_card': + try: + card_id = int(json_msg['card_id']) + except KeyError: + res = error('field `card_id\' is required') + else: + res = client['client'].play_white_card(card_id) + elif op == 'collect_cards': + res = client['client'].collect_cards() + else: + res = error('invalid command') + + server.send_message(client, res) + +def main(): + server = WebsocketServer(1236, '0.0.0.0') + server.set_fn_new_client(new_client_handler) + server.set_fn_client_left(client_left_handler) + server.set_fn_message_received(message_received_handler) + + server.run_forever() + +if __name__ == '__main__': + main() diff --git a/swiftstoryd b/swiftstoryd deleted file mode 100755 index 2f5ae36..0000000 --- a/swiftstoryd +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python - -from websocket_server import WebsocketServer -import swiftstory.GameManager -import swiftstory.Client -from swiftstory.Status import error - -import json - -game_manager = swiftstory.GameManager.GameManager() - -def new_client_handler(client, server): - client['client'] = swiftstory.Client.Client(server, client, game_manager) - -def client_left_handler(client, server): - client['client'].disconnect(); - -def message_received_handler(client, server, message): - try: - json_msg = json.loads(message) - except: - res = error('badly formatted json') - else: - op = json_msg['op'] - if op == 'join_game': - try: - game_name = json_msg['game_name'] - except KeyError: - res = error('field `game_name\' is required') - else: - lang = json_msg.get('lang') - res = client['client'].join_game(game_name, lang) - elif op == 'view_player_cards': - res = client['client'].view_player_cards() - elif op == 'view_black_card': - res = client['client'].view_black_card() - elif op == 'view_played_cards': - res = client['client'].view_played_cards() - elif op == 'pick_black_card': - res = client['client'].pick_black_card() - elif op == 'designate_card': - card_id = None - try: - card_id = int(json_msg['card_id']) - except (KeyError, TypeError): - pass - finally: - res = client['client'].designate_card(card_id) - elif op == 'play_white_card': - try: - card_id = int(json_msg['card_id']) - except KeyError: - res = error('field `card_id\' is required') - else: - res = client['client'].play_white_card(card_id) - elif op == 'collect_cards': - res = client['client'].collect_cards() - else: - res = error('invalid command') - - server.send_message(client, res) - -def main(): - server = WebsocketServer(1236, '0.0.0.0') - server.set_fn_new_client(new_client_handler) - server.set_fn_client_left(client_left_handler) - server.set_fn_message_received(message_received_handler) - - server.run_forever() - -if __name__ == '__main__': - main() -- cgit v1.2.3