...
 
Commits (4)
*.py[cod]
.ipynb_checkpoints/
__pycache__
*.egg-info
.vscode/
*/*.command
*/*.bat
......@@ -20,4 +21,7 @@ ezchat/chatbox/package-lock.json
ezchat-*/*
ezchat.egg-info/*
dist/*
\ No newline at end of file
dist/*
ezchat/ssl
ezchat/gcloud
# ezchat
## 1 - Summary
**ezchat** stands for easy chat.
+ No frills Python chat app.
+ No frills chat app.
+ Hub: [Flask](http://flask.pocoo.org/docs/0.12/), [Flask-socketIO](http://flask-socketio.readthedocs.io/en/latest/) backend.
+ Clients: [VueJS](https://vuejs.org/) frontend.
+ Instant setup.
+ Available on [PyPI](https://pypi.org/), distributed via [pip](https://pip.pypa.io/en/stable/).
## 2 - Install
Run from a notebook or command line.
In both cases, new independent processes are spawn.
From command line:
````
pip install ezchat
````
### 1 - Notebook
## 3 - Notebook
See [demo_notebook](http://nbviewer.jupyter.org/urls/gitlab.com/oscar6echo/ezchat/raw/master/demo_ezchat.ipynb).
In the [notebook](http://jupyter.org/), or [IPython console](https://ipython.org/), the hub and client servers are launched in `detached=True` mode to create new terminal windows and thus avoid blocking the notebook.
### 2 - Command Line
## 4 - Command Line
+ Launch Hub:
But in command line they can be launched in `detached=False` after manually creating the terminal windows to
+ Launch Hub and get back to prompt:
```Python
from ezchat.servers import hub
h = hub(port=5001)
h = hub(port=5001, detached=True)
````
+ Launch Hub in current terminal:
```Python
from ezchat.servers import hub
hub(port=5001, detached=False)
````
+ Launch Client and get back to prompt:
```Python
from ezchat.servers import client
c = client(port=5002, detached=True)
````
+ Launch Client:
+ Launch Client in current terminal:
```Python
from ezchat.servers import client
c = client(port=5002)
client(port=5002, detached=False)
````
+ Kill Hub and Clients:
+ Kill Hub and Clients - if handles availables:
```Python
from ezchat.servers import kill
......@@ -37,4 +63,4 @@ kill(h)
kill(c)
````
<!-- pandoc --from=markdown --to=rst --output=README.rst README.md -->
\ No newline at end of file
<!-- pandoc --from=markdown --to=rst --output=README.rst README.md -->
......@@ -49,16 +49,17 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Script /Users/Olivier/Documents/vuejs/ezchat/ezchat/hub.command created\n",
"Web server \"chat hub\" started\n",
"To check it is running, look for its terminal window\n",
"And open browser to http://localhost:5001\n",
"Open browser to http://localhost:5001\n",
"Note: The server will crash upon start if the port is being used\n"
]
},
{
"data": {
"text/plain": [
"['9258', '9255']"
"['9211', '9208']"
]
},
"execution_count": 3,
......@@ -67,7 +68,7 @@
}
],
"source": [
"h = hub(port=5001)\n",
"h = hub(port=5001, detached=True)\n",
"h"
]
},
......@@ -80,16 +81,17 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Web server \"chat client\" started\n",
"Script /Users/Olivier/Documents/vuejs/ezchat/ezchat/client.command created\n",
"Web server \"ezchat client\" started\n",
"To check it is running, look for its terminal window\n",
"And open browser to http://localhost:5002\n",
"Open browser to http://localhost:5002\n",
"Note: The server will crash upon start if the port is being used\n"
]
},
{
"data": {
"text/plain": [
"['9377', '9374']"
"['9344', '9341']"
]
},
"execution_count": 4,
......@@ -98,7 +100,7 @@
}
],
"source": [
"c = client(port=5002)\n",
"c = client(port=5002, detached=True)\n",
"c"
]
},
......@@ -118,7 +120,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Killing pids: ['9258', '9255']\n",
"Killing pids: ['9211', '9208']\n",
"Server killed\n"
]
}
......@@ -136,7 +138,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Killing pids: ['9377', '9374']\n",
"Killing pids: ['9344', '9341']\n",
"Server killed\n"
]
}
......@@ -144,15 +146,6 @@
"source": [
"kill(c)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
......
__name__ = 'ezchat'
__version__ = '0.0.2'
__version__ = '0.0.3'
......@@ -215,4 +215,7 @@ port = int(os.environ.get('port', 5000))
logging.info(app.config)
logging.info('Starting ezchat hub')
socketio.run(app, debug=True, port=port)
ssl_context = (os.path.join('ssl', 'host.cert'), os.path.join('ssl', 'host.key'))
# app.run(host='0.0.0.0', port=port, debug=True, threaded=False, ssl_context=ssl_context)
socketio.run(app, host='0.0.0.0', port=port, debug=True, threaded=False, ssl_context=ssl_context)
......@@ -6,25 +6,35 @@ import subprocess as sp
from time import sleep
def hub(port=5001):
def hub(port=5001, detached=False, verbose=True):
"""
Launch ezchat hub server in new terminal window
Launch ezchat hub server
In new terminal window in detached=True
"""
ref = launch_web_server(name='hub', port=port)
name = 'hub'
filename, msg = create_script(name=name, port=port, verbose=verbose)
ref = run_script(filename, msg=msg, detached=detached)
# ref = launch_web_server(name='hub', port=port)
return ref
def client(port=5002):
def client(port=5002, detached=False, verbose=True):
"""
Launch ezchat client server in new terminal window
Launch ezchat client server
In new terminal window if detached=True
"""
ref = launch_web_server(name='client', port=port)
name = 'client'
filename, msg = create_script(name=name, port=port, verbose=verbose)
ref = run_script(filename, msg=msg, detached=detached)
# ref = launch_web_server(name='client', port=port)
return ref
def launch_web_server(name=None, port=5000):
def create_script(name=None, port=5000, verbose=True):
"""
Launch web server for chat server of client in new terminal window
Create run script for chat server or client
"""
if name not in ['hub', 'client']:
print('Bad arguments')
......@@ -42,39 +52,72 @@ def launch_web_server(name=None, port=5000):
command = "cd {}; export port={}; python {}.py"
suffix = 'sh'
with open(os.path.join(here, '{}.{}'.format(name, suffix)), 'w') as f:
f.write(command.format(here, port, name))
filename = os.path.join(here, '{}.{}'.format(name, suffix))
script = command.format(here, port, name)
if sys.platform == 'darwin' or sys.platform == 'linux':
# launch server
cmd = 'cd {}; chmod +x ./{}.{}; open ./{}.{}'
cmd = cmd.format(here, name, suffix, name, suffix)
# os.system(cmd)
p = sp.Popen(cmd, stdout=sp.PIPE, shell=True)
with open(filename, 'w') as f:
f.write(script)
# get process ref: pids
sleep(0.8)
cmd = "'python {}.py'".format(name)
cmd = "ps aux | grep " + cmd + " | grep -v grep | awk '{print $2}'"
p = sp.Popen(cmd, stdout=sp.PIPE, shell=True)
res = p.communicate()[0]
pids = res.decode('utf-8').split('\n')
pids = [e for e in pids if e != '']
ref = pids
msg = 'Open browser to http://localhost:{}'.format(port)
if verbose:
print('Script {} created'.format(filename))
elif sys.platform == 'win32':
# launch server
cmd = 'cd /d {}; call {}.{}'
p = sp.Popen([cmd.format(here, name, suffix)],
creationflags=sp.CREATE_NEW_CONSOLE)
# process id is p itself - detached console is windows specific
ref = p
print('Web server "chat {}" started'.format(name))
print('To check it is running, look for its terminal window')
print('And open browser to http://localhost:{}'.format(port))
print('Note: The server will crash upon start if the port is being used')
return ref
return filename, msg
def run_script(filename, msg=None, detached=False):
"""
Run script filename
In new terminal window in detached=True
"""
here = os.path.dirname(os.path.realpath(__file__))
name, suffix = os.path.basename(filename).split('.')
if detached:
if sys.platform == 'darwin' or sys.platform == 'linux':
# launch server
cmd = 'cd {}; chmod +x ./{}.{}; open ./{}.{}'
cmd = cmd.format(here, name, suffix, name, suffix)
p = sp.Popen(cmd, stdout=sp.PIPE, shell=True)
# get process ref: pids
sleep(0.8)
cmd = "'python {}.py'".format(name)
cmd = "ps aux | grep " + cmd + " | grep -v grep | awk '{print $2}'"
p = sp.Popen(cmd, stdout=sp.PIPE, shell=True)
res = p.communicate()[0]
pids = res.decode('utf-8').split('\n')
pids = [e for e in pids if e != '']
ref = pids
elif sys.platform == 'win32':
# launch server
cmd = 'cd /d {}; call {}.{}'
p = sp.Popen([cmd.format(here, name, suffix)],
creationflags=sp.CREATE_NEW_CONSOLE)
# process id is p itself - detached console is windows specific
ref = p
print('Web server "ezchat {}" started'.format(name))
print('To check it is running, look for its terminal window')
if msg:
print(msg)
print('Note: The server will crash upon start if the port is being used')
return ref
else:
if sys.platform == 'darwin' or sys.platform == 'linux':
# launch server
cmd = '{}'.format(filename)
os.system(cmd)
elif sys.platform == 'win32':
# launch server
cmd = '{}'.format(filename)
os.system(cmd)
print('Server interrupted: {}'.format(name))
return None
def kill(ref=None):
......
......@@ -29,7 +29,7 @@ setup(
author = 'oscar6echo',
author_email = '[email protected]',
url = 'https://gitlab.com/oscar6echo/ezchat',
download_url = 'https://gitlab.com/oscar6echo/ezchat/tarball/' + version,
download_url = 'https://gitlab.com/oscar6echo/ezchat/repository/archive.tar.gz?ref=' + version,
keywords = ['chat', 'notebook', 'javascript', 'vuejs'],
license='MIT',
classifiers = [ 'Development Status :: 4 - Beta',
......