From 7a560181f7854400719470e8b472cf448b821c1f Mon Sep 17 00:00:00 2001 From: pictuga Date: Sun, 23 Aug 2020 14:23:45 +0200 Subject: [PATCH] Use env var for DEBUG --- README.md | 2 +- morss/cgi.py | 5 +---- morss/cli.py | 3 +-- morss/morss.py | 9 +++++---- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b9192b9..ab11f2f 100644 --- a/README.md +++ b/README.md @@ -113,13 +113,13 @@ misc: --nolink drop links, but keeps links' inner text --noref drop items' link --silent don't output the final RSS (useless on its own, but can be nice when debugging) - --debug to have some feedback from the script execution. Useful for debugging GNU AGPLv3 code ``` Further options: - Change what morss does +- `debug`: to have some feedback from the script execution. Useful for debugging. NB. for cli use, set the environment variable `DEBUG=1` - `silent`: don't output the final RSS (useless on its own, but can be nice when debugging) - `callback=NAME`: for JSONP calls - `cors`: allow Cross-origin resource sharing (allows XHR calls from other servers) diff --git a/morss/cgi.py b/morss/cgi.py index 1e84519..92d87b6 100644 --- a/morss/cgi.py +++ b/morss/cgi.py @@ -14,7 +14,7 @@ except ImportError: from . import crawler from . import readabilite from .morss import FeedFetch, FeedGather, FeedFormat -from .morss import Options, log, DELAY, DEBUG, MorssException +from .morss import Options, log, DELAY, MorssException from . import cred @@ -71,9 +71,6 @@ def cgi_parse_environ(environ): # init options = Options(parseOptions(raw_options)) - global DEBUG - DEBUG = options.debug - return (url, options) diff --git a/morss/cli.py b/morss/cli.py index a814188..30d90b6 100644 --- a/morss/cli.py +++ b/morss/cli.py @@ -5,7 +5,7 @@ import argparse from . import crawler from .morss import FeedFetch, FeedGather, FeedFormat from .morss import Options -from .morss import log, DEBUG +from .morss import log def cli_app(): @@ -41,7 +41,6 @@ def cli_app(): group.add_argument('--nolink', action='store_true', help='drop links, but keeps links\' inner text') group.add_argument('--noref', action='store_true', help='drop items\' link') group.add_argument('--silent', action='store_true', help='don\'t output the final RSS (useless on its own, but can be nice when debugging)') - group.add_argument('--debug', action='store_true', help='to have some feedback from the script execution. Useful for debugging') options = Options(parser.parse_args()) url = options.url diff --git a/morss/morss.py b/morss/morss.py index 0ec54b4..ac207d9 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -33,15 +33,16 @@ LIM_TIME = 2.5 # deletes what's after DELAY = 10 * 60 # xml cache & ETag cache (in sec) TIMEOUT = 4 # http timeout (in sec) -DEBUG = False - class MorssException(Exception): pass -def log(txt, force=False): - if DEBUG or force: +def log(txt): + if ('DEBUG' in os.environ + or ':debug' in os.environ.get('REQUEST_URI', '') + or ':debug' in os.environ.get('PATH_INFO', '') + ): if 'REQUEST_URI' in os.environ: open('morss.log', 'a').write("%s\n" % repr(txt))