From 59139272fdbd1cf1fa60d6209e82102dc5827236 Mon Sep 17 00:00:00 2001 From: pictuga Date: Tue, 14 Apr 2020 18:07:19 +0200 Subject: [PATCH] Auto-detect the location of www/ Either ../www or /usr/share/morss Adapted README accordingly --- README.md | 15 +++++---------- morss/morss.py | 31 +++++++++++++++++-------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 9bf2e07..91e4159 100644 --- a/README.md +++ b/README.md @@ -144,17 +144,12 @@ Running this command should do: uwsgi --http :9090 --plugin python --wsgi-file main.py ``` -However, one problem might be how to serve the provided `index.html` file if it -isn't in the same directory. Therefore you can add this at the end of the -command to point to another directory `--pyargv '--root ../../www/'`. - - #### Using morss' internal HTTP server Morss can run its own HTTP server. The later should start when you run morss without any argument, on port 8080. -You can change the port and the location of the `www/` folder like this `python -m morss 9000 --root ../../www`. +You can change the port like this `python -m morss 9000`. #### Passing arguments @@ -174,9 +169,9 @@ Works like a charm with [Tiny Tiny RSS](http://tt-rss.org/redmine/projects/tt-rs Run: ``` -python[2.7] -m morss [argwithoutvalue] [argwithvalue=value] [...] FEEDURL +morss [argwithoutvalue] [argwithvalue=value] [...] FEEDURL ``` -For example: `python -m morss debug http://feeds.bbci.co.uk/news/rss.xml` +For example: `morss debug http://feeds.bbci.co.uk/news/rss.xml` *(Brackets indicate optional text)* @@ -189,9 +184,9 @@ scripts can be run on top of the RSS feed, using its To use this script, you have to enable "(Unix) command" in liferea feed settings, and use the command: ``` -[python[2.7]] PATH/TO/MORSS/main.py [argwithoutvalue] [argwithvalue=value] [...] FEEDURL +morss [argwithoutvalue] [argwithvalue=value] [...] FEEDURL ``` -For example: `python2.7 PATH/TO/MORSS/main.py http://feeds.bbci.co.uk/news/rss.xml` +For example: `morss http://feeds.bbci.co.uk/news/rss.xml` *(Brackets indicate optional text)* diff --git a/morss/morss.py b/morss/morss.py index 7c074e3..4894956 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -620,21 +620,24 @@ def cgi_file_handler(environ, start_response, app): if url == '': url = 'index.html' - if '--root' in sys.argv[1:]: - path = os.path.join(sys.argv[-1], url) + paths = [os.path.join(sys.prefix, 'share/morss', url), + os.path.join(os.path.dirname(__file__), '../www', url)] + + for path in paths: + try: + print(path) + body = open(path, 'rb').read() + + headers['status'] = '200 OK' + headers['content-type'] = files[url] + start_response(headers['status'], list(headers.items())) + return [body] + + except IOError: + continue else: - path = url - - try: - body = open(path, 'rb').read() - - headers['status'] = '200 OK' - headers['content-type'] = files[url] - start_response(headers['status'], list(headers.items())) - return [body] - - except IOError: + # the for loop did not return, so here we are, i.e. no file found headers['status'] = '404 Not found' start_response(headers['status'], list(headers.items())) return ['Error %s' % headers['status']] @@ -762,7 +765,7 @@ def main(): wsgiref.handlers.CGIHandler().run(app) - elif len(sys.argv) <= 1 or isInt(sys.argv[1]) or '--root' in sys.argv[1:]: + elif len(sys.argv) <= 1 or isInt(sys.argv[1]): # start internal (basic) http server if len(sys.argv) > 1 and isInt(sys.argv[1]):