Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ usage: instantRst [-h] [-f FILENAME] [-b BROWSER] [-p PORT] [-s STATIC_DIR] [-t

optional arguments:

-h, --help
-h, --help
show this help message and exit
-f FILENAME, --file FILENAME
The local filename for Converting
Expand All @@ -55,16 +55,16 @@ optional arguments:
Default is '' for using system default
-p PORT, --port PORT The port for server to use
Default is '5676'
-t TEMPLATE_DIR, --template-dir TEMPLATE_DIR
Directory containing a template to
be used when rendering the output.
Defaults to a bundled rhythm.css_
-s STATIC_DIR, --static-dir STATIC_DIR
The directory containing static
-t TEMPLATE_DIR, --template-dir TEMPLATE_DIR
Directory containing a template to
be used when rendering the output.
Defaults to a bundled ``rhythm.css_``
-s STATIC_DIR, --static-dir STATIC_DIR
The directory containing static
files used by the template.
Defaults to a bundled rhythm.css_
-l, --localhost-only
Only use localhost, disable lan ip
Defaults to a bundled ``rhythm.css_``
-l, --localhost-only
Only use localhost, disable lan ip
default: False

-d, --additional-dir
Expand Down Expand Up @@ -130,7 +130,7 @@ STATIC FILES
0. Default Static file:

the ``static/main.css|js`` is served there

The instant rst's default theme is set there.

You can pass the ``-s`` for default static directory.
Expand All @@ -154,15 +154,15 @@ STATIC FILES
When using with dynamic files, you can post with '-dir=DYN_DIR_NAME' to update the ``DYN_STATIC_DIR``

e.g.:

You have a file named ``test/test.jpg``

When you start instantRst ``instantRst -f test/test.rst``

The file is served with ``localhost:5676/_static/test.jpg``

When you switch to another file like ``test1/test.rst``
Then you can post with ``dir=test1`` or ``dir=~/rst/test1`` to change
Then you can post with ``dir=test1`` or ``dir=~/rst/test1`` to change
the static dir.

Develop
Expand All @@ -171,17 +171,17 @@ Develop
Contribution are welcomed.

git clone the project::
git clone

git clone

install local package::

sudo pip install . --upgrade

start test with local package::

# localhost:5676
python scripts/instantRst --debug -f test/test.rst
# localhost:5000
python -m instant_rst -f README.rst

change to static/template file should change setup.py and manifest.in

Expand Down
5 changes: 2 additions & 3 deletions scripts/instantRst → instant_rst/__main__.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from instant_rst.main import run

run()
if __name__ == '__main__':
run()
48 changes: 0 additions & 48 deletions instant_rst/args.py

This file was deleted.

116 changes: 102 additions & 14 deletions instant_rst/main.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,122 @@
#!/usr/bin/env python3
from multiprocessing import Process
from threading import Thread
import argparse
import socket
import sys
import sys

from instant_rst.server import sock, app
from instant_rst import util, args, settings
from instant_rst import util
from instant_rst import settings

_args = args.parse()
import ubelt as ub
import scriptconfig as scfg

if _args.localhost_only:
settings.HOST = "localhost"
APP_HOST = "127.0.0.1"
else:
# get hostname of local LAN IP
settings.HOST = socket.gethostbyname(socket.gethostname())
APP_HOST = "0.0.0.0"

settings.URL = f"http://{settings.HOST}:{settings.PORT}"
class InstantRST_CLI(scfg.DataConfig):
"""
Preview rst instantly.
"""
filename = scfg.Value(
settings.DEFAULT_FILE,
alias=['file'], short_alias=['f'],
help='The local filename for Converting',
position=1)
browser = scfg.Value(settings.BROWSER, short_alias=['b'], help=ub.paragraph(
'''
The browser command for viewing, empty will use default
'''))
port = scfg.Value(settings.PORT, short_alias=['p'], help='The port for server to use')
static_dir = scfg.Value(settings.FLASK_TEMPLATE_FOLDER, short_alias=['s'], help=ub.paragraph(
'''
Directory with static files for rendering
'''))
template_dir = scfg.Value(settings.FLASK_STATIC_FOLDER, short_alias=['t'], help=ub.paragraph(
'''
Directory with template files for rendering
'''))
localhost_only = scfg.Value(False, isflag=True, short_alias=['l'], help=ub.paragraph(
'''
Only use localhost, disable lan. default: False
'''))
additional_dirs = scfg.Value([], alias=['aditional_dir'], short_alias=['d'], help='Additional directories to serve')
debug = scfg.Value(False, isflag=True, help='debug mode or not')


def make_argparse():
"""
Ignore:
from instant_rst.main import * # NOQA
import scriptconfig
parser = make_argparse()
print(scriptconfig.DataConfig.port_from_argparse(parser, name='InstantRST_CLI'))

"""
parser = argparse.ArgumentParser(description='Preview rst instantly.')
parser.add_argument('-f', '--file', dest='filename',
default=settings.DEFAULT_FILE,
help='The local filename for Converting')
parser.add_argument('-b', '--browser', dest='browser',
default=settings.BROWSER,
help='The browser command for viewing, empty will use default')
parser.add_argument('-p', '--port', dest='port',
default=settings.PORT,
help='The port for server to use')
parser.add_argument('-s', '--static-dir', dest='static_dir',
default=settings.FLASK_STATIC_FOLDER,
help='Directory with static files for rendering')
parser.add_argument('-t', '--template-dir', dest='template_dir',
default=settings.FLASK_TEMPLATE_FOLDER,
help='Directory with template files for rendering')
parser.add_argument('-l', '--localhost-only', dest='localhost_only',
action='store_true',
help='Only use localhost, disable lan. default: False')
parser.add_argument('-d', '--aditional-dir', dest='additional_dirs',
action='append',
default=[],
help='Additional directories to serve')

parser.add_argument('--debug',
action='store_true',
default=False,
help='debug mode or not')

return parser


def run():
try:
_args = InstantRST_CLI.cli(strict=True, verbose='auto')
except Exception:
parser = make_argparse()
_args = parser.parse_args()

# Settings are stored in a global module, might be best to change this.
settings.FLASK_TEMPLATE_FOLDER = _args.template_dir
settings.FLASK_STATIC_FOLDER = _args.static_dir
settings.DEFAULT_FILE = _args.filename
settings.ADDITIONAL_DIRS = _args.additional_dirs
settings.PORT = _args.port

if _args.localhost_only:
settings.HOST = "localhost"
APP_HOST = "127.0.0.1"
else:
# get hostname of local LAN IP
settings.HOST = socket.gethostbyname(socket.gethostname())
APP_HOST = "0.0.0.0"

settings.URL = f"http://{settings.HOST}:{settings.PORT}"

print(settings.URL)
settings._p1 = Thread(target=util.delay, args=(1, "browseAndPost", [_args.browser, settings.URL]))
settings._p2 = Thread(target=sock.run, args=(app,), kwargs={'host':APP_HOST,'port':settings.PORT})
settings._p2 = Thread(target=sock.run, args=(app,), kwargs={'host': APP_HOST, 'port': settings.PORT})

try:
if not _args.debug:
settings._p1.start()
# sock.run(app, host=APP_HOST, port=settings.PORT)
settings._p2.start()
except:
except Exception:
print('\nSome error/exception occurred.')
print(sys.exc_info())
settings._p1.terminate()
Expand Down
5 changes: 3 additions & 2 deletions instant_rst/rst.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from docutils import core, io
from docutils import core

def html_parts(input_string, source_path=None,

def html_parts(input_string, source_path=None,
destination_path=None,
input_encoding='unicode', doctitle=True,
initial_header_level=1):
Expand Down
Loading