Use env var for DEBUG

master
pictuga 2020-08-23 14:23:45 +02:00
parent baccd3b22b
commit 7a560181f7
4 changed files with 8 additions and 11 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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))